Пример #1
0
    def test_de_json_all(self, client, artist, label, track_position, track):
        json_dict = {
            'id_': self.id,
            'error': self.error,
            'title': self.title,
            'cover_uri': self.cover_uri,
            'track_count': self.track_count,
            'artists': [artist.to_dict()],
            'labels': [label.to_dict()],
            'available': self.available,
            'available_for_premium_users': self.available_for_premium_users,
            'version': self.version,
            'content_warning': self.content_warning,
            'regions': self.regions,
            'original_release_year': self.original_release_year,
            'genre': self.genre,
            'buy': self.buy,
            'og_image': self.og_image,
            'recent': self.recent,
            'very_important': self.very_important,
            'available_for_mobile': self.available_for_mobile,
            'available_partially': self.available_partially,
            'bests': self.bests,
            'prerolls': self.prerolls,
            'volumes': [[track.to_dict()]],
            'year': self.year,
            'release_date': self.release_date,
            'type_': self.type,
            'track_position': track_position.to_dict()
        }
        album = Album.de_json(json_dict, client)

        assert album.id == self.id
        assert album.error == self.error
        assert album.title == self.title
        assert album.version == self.version
        assert album.cover_uri == self.cover_uri
        assert album.track_count == self.track_count
        assert album.artists == [artist]
        assert album.labels == [label]
        assert album.available == self.available
        assert album.available_for_premium_users == self.available_for_premium_users
        assert album.content_warning == self.content_warning
        assert album.original_release_year == self.original_release_year
        assert album.genre == self.genre
        assert album.og_image == self.og_image
        assert album.buy == self.buy
        assert album.recent == self.recent
        assert album.very_important == self.very_important
        assert album.available_for_mobile == self.available_for_mobile
        assert album.available_partially == self.available_partially
        assert album.bests == self.bests
        assert album.prerolls == self.prerolls
        assert album.volumes == [[track]]
        assert album.year == self.year
        assert album.release_date == self.release_date
        assert album.type == self.type
        assert album.track_position == track_position
        assert album.regions == self.regions
Пример #2
0
    def de_json(cls, data, client):
        if not data:
            return None

        data = super(AlbumsLikes, cls).de_json(data, client)
        from yandex_music import Album
        data['album'] = Album.de_json(data.get('album'), client)

        return cls(client=client, **data)
Пример #3
0
    def de_json(cls, data, client):
        if not data:
            return None

        data = super(AlbumEvent, cls).de_json(data, client)
        from yandex_music import Album, Track
        data['album'] = Album.de_json(data.get('album'), client)
        data['tracks'] = Track.de_list(data.get('tracks'), client)

        return cls(client=client, **data)
Пример #4
0
    def test_de_json_required(self, client, artist, label):
        json_dict = {'id_': self.id, 'title': self.title, 'cover_uri': self.cover_uri, 'track_count': self.track_count,
                     'artists': [artist.to_dict()], 'labels': [label.to_dict()],
                     'available': self.available, 'available_for_premium_users': self.available_for_premium_users}
        album = Album.de_json(json_dict, client)

        assert album.id == self.id
        assert album.title == self.title
        assert album.cover_uri == self.cover_uri
        assert album.track_count == self.track_count
        assert album.artists == [artist]
        assert album.labels == [label]
        assert album.available == self.available
        assert album.available_for_premium_users == self.available_for_premium_users
Пример #5
0
    def de_json(cls, data: dict, client: 'Client') -> Optional['AlbumEvent']:
        """Десериализация объекта.

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

        Returns:
            :obj:`yandex_music.AlbumEvent`: Альбом в событии фида.
        """
        if not data:
            return None

        data = super(AlbumEvent, cls).de_json(data, client)
        from yandex_music import Album, Track
        data['album'] = Album.de_json(data.get('album'), client)
        data['tracks'] = Track.de_list(data.get('tracks'), client)

        return cls(client=client, **data)
