def de_json(cls, data: dict, client: 'Client') -> Optional['Artist']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`): Клиент Yandex Music. Returns: :obj:`yandex_music.Artist`: Исполнитель. """ if not data: return None data = super(Artist, cls).de_json(data, client) from yandex_music import Cover, Ratings, Counts, Link, Track, Description data['cover'] = Cover.de_json(data.get('cover'), client) data['ratings'] = Ratings.de_json(data.get('ratings'), client) data['counts'] = Counts.de_json(data.get('counts'), client) data['links'] = Link.de_list(data.get('links'), client) data['popular_tracks'] = Track.de_list(data.get('popular_tracks'), client) data['description'] = Description.de_json(data.get('description'), client) # TODO add "decomposed" deserialization return cls(client=client, **data)
def de_json(cls, data: dict, client: 'Client') -> Optional['Artist']: """Десериализация объекта. Args: data (:obj:`dict`): Поля и значения десериализуемого объекта. client (:obj:`yandex_music.Client`): Клиент Yandex Music. Returns: :obj:`yandex_music.Artist`: Исполнитель. """ if not data: return None data = super(Artist, cls).de_json(data, client) from yandex_music import Cover, Ratings, Counts, Link, Track, Description data['cover'] = Cover.de_json(data.get('cover'), client) data['ratings'] = Ratings.de_json(data.get('ratings'), client) data['counts'] = Counts.de_json(data.get('counts'), client) data['links'] = Link.de_list(data.get('links'), client) data['popular_tracks'] = Track.de_list(data.get('popular_tracks'), client) data['description'] = Description.de_json(data.get('description'), client) # Мне очень интересно увидеть как в яндухе на клиентах солвят свой бэковский костыль, пригласите на экскурсию if data.get('decomposed'): data['decomposed'] = [ Artist.de_json(part, client) if isinstance(part, dict) else part for part in data['decomposed'] ] return cls(client=client, **data)
def test_de_json_all(self, client): json_dict = { 'tracks': self.tracks, 'direct_albums': self.direct_albums, 'also_albums': self.also_albums, 'also_tracks': self.also_tracks } counts = Counts.de_json(json_dict, client) assert counts.tracks == self.tracks assert counts.direct_albums == self.direct_albums assert counts.also_albums == self.also_albums assert counts.also_tracks == self.also_tracks
def de_json(cls, data, client): if not data: return None data = super(Artist, cls).de_json(data, client) from yandex_music import Cover, Ratings, Counts, Link, Track data['cover'] = Cover.de_json(data.get('cover'), client) data['ratings'] = Ratings.de_json(data.get('ratings'), client) data['counts'] = Counts.de_json(data.get('counts'), client) data['links'] = Link.de_list(data.get('links'), client) data['popular_tracks'] = Track.de_list(data.get('popular_tracks'), client) # TODO add "decomposed" deserialization return cls(client=client, **data)
def test_de_json_none(self, client): assert Counts.de_json({}, client) is None