def test_equality(self): a = TrackId(self.id, self.album_id) b = TrackId(10, self.album_id) c = TrackId(self.id, self.album_id) assert a != b assert hash(a) != hash(b) assert a is not b assert a == c
def de_json(cls, data: dict, client: 'Client') -> Optional['Playlist']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.Playlist`: Плейлист. """ if not data: return None data = super(Playlist, cls).de_json(data, client) from yandex_music import ( User, MadeFor, Cover, PlayCounter, TrackShort, PlaylistAbsence, Artist, TrackId, Contest, OpenGraphData, Brand, ) data['owner'] = User.de_json(data.get('owner'), client) data['cover'] = Cover.de_json(data.get('cover'), client) data['cover_without_text'] = Cover.de_json( data.get('cover_without_text'), client) data['made_for'] = MadeFor.de_json(data.get('made_for'), client) data['tracks'] = TrackShort.de_list(data.get('tracks'), client) data['recent_tracks'] = TrackId.de_list(data.get('recent_tracks'), client) data['play_counter'] = PlayCounter.de_json(data.get('play_counter'), client) data['top_artist'] = Artist.de_list(data.get('top_artist'), client) data['contest'] = Contest.de_json(data.get('contest'), client) data['og_data'] = OpenGraphData.de_json(data.get('og_data'), client) data['dummy_cover'] = Cover.de_json(data.get('dummy_cover'), client) data['dummy_rollover_cover'] = Cover.de_json( data.get('dummy_rollover_cover'), client) data['branding'] = Brand.de_json(data.get('branding'), client) data['similar_playlists'] = Playlist.de_list( data.get('similar_playlists'), client) data['last_owner_playlists'] = Playlist.de_list( data.get('last_owner_playlists'), client) data['playlist_absence'] = PlaylistAbsence.de_json( data.get('playlist_absence'), client) # на случай фикса if data.get('playlist_absense'): # очепятка яндуха data['playlist_absence'] = PlaylistAbsence.de_json( data.get('playlist_absense'), client) data.pop('playlist_absense') return cls(client=client, **data)
def test_de_json_all(self, client): json_dict = {'id_': self.id, 'track_id': self.track_id, 'album_id': self.album_id, 'from_': self.from_} track_id = TrackId.de_json(json_dict, client) assert track_id.id == self.id assert track_id.track_id == self.track_id assert track_id.album_id == self.album_id assert track_id.from_ == self.from_
def de_json(cls, data, client): if not data: return None data = super(TrackShortOld, cls).de_json(data, client) from yandex_music import TrackId data['track_id'] = TrackId.de_json(data.get('track_id'), client) return cls(client=client, **data)
def de_json(cls, data: dict, client: 'Client') -> Optional['Chart']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.Chart`: Элемент чарта. """ if not data: return None data = super(Chart, cls).de_json(data, client) from yandex_music import TrackId data['track_id'] = TrackId.de_json(data.get('track_id'), 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.TrackShortOld`: Объект класса :class:`yandex_music.TrackShortOld`. """ if not data: return None data = super(TrackShortOld, cls).de_json(data, client) from yandex_music import TrackId data['track_id'] = TrackId.de_json(data.get('track_id'), client) return cls(client=client, **data)
def de_json(cls, data: dict, client: 'Client') -> Optional['TrackShortOld']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.TrackShortOld`: Сокращённая версия трека или :obj:`None`. """ if not data: return None data = super(TrackShortOld, cls).de_json(data, client) from yandex_music import TrackId data['track_id'] = TrackId.de_json(data.get('track_id'), client) return cls(client=client, **data)
def de_json(cls, data: dict, client: 'Client') -> Optional['Queue']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.Queue`: Очередь. """ if not data: return None from yandex_music import TrackId, Context data = super(Queue, cls).de_json(data, client) data['tracks'] = TrackId.de_list(data.get('tracks'), client) data['context'] = Context.de_json(data.get('context'), client) return cls(client=client, **data)
def track_id(): return TrackId(TestTrackId.id, TestTrackId.album_id)
def test_de_list_none(self, client): assert TrackId.de_list({}, client) == []
def test_de_json_none(self, client): assert TrackId.de_json({}, client) is None
def test_de_json_required(self, client): json_dict = {'id': self.id} track_id = TrackId.de_json(json_dict, client) assert track_id.id == self.id