Esempio n. 1
0
    def test_equality(self):
        a = Event(self.id, self.type)
        b = Event(self.id, '')
        c = Event(self.id, self.type, self.type_for_from)

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

        assert a == c
Esempio n. 2
0
    def test_de_json_all(self, client, track, artist_event, album_event):
        json_dict = {
            'id_': self.id,
            'type_': self.type,
            'type_for_from': self.type_for_from,
            'title': self.title,
            'tracks': [track.to_dict()],
            'artists': [artist_event.to_dict()],
            'albums': [album_event.to_dict()],
            'message': self.message,
            'device': self.device,
            'tracks_count': self.tracks_count,
            'genre': self.genre,
        }
        event = Event.de_json(json_dict, client)

        assert event.id == self.id
        assert event.type == self.type
        assert event.type_for_from == self.type_for_from
        assert event.title == self.title
        assert event.tracks == [track]
        assert event.artists == [artist_event]
        assert event.albums == [album_event]
        assert event.message == self.message
        assert event.device == self.device
        assert event.tracks_count == self.tracks_count
        assert event.genre == self.genre
Esempio n. 3
0
    def de_json(cls, data, client):
        if not data:
            return None

        data = super(Day, cls).de_json(data, client)
        from yandex_music import Event, Track, TrackWithAds
        data['events'] = Event.de_list(data.get('events'), client)
        data['tracks_to_play_with_ads'] = TrackWithAds.de_list(data.get('tracks_to_play_with_ads'), client)
        data['tracks_to_play'] = Track.de_list(data.get('tracks_to_play'), client)

        return cls(client=client, **data)
Esempio n. 4
0
def event(track, artist_event, album_event):
    return Event(
        TestEvent.id,
        TestEvent.type,
        TestEvent.type_for_from,
        TestEvent.title,
        [track],
        [artist_event],
        [album_event],
        TestEvent.message,
        TestEvent.device,
        TestEvent.tracks_count,
        TestEvent.genre,
    )
Esempio n. 5
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['Day']:
        """Десериализация объекта.

        Args:
            data (:obj:`dict`): Поля и значения десериализуемого объекта.
            client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.

        Returns:
            :obj:`yandex_music.Day`: День в фиде.
        """
        if not data:
            return None

        data = super(Day, cls).de_json(data, client)
        from yandex_music import Event, Track, TrackWithAds
        data['events'] = Event.de_list(data.get('events'), client)
        data['tracks_to_play_with_ads'] = TrackWithAds.de_list(data.get('tracks_to_play_with_ads'), client)
        data['tracks_to_play'] = Track.de_list(data.get('tracks_to_play'), client)

        return cls(client=client, **data)
Esempio n. 6
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.Day`: Объект класса :class:`yandex_music.Day`.
        """
        if not data:
            return None

        data = super(Day, cls).de_json(data, client)
        from yandex_music import Event, Track, TrackWithAds
        data['events'] = Event.de_list(data.get('events'), client)
        data['tracks_to_play_with_ads'] = TrackWithAds.de_list(
            data.get('tracks_to_play_with_ads'), client)
        data['tracks_to_play'] = Track.de_list(data.get('tracks_to_play'),
                                               client)

        return cls(client=client, **data)
Esempio n. 7
0
    def test_de_json_required(self, client):
        json_dict = {'id_': self.id, 'type_': self.type}
        event = Event.de_json(json_dict, client)

        assert event.id == self.id
        assert event.type == self.type
Esempio n. 8
0
 def test_de_list_none(self, client):
     assert Event.de_list({}, client) == []
Esempio n. 9
0
 def test_de_json_none(self, client):
     assert Event.de_json({}, client) is None