Пример #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.AlbumEvent`: Объект класса :class:`yandex_music.AlbumEvent`.
        """
        if not data:
            return None

        data = super(AlbumEvent, cls).de_json(data, client)
        from yandex_music import Album, Track
        data['album'] = Album.de_json(data.get('album'), client)
        data['tracks'] = Track.de_list(data.get('tracks'), client)

        return cls(client=client, **data)
Пример #7
0
    def albums_with_tracks(self, album_id: str or int, timeout=None, *args, **kwargs):
        """Получение альбома по его уникальному идентификатору вместе с треками.

        Args:
            album_id (:obj:`str` | :obj:`int`): Уникальный идентификатор альбома.
            timeout (:obj:`int` | :obj:`float`, optional): Если это значение указано, используется как время ожидания
                ответа от сервера вместо указанного при создании пула.
            **kwargs (:obj:`dict`, optional): Произвольные аргументы (будут переданы в запрос).

        Returns:
            :obj:`list` из :obj:`yandex_music.Album`: Объект класса :class:`yandex_music.Album` представляющий альбом,
            иначе :obj:`None`.

        Raises:
            :class:`yandex_music.YandexMusicError`
        """

        url = f'{self.base_url}/albums/{album_id}/with-tracks'

        result = self._request.get(url, timeout=timeout, *args, **kwargs)

        return Album.de_json(result, self)
Пример #8
0
    def test_de_json_all(self, client, artist, label, track_position, track,
                         album_without_nested_albums, deprecation):
        labels = [label] if type(label) == str else [label.to_dict()]
        json_dict = {
            'id_': self.id,
            'error': self.error,
            'title': self.title,
            'cover_uri': self.cover_uri,
            'track_count': self.track_count,
            'artists': [artist.to_dict()],
            'labels': labels,
            'available': self.available,
            'available_for_premium_users': self.available_for_premium_users,
            'version': self.version,
            'content_warning': self.content_warning,
            'regions': self.regions,
            'original_release_year': self.original_release_year,
            'genre': self.genre,
            'buy': self.buy,
            'og_image': self.og_image,
            'recent': self.recent,
            'very_important': self.very_important,
            'available_for_mobile': self.available_for_mobile,
            'available_partially': self.available_partially,
            'bests': self.bests,
            'prerolls': self.prerolls,
            'volumes': [[track.to_dict()]],
            'year': self.year,
            'release_date': self.release_date,
            'type_': self.type,
            'track_position': track_position.to_dict(),
            'meta_type': self.meta_type,
            'storage_dir': self.storage_dir,
            'is_banner': self.is_banner,
            'duplicates': [album_without_nested_albums.to_dict()],
            'is_premiere': self.is_premiere,
            'short_description': self.short_description,
            'description': self.description,
            'text_color': self.text_color,
            'available_as_rbt': self.available_as_rbt,
            'lyrics_available': self.lyrics_available,
            'remember_position': self.remember_position,
            'albums': [album_without_nested_albums.to_dict()],
            'duration_ms': self.duration_ms,
            'explicit': self.explicit,
            'start_date': self.start_date,
            'likes_count': self.likes_count,
            'deprecation': deprecation.to_dict(),
            'available_regions': self.available_regions,
        }
        album = Album.de_json(json_dict, client)

        assert album.id == self.id
        assert album.error == self.error
        assert album.title == self.title
        assert album.version == self.version
        assert album.cover_uri == self.cover_uri
        assert album.track_count == self.track_count
        assert album.artists == [artist]
        assert album.labels == [label]
        assert album.available == self.available
        assert album.available_for_premium_users == self.available_for_premium_users
        assert album.content_warning == self.content_warning
        assert album.original_release_year == self.original_release_year
        assert album.genre == self.genre
        assert album.text_color == self.text_color
        assert album.short_description == self.short_description
        assert album.description == self.description
        assert album.is_premiere == self.is_premiere
        assert album.is_banner == self.is_banner
        assert album.meta_type == self.meta_type
        assert album.storage_dir == self.storage_dir
        assert album.og_image == self.og_image
        assert album.buy == self.buy
        assert album.recent == self.recent
        assert album.very_important == self.very_important
        assert album.available_for_mobile == self.available_for_mobile
        assert album.available_partially == self.available_partially
        assert album.bests == self.bests
        assert album.duplicates == [album_without_nested_albums]
        assert album.prerolls == self.prerolls
        assert album.volumes == [[track]]
        assert album.year == self.year
        assert album.release_date == self.release_date
        assert album.type == self.type
        assert album.track_position == track_position
        assert album.regions == self.regions
        assert album.available_as_rbt == self.available_as_rbt
        assert album.lyrics_available == self.lyrics_available
        assert album.remember_position == self.remember_position
        assert album.duration_ms == self.duration_ms
        assert album.explicit == self.explicit
        assert album.start_date == self.start_date
        assert album.likes_count == self.likes_count
        assert album.deprecation == deprecation
        assert album.available_regions == self.available_regions
Пример #9
0
 def test_de_json_required(self, client):
     json_dict = {'id_': self.id}
     album = Album.de_json(json_dict, client)
Пример #10
0
 def test_de_json_none(self, client):
     assert Album.de_json({}, client) is None