示例#1
0
    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
示例#2
0
    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)
示例#3
0
    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)
示例#4
0
    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
示例#5
0
    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
示例#6
0
    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)
示例#7
0
def link():
    return Link(TestLink.title, TestLink.href, TestLink.type, TestLink.social_network)
示例#8
0
 def test_de_list_none(self, client):
     assert Link.de_list({}, client) == []
示例#9
0
 def test_de_json_none(self, client):
     assert Link.de_json({}, client) is None