90 行
4.0 KiB
Python
90 行
4.0 KiB
Python
![]() |
import pytest
|
||
|
|
||
|
from tests import TestSearchResult
|
||
|
from yandex_music import Search, SearchResult
|
||
|
|
||
|
|
||
|
@pytest.fixture(scope='class')
|
||
|
def search_result(results):
|
||
|
def make_search_result(param):
|
||
|
return SearchResult(TestSearchResult.total, TestSearchResult.per_page,
|
||
|
TestSearchResult.order, [results[param]])
|
||
|
|
||
|
return make_search_result
|
||
|
|
||
|
|
||
|
@pytest.fixture(scope='class')
|
||
|
def search(best, search_result):
|
||
|
return Search(TestSearch.search_request_id, TestSearch.text, best,
|
||
|
search_result(3), search_result(2), search_result(4),
|
||
|
search_result(1), search_result(5), TestSearch.misspell_corrected, TestSearch.nocorrect)
|
||
|
|
||
|
|
||
|
class TestSearch:
|
||
|
search_request_id = 'myt1-0261-c2e-msk-myt-music-st-e72-18274.gencfg-c.yandex.net-1573323135801461' \
|
||
|
'-3742331365077765411-1573323135819 '
|
||
|
text = 'NCS'
|
||
|
misspell_corrected = False
|
||
|
nocorrect = False
|
||
|
|
||
|
def test_expected_values(self, search, best, search_result):
|
||
|
assert search.search_request_id == self.search_request_id
|
||
|
assert search.text == self.text
|
||
|
assert search.best == best
|
||
|
assert search.albums == search_result(3)
|
||
|
assert search.artists == search_result(2)
|
||
|
assert search.playlists == search_result(4)
|
||
|
assert search.tracks == search_result(1)
|
||
|
assert search.videos == search_result(5)
|
||
|
assert search.misspell_corrected == self.misspell_corrected
|
||
|
assert search.nocorrect == self.nocorrect
|
||
|
|
||
|
def test_de_json_required(self, client, best, search_result):
|
||
|
json_dict = {'search_request_id': self.search_request_id, 'text': self.text, 'best': best.to_dict(),
|
||
|
'albums': search_result(3).to_dict(), 'artists': search_result(2).to_dict(),
|
||
|
'playlists': search_result(4).to_dict(), 'tracks': search_result(1).to_dict(),
|
||
|
'videos': search_result(5).to_dict()}
|
||
|
search = Search.de_json(json_dict, client)
|
||
|
|
||
|
assert search.search_request_id == self.search_request_id
|
||
|
assert search.text == self.text
|
||
|
assert search.best == best
|
||
|
assert search.albums == search_result(3)
|
||
|
assert search.artists == search_result(2)
|
||
|
assert search.playlists == search_result(4)
|
||
|
assert search.tracks == search_result(1)
|
||
|
assert search.videos == search_result(5)
|
||
|
|
||
|
def test_de_json_all(self, client, best, search_result):
|
||
|
json_dict = {'search_request_id': self.search_request_id, 'text': self.text, 'best': best.to_dict(),
|
||
|
'albums': search_result(3).to_dict(), 'artists': search_result(2).to_dict(),
|
||
|
'playlists': search_result(4).to_dict(), 'tracks': search_result(1).to_dict(),
|
||
|
'videos': search_result(5).to_dict(), 'misspell_corrected': self.misspell_corrected,
|
||
|
'nocorrect': self.nocorrect}
|
||
|
search = Search.de_json(json_dict, client)
|
||
|
|
||
|
assert search.search_request_id == self.search_request_id
|
||
|
assert search.text == self.text
|
||
|
assert search.best == best
|
||
|
assert search.albums == search_result(3)
|
||
|
assert search.artists == search_result(2)
|
||
|
assert search.playlists == search_result(4)
|
||
|
assert search.tracks == search_result(1)
|
||
|
assert search.videos == search_result(5)
|
||
|
assert search.misspell_corrected == self.misspell_corrected
|
||
|
assert search.nocorrect == self.nocorrect
|
||
|
|
||
|
def test_equality(self, best, search_result):
|
||
|
a = Search(self.search_request_id, self.text, best, search_result(3), search_result(2), search_result(4),
|
||
|
search_result(1), search_result(5))
|
||
|
b = Search(self.search_request_id, '', best, search_result(3), None, search_result(4), search_result(1),
|
||
|
search_result(5))
|
||
|
c = Search(self.search_request_id, self.text, best, search_result(3), search_result(2), search_result(4),
|
||
|
search_result(1), search_result(5))
|
||
|
|
||
|
assert a != b
|
||
|
assert hash(a) != hash(b)
|
||
|
assert a is not b
|
||
|
|
||
|
assert a == c
|