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') data['users'] = SearchResult.de_json(data.get('users'), client, 'user') data['podcasts'] = SearchResult.de_json(data.get('podcasts'), client, 'podcast') data['podcast_episodes'] = SearchResult.de_json( data.get('podcast_episodes'), client, 'podcast_episode') return cls(client=client, **data)
def test_de_json_required(self, client, best_with_result): best_fixture, result = best_with_result json_dict = {'type_': best_fixture.type, 'result': result.to_dict()} best = Best.de_json(json_dict, client) assert best.type == best_fixture.type assert best.result == result
def de_json(cls, data, client): if not data: return None data = super(Suggestions, cls).de_json(data, client) from yandex_music import Best data['best'] = Best.de_json(data.get('best'), client) return cls(client=client, **data)
def test_de_json_all(self, client, best_with_result): best_fixture, result = best_with_result json_dict = { 'type_': best_fixture.type, 'result': result.to_dict(), 'text': self.text } best = Best.de_json(json_dict, client) assert best.type == best_fixture.type assert best.result == result assert best.text == self.text
def de_json(cls, data, client): if not data: return None data = super(Search, cls).de_json(data, client) from yandex_music import Best, AlbumSearchResult, ArtistSearchResult, PlaylistSearchResult, \ TrackSearchResult, VideoSearchResult data['best'] = Best.de_json(data.get('best'), client) data['albums'] = AlbumSearchResult.de_json(data.get('albums'), client) data['artists'] = ArtistSearchResult.de_json(data.get('artists'), client) data['playlists'] = PlaylistSearchResult.de_json( data.get('playlists'), client) data['tracks'] = TrackSearchResult.de_json(data.get('tracks'), client) data['videos'] = VideoSearchResult.de_json(data.get('videos'), client) return cls(client=client, **data)
def de_json(cls, data: dict, client: 'Client') -> Optional['Suggestions']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.Suggestions`: Подсказки при поиске. """ if not data: return None data = super(Suggestions, cls).de_json(data, client) from yandex_music import Best data['best'] = Best.de_json(data.get('best'), client) return cls(client=client, **data)
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.Suggestions`: Объект класса :class:`yandex_music.Suggestions`. """ if not data: return None data = super(Suggestions, cls).de_json(data, client) from yandex_music import Best data['best'] = Best.de_json(data.get('best'), client) 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 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 Best.de_json({}, client) is None