def test_equality(self): a = Link(self.title, self.href, self.type, self.social_network) b = Link(self.title, '', self.type, self.social_network) c = Link(self.title, self.href, '', self.social_network) d = Link(self.title, self.href, self.type, self.social_network) 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['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_required(self, client): json_dict = {'title': self.title, 'href': self.href, 'type_': self.type} link = Link.de_json(json_dict, client) assert link.title == self.title assert link.href == self.href assert link.type == self.type
def test_de_json_all(self, client): json_dict = {'title': self.title, 'href': self.href, 'type_': self.type, 'social_network': self.social_network} link = Link.de_json(json_dict, client) assert link.title == self.title assert link.href == self.href assert link.type == self.type assert link.social_network == self.social_network
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 link(): return Link(TestLink.title, TestLink.href, TestLink.type, TestLink.social_network)
def test_de_list_none(self, client): assert Link.de_list({}, client) == []
def test_de_json_none(self, client): assert Link.de_json({}, client) is None