2019-11-10 05:59:22 +09:00
|
|
|
import pytest
|
|
|
|
|
|
|
|
from tests import TestSearchResult
|
|
|
|
from yandex_music import Search, SearchResult
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='class')
|
2020-02-04 04:26:10 +09:00
|
|
|
def search_result(results, types):
|
2019-11-10 05:59:22 +09:00
|
|
|
def make_search_result(param):
|
2021-02-03 21:28:10 +09:00
|
|
|
return SearchResult(
|
|
|
|
types[param], TestSearchResult.total, TestSearchResult.per_page, TestSearchResult.order, [results[param]]
|
|
|
|
)
|
2019-11-10 05:59:22 +09:00
|
|
|
|
|
|
|
return make_search_result
|
|
|
|
|
|
|
|
|
|
|
|
@pytest.fixture(scope='class')
|
|
|
|
def search(best, search_result):
|
2021-02-03 21:28:10 +09:00
|
|
|
return Search(
|
|
|
|
TestSearch.search_request_id,
|
|
|
|
TestSearch.text,
|
|
|
|
best,
|
|
|
|
search_result(3),
|
|
|
|
search_result(2),
|
|
|
|
search_result(4),
|
|
|
|
search_result(1),
|
|
|
|
search_result(5),
|
|
|
|
search_result(13),
|
|
|
|
search_result(14),
|
|
|
|
search_result(15),
|
|
|
|
TestSearch.type_,
|
|
|
|
TestSearch.page,
|
|
|
|
TestSearch.per_page,
|
|
|
|
TestSearch.misspell_result,
|
|
|
|
TestSearch.misspell_original,
|
|
|
|
TestSearch.misspell_corrected,
|
|
|
|
TestSearch.nocorrect,
|
|
|
|
)
|
2019-11-10 05:59:22 +09:00
|
|
|
|
|
|
|
|
|
|
|
class TestSearch:
|
2021-02-03 21:28:10 +09:00
|
|
|
search_request_id = (
|
|
|
|
'myt1-0261-c2e-msk-myt-music-st-e72-18274.gencfg-c.yandex.net-1573323135801461'
|
|
|
|
'-3742331365077765411-1573323135819 '
|
|
|
|
)
|
2019-11-10 05:59:22 +09:00
|
|
|
text = 'NCS'
|
Метод de_list в TrackId.
Поля coauthors и recent_tracks в Playlist.
Поле regions в User.
Поля users, podcasts, podcast_episodes, type_, page, per_page в Search.
Поддержка новых типов поиска: подкасты, выпуски, пользователи.
Поля short_description, description, is_premiere, is_banner в Like.
Документация и тесты к новым поля. #339
2020-06-07 18:55:30 +09:00
|
|
|
type_ = 'artist'
|
|
|
|
page = 0
|
|
|
|
per_page = 10
|
2020-06-07 20:46:37 +09:00
|
|
|
misspell_result = 'era ameno'
|
|
|
|
misspell_original = 'ero amen'
|
2019-11-10 05:59:22 +09:00
|
|
|
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)
|
Метод de_list в TrackId.
Поля coauthors и recent_tracks в Playlist.
Поле regions в User.
Поля users, podcasts, podcast_episodes, type_, page, per_page в Search.
Поддержка новых типов поиска: подкасты, выпуски, пользователи.
Поля short_description, description, is_premiere, is_banner в Like.
Документация и тесты к новым поля. #339
2020-06-07 18:55:30 +09:00
|
|
|
assert search.users == search_result(13)
|
|
|
|
assert search.podcasts == search_result(14)
|
|
|
|
assert search.podcast_episodes == search_result(15)
|
2021-09-19 22:47:19 +09:00
|
|
|
assert search.type == self.type_
|
Метод de_list в TrackId.
Поля coauthors и recent_tracks в Playlist.
Поле regions в User.
Поля users, podcasts, podcast_episodes, type_, page, per_page в Search.
Поддержка новых типов поиска: подкасты, выпуски, пользователи.
Поля short_description, description, is_premiere, is_banner в Like.
Документация и тесты к новым поля. #339
2020-06-07 18:55:30 +09:00
|
|
|
assert search.page == self.page
|
|
|
|
assert search.per_page == self.per_page
|
2020-06-07 20:46:37 +09:00
|
|
|
assert search.misspell_result == self.misspell_result
|
|
|
|
assert search.misspell_original == self.misspell_original
|
2019-11-10 05:59:22 +09:00
|
|
|
assert search.misspell_corrected == self.misspell_corrected
|
|
|
|
assert search.nocorrect == self.nocorrect
|
|
|
|
|
2019-12-29 16:38:24 +09:00
|
|
|
def test_de_json_none(self, client):
|
|
|
|
assert Search.de_json({}, client) is None
|
|
|
|
|
2019-11-10 05:59:22 +09:00
|
|
|
def test_de_json_required(self, client, best, search_result):
|
2021-02-03 21:28:10 +09:00
|
|
|
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(),
|
|
|
|
'users': search_result(13).to_dict(),
|
|
|
|
'podcasts': search_result(14).to_dict(),
|
|
|
|
'podcast_episodes': search_result(15).to_dict(),
|
|
|
|
}
|
2019-11-10 05:59:22 +09:00
|
|
|
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)
|
Метод de_list в TrackId.
Поля coauthors и recent_tracks в Playlist.
Поле regions в User.
Поля users, podcasts, podcast_episodes, type_, page, per_page в Search.
Поддержка новых типов поиска: подкасты, выпуски, пользователи.
Поля short_description, description, is_premiere, is_banner в Like.
Документация и тесты к новым поля. #339
2020-06-07 18:55:30 +09:00
|
|
|
assert search.users == search_result(13)
|
|
|
|
assert search.podcasts == search_result(14)
|
|
|
|
assert search.podcast_episodes == search_result(15)
|
2019-11-10 05:59:22 +09:00
|
|
|
|
|
|
|
def test_de_json_all(self, client, best, search_result):
|
2021-02-03 21:28:10 +09:00
|
|
|
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(),
|
|
|
|
'users': search_result(13).to_dict(),
|
|
|
|
'podcasts': search_result(14).to_dict(),
|
|
|
|
'podcast_episodes': search_result(15).to_dict(),
|
|
|
|
'misspell_corrected': self.misspell_corrected,
|
|
|
|
'nocorrect': self.nocorrect,
|
2021-09-19 22:47:19 +09:00
|
|
|
'type': self.type_,
|
2021-02-03 21:28:10 +09:00
|
|
|
'page': self.page,
|
|
|
|
'per_page': self.per_page,
|
|
|
|
'misspell_result': self.misspell_result,
|
|
|
|
'misspell_original': self.misspell_original,
|
|
|
|
}
|
2019-11-10 05:59:22 +09:00
|
|
|
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)
|
Метод de_list в TrackId.
Поля coauthors и recent_tracks в Playlist.
Поле regions в User.
Поля users, podcasts, podcast_episodes, type_, page, per_page в Search.
Поддержка новых типов поиска: подкасты, выпуски, пользователи.
Поля short_description, description, is_premiere, is_banner в Like.
Документация и тесты к новым поля. #339
2020-06-07 18:55:30 +09:00
|
|
|
assert search.users == search_result(13)
|
|
|
|
assert search.podcasts == search_result(14)
|
|
|
|
assert search.podcast_episodes == search_result(15)
|
2021-09-19 22:47:19 +09:00
|
|
|
assert search.type == self.type_
|
Метод de_list в TrackId.
Поля coauthors и recent_tracks в Playlist.
Поле regions в User.
Поля users, podcasts, podcast_episodes, type_, page, per_page в Search.
Поддержка новых типов поиска: подкасты, выпуски, пользователи.
Поля short_description, description, is_premiere, is_banner в Like.
Документация и тесты к новым поля. #339
2020-06-07 18:55:30 +09:00
|
|
|
assert search.page == self.page
|
|
|
|
assert search.per_page == self.per_page
|
2020-06-07 20:46:37 +09:00
|
|
|
assert search.misspell_result == self.misspell_result
|
|
|
|
assert search.misspell_original == self.misspell_original
|
2019-11-10 05:59:22 +09:00
|
|
|
assert search.misspell_corrected == self.misspell_corrected
|
|
|
|
assert search.nocorrect == self.nocorrect
|
|
|
|
|
|
|
|
def test_equality(self, best, search_result):
|
2021-02-03 21:28:10 +09:00
|
|
|
a = Search(
|
|
|
|
self.search_request_id,
|
|
|
|
self.text,
|
|
|
|
best,
|
|
|
|
search_result(3),
|
|
|
|
search_result(2),
|
|
|
|
search_result(4),
|
|
|
|
search_result(1),
|
|
|
|
search_result(5),
|
|
|
|
search_result(13),
|
|
|
|
search_result(14),
|
|
|
|
search_result(15),
|
|
|
|
)
|
|
|
|
b = Search(
|
|
|
|
self.search_request_id,
|
|
|
|
'',
|
|
|
|
best,
|
|
|
|
search_result(3),
|
|
|
|
None,
|
|
|
|
search_result(4),
|
|
|
|
search_result(1),
|
|
|
|
search_result(5),
|
|
|
|
search_result(13),
|
|
|
|
None,
|
|
|
|
search_result(15),
|
|
|
|
)
|
|
|
|
c = Search(
|
|
|
|
self.search_request_id,
|
|
|
|
self.text,
|
|
|
|
best,
|
|
|
|
search_result(3),
|
|
|
|
search_result(2),
|
|
|
|
search_result(4),
|
|
|
|
search_result(1),
|
|
|
|
search_result(5),
|
|
|
|
search_result(13),
|
|
|
|
search_result(14),
|
|
|
|
search_result(15),
|
|
|
|
)
|
2019-11-10 05:59:22 +09:00
|
|
|
|
|
|
|
assert a != b
|
|
|
|
assert hash(a) != hash(b)
|
|
|
|
assert a is not b
|
|
|
|
|
|
|
|
assert a == c
|