Example #1
0
    def test_equality(self):
        a = Description(self.text, self.uri)
        b = Description('', self.uri)
        c = Description(self.text, '')
        d = Description(self.text, self.uri)

        assert a != b != c
        assert hash(a) != hash(b) != hash(c)
        assert a is not b is not c

        assert a == d
Example #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)
Example #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)
Example #4
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, 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)
Example #5
0
def description():
    return Description(TestDescription.text, TestDescription.uri)
Example #6
0
    def test_de_json_all(self, client):
        json_dict = {'text': self.text, 'uri': self.uri}
        description = Description.de_json(json_dict, client)

        assert description.text == self.text
        assert description.uri == self.uri
Example #7
0
 def test_de_json_none(self, client):
     assert Description.de_json({}, client) is None
Example #8
0
    def test_de_json_required(self, client):
        json_dict = {'text': self.text, 'url': self.url}
        description = Description.de_json(json_dict, client)

        assert description.text == self.text
        assert description.url == self.url