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
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(), 'users': search_result(13).to_dict(), 'podcasts': search_result(14).to_dict(), 'podcast_episodes': search_result(15).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) assert search.users == search_result(13) assert search.podcasts == search_result(14) assert search.podcast_episodes == search_result(15)
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 search(self, text, nocorrect=False, type='all', page=0, playlist_in_best=True, timeout=None, *args, **kwargs): url = f'{self.base_url}/search' params = { 'text': text, 'nocorrect': nocorrect, 'type': type, 'page': page, 'playlist-in-best': playlist_in_best, } result = self._request.get(url, params, timeout=timeout, *args, **kwargs) return Search.de_json(result, self)
def search(self, text: str, nocorrect: bool = False, type_: str = 'all', page: int = 0, playlist_in_best: bool = True, timeout=None, *args, **kwargs): """Осуществление поиска по запросу и типу, получение результатов. Args: text (:obj:`str`): Текст запроса. nocorrect (:obj:`bool`): Без исправлений ли TODO. type_ (:obj:`str`): Среди какого типа искать (трек, плейлист, альбом, исполнитель). page (:obj:`int`): Номер страницы. playlist_in_best (:obj:`bool`): Выдавать ли плейлисты лучшим вариантом поиска. timeout (:obj:`int` | :obj:`float`, optional): Если это значение указано, используется как время ожидания ответа от сервера вместо указанного при создании пула. **kwargs (:obj:`dict`, optional): Произвольные аргументы (будут переданы в запрос). Returns: :obj:`yandex_music.Search`: Объекта класса :class:`yandex_music.Search` представляющий результаты поиска, иначе :obj:`None`. Raises: :class:`yandex_music.YandexMusicError` """ url = f'{self.base_url}/search' params = { 'text': text, 'nocorrect': nocorrect, 'type': type_, 'page': page, 'playlist-in-best': playlist_in_best, } result = self._request.get(url, params, timeout=timeout, *args, **kwargs) return Search.de_json(result, self)
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(), '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, 'type_': self.type_, 'page': self.page, 'per_page': self.per_page, 'misspell_result': self.misspell_result, 'misspell_original': self.misspell_original, } 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.users == search_result(13) assert search.podcasts == search_result(14) assert search.podcast_episodes == search_result(15) assert search.type_ == self.type_ assert search.page == self.page assert search.per_page == self.per_page assert search.misspell_result == self.misspell_result assert search.misspell_original == self.misspell_original assert search.misspell_corrected == self.misspell_corrected assert search.nocorrect == self.nocorrect
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), 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, )
def test_de_json_none(self, client): assert Search.de_json({}, client) is None
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)