Example #1
0
    def test_equality(self, artist, track):
        a = ArtistEvent(artist, [track], [artist])
        b = ArtistEvent(None, [track], [artist])
        c = ArtistEvent(artist, [track], [artist])

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

        assert a == c
Example #2
0
    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)
Example #3
0
    def test_de_json_all(self, client, artist, track):
        json_dict = {
            'artist': artist.to_dict(),
            'tracks': [track.to_dict()],
            'similar_to_artists_from_history': [artist.to_dict()]
        }
        artist_event = ArtistEvent.de_json(json_dict, client)

        assert artist_event.artist == artist
        assert artist_event.tracks == [track]
        assert artist_event.similar_to_artists_from_history == [artist]
Example #4
0
    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)
Example #5
0
    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)
Example #6
0
def artist_event(artist, track):
    return ArtistEvent(artist, [track], [artist])
Example #7
0
def artist_event(artist, track):
    return ArtistEvent(artist, [track], [artist], TestArtistEvent.subscribed)
Example #8
0
 def test_de_json_none(self, client):
     assert ArtistEvent.de_json({}, client) is None
Example #9
0
 def test_de_list_none(self, client):
     assert ArtistEvent.de_list({}, client) == []