Исправлена десериализация альбомов. Удалён класс `Label`. Вместо него теперь массив строк.
このコミットが含まれているのは:
コミット
9e92bfc708
|
@ -1,7 +0,0 @@
|
|||
yandex_music.Label
|
||||
==================
|
||||
|
||||
.. autoclass:: yandex_music.Label
|
||||
:members:
|
||||
:undoc-members:
|
||||
:show-inheritance:
|
|
@ -26,7 +26,6 @@ from .test_icon import TestIcon
|
|||
from .test_id import TestId
|
||||
from .test_images import TestImages
|
||||
from .test_invocation_info import TestInvocationInfo
|
||||
from .test_label import TestLabel
|
||||
from .test_link import TestLink
|
||||
from .test_link import TestLink
|
||||
from .test_lyrics import TestLyrics
|
||||
|
|
|
@ -2,7 +2,7 @@ import pytest
|
|||
|
||||
from yandex_music import Account, AdParams, Album, AlbumEvent, Artist, ArtistEvent, AutoRenewable, Best, Block, \
|
||||
BlockEntity, CaseForms, Chart, ChartInfo, ChartInfoMenu, ChartInfoMenuItem, ChartItem, Client, Counts, Cover, Day, \
|
||||
Description, DiscreteScale, Enum, Event, GeneratedPlaylist, Icon, Id, Images, InvocationInfo, Label, \
|
||||
Description, DiscreteScale, Enum, Event, GeneratedPlaylist, Icon, Id, Images, InvocationInfo, \
|
||||
LicenceTextPart, Link, Lyrics, MadeFor, Major, MetaData, MixLink, Normalization, Pager, PassportPhone, \
|
||||
Permissions, PersonalPlaylistsData, PlayContext, PlayContextsData, PlayCounter, Playlist, PlaylistAbsence, \
|
||||
PlaylistId, Plus, Price, Product, Promotion, Ratings, RenewableRemainder, Restrictions, RotorSettings, \
|
||||
|
@ -13,7 +13,7 @@ from yandex_music import Account, AdParams, Album, AlbumEvent, Artist, ArtistEve
|
|||
from . import TestAccount, TestAdParams, TestAlbum, TestArtist, TestAutoRenewable, TestBest, TestBlock, \
|
||||
TestBlockEntity, TestCaseForms, TestChart, TestChartInfo, TestChartInfoMenuItem, TestCounts, TestCover, TestDay, \
|
||||
TestDescription, TestDiscreteScale, TestEnum, TestEvent, TestGeneratedPlaylist, TestIcon, TestId, TestImages, \
|
||||
TestInvocationInfo, TestLabel, TestLicenceTextPart, TestLink, TestLyrics, TestMajor, TestMetaData, TestMixLink, \
|
||||
TestInvocationInfo, TestLicenceTextPart, TestLink, TestLyrics, TestMajor, TestMetaData, TestMixLink, \
|
||||
TestNormalization, TestPager, TestPassportPhone, TestPermissions, TestPersonalPlaylistsData, TestPlayContext, \
|
||||
TestPlayCounter, TestPlaylist, TestPlaylistAbsence, TestPlaylistId, TestPlus, TestPrice, TestProduct,\
|
||||
TestPromotion, TestRatings, TestRenewableRemainder, TestRotorSettings, TestSearchResult, TestSequence, \
|
||||
|
@ -102,18 +102,18 @@ def track_without_nested_tracks(artist, album, track_factory):
|
|||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def album_factory(label, track_position):
|
||||
def album_factory(track_position):
|
||||
class AlbumFactory:
|
||||
def get(self, artists, volumes, duplicates=None):
|
||||
return Album(TestAlbum.id, TestAlbum.error, TestAlbum.title, TestAlbum.track_count, artists, [label],
|
||||
TestAlbum.available, TestAlbum.available_for_premium_users, TestAlbum.version,
|
||||
TestAlbum.cover_uri, TestAlbum.content_warning, TestAlbum.original_release_year,
|
||||
TestAlbum.genre, TestAlbum.text_color, TestAlbum.short_description, TestAlbum.description,
|
||||
TestAlbum.is_premiere, TestAlbum.is_banner, TestAlbum.meta_type, TestAlbum.storage_dir,
|
||||
TestAlbum.og_image, TestAlbum.buy, TestAlbum.recent, TestAlbum.very_important,
|
||||
TestAlbum.available_for_mobile, TestAlbum.available_partially, TestAlbum.bests, duplicates,
|
||||
TestAlbum.prerolls, volumes, TestAlbum.year, TestAlbum.release_date, TestAlbum.type,
|
||||
track_position, TestAlbum.regions)
|
||||
return Album(TestAlbum.id, TestAlbum.error, TestAlbum.title, TestAlbum.track_count, artists,
|
||||
TestAlbum.labels, TestAlbum.available, TestAlbum.available_for_premium_users,
|
||||
TestAlbum.version, TestAlbum.cover_uri, TestAlbum.content_warning,
|
||||
TestAlbum.original_release_year, TestAlbum.genre, TestAlbum.text_color, TestAlbum.short_description,
|
||||
TestAlbum.description, TestAlbum.is_premiere, TestAlbum.is_banner, TestAlbum.meta_type,
|
||||
TestAlbum.storage_dir, TestAlbum.og_image, TestAlbum.buy, TestAlbum.recent,
|
||||
TestAlbum.very_important, TestAlbum.available_for_mobile, TestAlbum.available_partially,
|
||||
TestAlbum.bests, duplicates, TestAlbum.prerolls, volumes, TestAlbum.year,
|
||||
TestAlbum.release_date, TestAlbum.type, track_position, TestAlbum.regions)
|
||||
|
||||
return AlbumFactory()
|
||||
|
||||
|
@ -500,11 +500,6 @@ def contest():
|
|||
TestContest.sent, TestContest.withdrawn)
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def label():
|
||||
return Label(TestLabel.id, TestLabel.name)
|
||||
|
||||
|
||||
@pytest.fixture(scope='session')
|
||||
def track_position():
|
||||
return TrackPosition(TestTrackPosition.volume, TestTrackPosition.index)
|
||||
|
|
|
@ -36,8 +36,9 @@ class TestAlbum:
|
|||
release_date = '2019-03-22T00:00:00+03:00'
|
||||
type = 'single'
|
||||
regions = None
|
||||
labels = ['NoCopyrightSounds']
|
||||
|
||||
def test_expected_values(self, album, artist_without_tracks, label, track_position,
|
||||
def test_expected_values(self, album, artist_without_tracks, track_position,
|
||||
track_without_albums, album_without_nested_albums):
|
||||
assert album.id == self.id
|
||||
assert album.error == self.error
|
||||
|
@ -46,7 +47,7 @@ class TestAlbum:
|
|||
assert album.cover_uri == self.cover_uri
|
||||
assert album.track_count == self.track_count
|
||||
assert album.artists == [artist_without_tracks]
|
||||
assert album.labels == [label]
|
||||
assert album.labels == self.labels
|
||||
assert album.available == self.available
|
||||
assert album.available_for_premium_users == self.available_for_premium_users
|
||||
assert album.content_warning == self.content_warning
|
||||
|
@ -87,9 +88,9 @@ class TestAlbum:
|
|||
|
||||
assert album.id == self.id
|
||||
|
||||
def test_de_json_all(self, client, artist, label, track_position, track, album_without_nested_albums):
|
||||
def test_de_json_all(self, client, artist, track_position, track, album_without_nested_albums):
|
||||
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()],
|
||||
'track_count': self.track_count, 'artists': [artist.to_dict()], 'labels': self.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,
|
||||
|
@ -110,7 +111,7 @@ class TestAlbum:
|
|||
assert album.cover_uri == self.cover_uri
|
||||
assert album.track_count == self.track_count
|
||||
assert album.artists == [artist]
|
||||
assert album.labels == [label]
|
||||
assert album.labels == self.labels
|
||||
assert album.available == self.available
|
||||
assert album.available_for_premium_users == self.available_for_premium_users
|
||||
assert album.content_warning == self.content_warning
|
||||
|
@ -139,7 +140,7 @@ class TestAlbum:
|
|||
assert album.track_position == track_position
|
||||
assert album.regions == self.regions
|
||||
|
||||
def test_equality(self, artist, label):
|
||||
def test_equality(self):
|
||||
a = Album(self.id)
|
||||
b = Album(10)
|
||||
c = Album(self.id)
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
from yandex_music import Label
|
||||
|
||||
|
||||
class TestLabel:
|
||||
id = 148217
|
||||
name = 'tommee profitt STUDIOS'
|
||||
|
||||
def test_expected_values(self, label):
|
||||
assert label.id == self.id
|
||||
assert label.name == self.name
|
||||
|
||||
def test_de_list_none(self, client):
|
||||
assert Label.de_list({}, client) == []
|
||||
|
||||
def test_de_json_none(self, client):
|
||||
assert Label.de_json({}, client) is None
|
||||
|
||||
def test_de_json_required(self, client):
|
||||
json_dict = {'id_': self.id, 'name': self.name}
|
||||
label = Label.de_json(json_dict, client)
|
||||
|
||||
assert label.id == self.id
|
||||
assert label.name == self.name
|
||||
|
||||
def test_de_json_all(self, client):
|
||||
json_dict = {'id_': self.id, 'name': self.name}
|
||||
label = Label.de_json(json_dict, client)
|
||||
|
||||
assert label.id == self.id
|
||||
assert label.name == self.name
|
||||
|
||||
def test_equality(self):
|
||||
a = Label(self.id, self.name)
|
||||
b = Label(10, self.name)
|
||||
c = Label(self.id, '')
|
||||
d = Label(self.id, self.name)
|
||||
|
||||
assert a != b != c
|
||||
assert hash(a) != hash(b) != hash(c)
|
||||
assert a is not b is not c
|
||||
|
||||
assert a == d
|
|
@ -22,7 +22,6 @@ from .account.passport_phone import PassportPhone
|
|||
from .account.permissions import Permissions
|
||||
|
||||
from .album.album import Album
|
||||
from .album.label import Label
|
||||
from .album.track_position import TrackPosition
|
||||
from .artist.artist import Artist
|
||||
from .artist.artist_tracks import ArtistTracks
|
||||
|
@ -133,7 +132,7 @@ from .client import Client
|
|||
|
||||
__all__ = ['YandexMusicObject', 'Client', 'Account', 'PassportPhone', 'InvocationInfo', 'Permissions', 'Plus',
|
||||
'Subscription', 'Status', 'Price', 'Product', 'AutoRenewable', 'Settings', 'PermissionAlerts', 'Experiments',
|
||||
'Cover', 'Ratings', 'Counts', 'Link', 'Artist', 'User', 'CaseForms', 'MadeFor', 'Label', 'Album',
|
||||
'Cover', 'Ratings', 'Counts', 'Link', 'Artist', 'User', 'CaseForms', 'MadeFor', 'Album',
|
||||
'PlayCounter', 'Playlist', 'TrackShort', 'TracksList', 'Major', 'Normalization', 'TrackPosition', 'Track',
|
||||
'Like', 'GeneratedPlaylist', 'TrackWithAds', 'Day', 'ArtistEvent', 'AlbumEvent', 'Feed', 'Event',
|
||||
'PromoCodeStatus', 'DownloadInfo', 'Video', 'SearchResult', 'Best', 'Search', 'Suggestions', 'MixLink',
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import TYPE_CHECKING, Optional, List
|
|||
from yandex_music import YandexMusicObject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from yandex_music import Client, Artist, Label, TrackPosition, Track
|
||||
from yandex_music import Client, Artist, TrackPosition, Track
|
||||
|
||||
|
||||
class Album(YandexMusicObject):
|
||||
|
@ -24,7 +24,7 @@ class Album(YandexMusicObject):
|
|||
title (:obj:`str`): Название альбома.
|
||||
track_count (:obj:`int`): Количество треков.
|
||||
artists (:obj:`list` из :obj:`yandex_music.Artist`): Артисты.
|
||||
labels (:obj:`list` из :obj:`yandex_music.Label`): Лейблы.
|
||||
labels (:obj:`list` из :obj:`str`): Лейблы.
|
||||
available (:obj:`bool`): Доступен ли альбом.
|
||||
available_for_premium_users (:obj:`bool`): Доступен ли альбом для пользователей с подпиской.
|
||||
version (:obj:`str`): Дополнительная информация об альбоме.
|
||||
|
@ -60,7 +60,7 @@ class Album(YandexMusicObject):
|
|||
title (:obj:`str`, optional): Название альбома.
|
||||
track_count (:obj:`int`, optional): Количество треков.
|
||||
artists (:obj:`list` из :obj:`yandex_music.Artist`, optional): Артисты.
|
||||
labels (:obj:`list` из :obj:`yandex_music.Label`, optional): Лейблы.
|
||||
labels (:obj:`list` из :obj:`str`, optional): Лейблы.
|
||||
available (:obj:`bool`, optional): Доступен ли альбом.
|
||||
available_for_premium_users (:obj:`bool`, optional): Доступен ли альбом для пользователей с подпиской.
|
||||
version (:obj:`str`, optional): Дополнительная информация об альбоме.
|
||||
|
@ -98,7 +98,7 @@ class Album(YandexMusicObject):
|
|||
title: Optional[str] = None,
|
||||
track_count: Optional[int] = None,
|
||||
artists: List['Artist'] = None,
|
||||
labels: List['Label'] = None,
|
||||
labels: List[str] = None,
|
||||
available: Optional[bool] = None,
|
||||
available_for_premium_users: Optional[bool] = None,
|
||||
version: Optional[str] = None,
|
||||
|
@ -228,9 +228,8 @@ class Album(YandexMusicObject):
|
|||
return None
|
||||
|
||||
data = super(Album, cls).de_json(data, client)
|
||||
from yandex_music import Artist, Label, TrackPosition, Track
|
||||
from yandex_music import Artist, TrackPosition, Track
|
||||
data['artists'] = Artist.de_list(data.get('artists'), client)
|
||||
data['labels'] = Label.de_list(data.get('labels'), client)
|
||||
data['track_position'] = TrackPosition.de_json(data.get('track_position'), client)
|
||||
data['duplicates'] = Album.de_list(data.get('duplicates'), client)
|
||||
if data.get('volumes'):
|
||||
|
|
|
@ -1,71 +0,0 @@
|
|||
from typing import TYPE_CHECKING, Optional, List
|
||||
|
||||
from yandex_music import YandexMusicObject
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from yandex_music import Client
|
||||
|
||||
|
||||
class Label(YandexMusicObject):
|
||||
"""Класс, представляющий лейбл альбома.
|
||||
|
||||
Attributes:
|
||||
id (:obj:`int`): Идентификатор альбома.
|
||||
name (:obj:`str`): Название альбома.
|
||||
client (:obj:`yandex_music.Client`): Клиент Yandex Music.
|
||||
Args:
|
||||
id_ (:obj:`int`): Идентификатор альбома.
|
||||
name (:obj:`str`): Название альбома.
|
||||
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
||||
**kwargs: Произвольные ключевые аргументы полученные от API.
|
||||
"""
|
||||
|
||||
def __init__(self,
|
||||
id_: int,
|
||||
name: str,
|
||||
client: Optional['Client'] = None,
|
||||
**kwargs) -> None:
|
||||
self.id = id_
|
||||
self.name = name
|
||||
|
||||
self.client = client
|
||||
self._id_attrs = (self.id, self.name)
|
||||
|
||||
super().handle_unknown_kwargs(self, **kwargs)
|
||||
|
||||
@classmethod
|
||||
def de_json(cls, data: dict, client: 'Client') -> Optional['Label']:
|
||||
"""Десериализация объекта.
|
||||
|
||||
Args:
|
||||
data (:obj:`dict`): Поля и значения десериализуемого объекта.
|
||||
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
||||
Returns:
|
||||
:obj:`yandex_music.Label`: Лейбл.
|
||||
"""
|
||||
if not data:
|
||||
return None
|
||||
|
||||
data = super(Label, cls).de_json(data, client)
|
||||
|
||||
return cls(client=client, **data)
|
||||
|
||||
@classmethod
|
||||
def de_list(cls, data: dict, client: 'Client') -> List['Label']:
|
||||
"""Десериализация списка объектов.
|
||||
|
||||
Args:
|
||||
data (:obj:`list`): Список словарей с полями и значениями десериализуемого объекта.
|
||||
client (:obj:`yandex_music.Client`, optional): Клиент Yandex Music.
|
||||
|
||||
Returns:
|
||||
:obj:`list` из :obj:`yandex_music.Label`: Лейблы.
|
||||
"""
|
||||
if not data:
|
||||
return []
|
||||
|
||||
labels = list()
|
||||
for label in data:
|
||||
labels.append(cls.de_json(label, client))
|
||||
|
||||
return labels
|
読み込み中…
新しいイシューから参照