def test_equality(self): a = Chart(self.position, self.progress, self.listeners, self.shift) b = Chart(10, self.progress, self.listeners, self.shift) c = Chart(self.position, self.progress, 10, self.shift) d = Chart(self.position, self.progress, self.listeners, self.shift) assert a != b != c assert hash(a) != hash(b) != hash(c) assert a is not b is not c assert a == d
def de_json(cls, data: dict, client: 'Client') -> Optional['BriefInfo']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.BriefInfo`: Информация об артисте. """ if not data: return None data = super(BriefInfo, cls).de_json(data, client) from yandex_music import Artist, Track, Album, Cover, PlaylistId, Video, Chart, Vinyl, Playlist data['playlists'] = Playlist.de_list(data.get('playlists'), client) data['artist'] = Artist.de_json(data.get('artist'), client) data['similar_artists'] = Artist.de_list(data.get('similar_artists'), client) data['popular_tracks'] = Track.de_list(data.get('popular_tracks'), client) data['albums'] = Album.de_list(data.get('albums'), client) data['also_albums'] = Album.de_list(data.get('also_albums'), client) data['last_releases'] = Album.de_list(data.get('last_releases'), client) data['all_covers'] = Cover.de_list(data.get('all_covers'), client) data['playlist_ids'] = PlaylistId.de_list(data.get('playlist_ids'), client) data['videos'] = Video.de_list(data.get('videos'), client) data['tracks_in_chart'] = Chart.de_list(data.get('tracks_in_chart'), client) data['vinyls'] = Vinyl.de_list(data.get('vinyls'), 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.BriefInfo`: Объект класса :class:`yandex_music.BriefInfo`. """ if not data: return None data = super(BriefInfo, cls).de_json(data, client) from yandex_music import Artist, Track, Album, Cover, PlaylistId, Video, Chart, Vinyl data['artist'] = Artist.de_json(data.get('artist'), client) data['popular_tracks'] = Track.de_list(data.get('popular_tracks'), client) data['albums'] = Album.de_list(data.get('albums'), client) data['also_albums'] = Album.de_list(data.get('also_albums'), client) data['all_covers'] = Cover.de_list(data.get('all_covers'), client) data['playlist_ids'] = PlaylistId.de_list(data.get('playlist_ids'), client) data['videos'] = Video.de_list(data.get('videos'), client) data['tracks_in_chart'] = Chart.de_list(data.get('tracks_in_chart'), client) data['vinyls'] = Vinyl.de_list(data.get('vinyls'), client) return cls(client=client, **data)
def de_json(cls, data, client): if not data: return None data = super(ChartItem, cls).de_json(data, client) from yandex_music import Chart, Track data['track'] = Track.de_json(data.get('track'), client) data['chart'] = Chart.de_json(data.get('chart'), client) return cls(client=client, **data)
def test_de_json_required(self, client): json_dict = { 'position': self.position, 'progress': self.progress, 'listeners': self.listeners, 'shift': self.shift } chart = Chart.de_json(json_dict, client) assert chart.position == self.position assert chart.progress == self.progress assert chart.listeners == self.listeners assert chart.shift == self.shift
def test_de_json_all(self, client, track_id): json_dict = { 'position': self.position, 'progress': self.progress, 'listeners': self.listeners, 'shift': self.shift, 'track_id': track_id.to_dict() } chart = Chart.de_json(json_dict, client) assert chart.position == self.position assert chart.progress == self.progress assert chart.listeners == self.listeners assert chart.shift == self.shift assert chart.track_id == track_id
def de_json(cls, data: dict, client: 'Client') -> Optional['ChartItem']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.ChartItem`: Трек в чарте. """ if not data: return None data = super(ChartItem, cls).de_json(data, client) from yandex_music import Chart, Track data['track'] = Track.de_json(data.get('track'), client) data['chart'] = Chart.de_json(data.get('chart'), client) return cls(client=client, **data)
def de_json(cls, data: dict, client: 'Client') -> Optional['TrackShort']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.TrackShort`: Укороченная версия трека с неполными данными. """ if not data: return None data = super(TrackShort, cls).de_json(data, client) from yandex_music import Track, Chart data['track'] = Track.de_json(data.get('track'), client) data['chart'] = Chart.de_json(data.get('chart'), 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.ChartItem`: Объект класса :class:`yandex_music.ChartItem`. """ if not data: return None data = super(ChartItem, cls).de_json(data, client) from yandex_music import Chart, Track data['track'] = Track.de_json(data.get('track'), client) data['chart'] = Chart.de_json(data.get('chart'), client) return cls(client=client, **data)
def chart(track_id): return Chart(TestChart.position, TestChart.progress, TestChart.listeners, TestChart.shift, track_id)
def test_de_list_none(self, client): assert Chart.de_list({}, client) == []
def test_de_json_none(self, client): assert Chart.de_json({}, client) is None