def test_equality(self, album, track, artist_event): a = AlbumEvent(album, track) b = AlbumEvent(None, track) c = AlbumEvent(album, track) assert a != b != artist_event assert hash(a) != hash(b) != hash(artist_event) assert a is not b is not artist_event assert a == c
def de_json(cls, data, client): if not data: return None data = super(Event, cls).de_json(data, client) from yandex_music import Track, AlbumEvent, ArtistEvent data['tracks'] = Track.de_list(data.get('tracks'), client) data['albums'] = AlbumEvent.de_list(data.get('albums'), client) data['artists'] = ArtistEvent.de_list(data.get('artists'), client) return cls(client=client, **data)
def de_json(cls, data: dict, client: 'Client') -> Optional['Event']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music. Returns: :obj:`yandex_music.Event`: Событие фида. """ if not data: return None data = super(Event, cls).de_json(data, client) from yandex_music import Track, AlbumEvent, ArtistEvent data['tracks'] = Track.de_list(data.get('tracks'), client) data['albums'] = AlbumEvent.de_list(data.get('albums'), client) data['artists'] = ArtistEvent.de_list(data.get('artists'), 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.Event`: Объект класса :class:`yandex_music.Event`. """ if not data: return None data = super(Event, cls).de_json(data, client) from yandex_music import Track, AlbumEvent, ArtistEvent data['tracks'] = Track.de_list(data.get('tracks'), client) data['albums'] = AlbumEvent.de_list(data.get('albums'), client) data['artists'] = ArtistEvent.de_list(data.get('artists'), client) return cls(client=client, **data)
def album_event(album, track): return AlbumEvent(album, [track])
def test_de_json_none(self, client): assert AlbumEvent.de_json({}, client) is None
def test_de_json_all(self, client, album, track): json_dict = {'album': album.to_dict(), 'tracks': [track.to_dict()]} album_event = AlbumEvent.de_json(json_dict, client) assert album_event.album == album assert album_event.tracks == [track]
def test_de_list_none(self, client): assert AlbumEvent.de_list({}, client) == []