def de_json(cls, data: dict, client: 'Client') -> Optional['Search']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.Search`: Результаты поиска. """ if not data: return None data = super(Search, cls).de_json(data, client) from yandex_music import SearchResult, Best data['best'] = Best.de_json(data.get('best'), client) data['albums'] = SearchResult.de_json(data.get('albums'), client, 'album') data['artists'] = SearchResult.de_json(data.get('artists'), client, 'artist') data['playlists'] = SearchResult.de_json(data.get('playlists'), client, 'playlist') data['tracks'] = SearchResult.de_json(data.get('tracks'), client, 'track') data['videos'] = SearchResult.de_json(data.get('videos'), client, 'video') return cls(client=client, **data)
def de_json(cls, data, client): if not data: return None data = super(Search, cls).de_json(data, client) from yandex_music import SearchResult, Best data['best'] = Best.de_json(data.get('best'), client) data['albums'] = SearchResult.de_json(data.get('albums'), client, 'album') data['artists'] = SearchResult.de_json(data.get('artists'), client, 'artist') data['playlists'] = SearchResult.de_json(data.get('playlists'), client, 'playlist') data['tracks'] = SearchResult.de_json(data.get('tracks'), client, 'track') data['videos'] = SearchResult.de_json(data.get('videos'), client, 'video') return cls(client=client, **data)
def test_de_json_all(self, client, result_with_type): result, type = result_with_type json_dict = {'total': self.total, 'per_page': self.per_page, 'order': self.order, 'results': [result.to_dict()]} search_result = SearchResult.de_json(json_dict, client, type) assert search_result.total == self.total assert search_result.per_page == self.per_page assert search_result.order == self.order assert search_result.results == [result]
def de_json(cls, data, client): """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`): Объект класса :class:`yandex_music.Client` представляющий клиент Yandex Music. Returns: :obj:`yandex_music.Search`: Объект класса :class:`yandex_music.Search`. """ if not data: return None data = super(Search, cls).de_json(data, client) from yandex_music import SearchResult, Best data['best'] = Best.de_json(data.get('best'), client) data['albums'] = SearchResult.de_json(data.get('albums'), client, 'album') data['artists'] = SearchResult.de_json(data.get('artists'), client, 'artist') data['playlists'] = SearchResult.de_json(data.get('playlists'), client, 'playlist') data['tracks'] = SearchResult.de_json(data.get('tracks'), client, 'track') data['videos'] = SearchResult.de_json(data.get('videos'), client, 'video') return cls(client=client, **data)
def test_de_json_none(self, client): assert SearchResult.de_json({}, client) is None