Все поля кроме id у класса Album теперь опциональны в связи с тем, что может прийти пустой объект с объяснением, почему он пустой #189
このコミットが含まれているのは:
コミット
11f90563d3
|
@ -80,7 +80,7 @@ def track_without_artists_and_albums(track_factory):
|
||||||
def album_factory(label, track_position):
|
def album_factory(label, track_position):
|
||||||
class AlbumFactory:
|
class AlbumFactory:
|
||||||
def get(self, artists, volumes):
|
def get(self, artists, volumes):
|
||||||
return Album(TestAlbum.id, TestAlbum.title, TestAlbum.track_count, artists, [label],
|
return Album(TestAlbum.id, TestAlbum.error, TestAlbum.title, TestAlbum.track_count, artists, [label],
|
||||||
TestAlbum.available, TestAlbum.available_for_premium_users, TestAlbum.version,
|
TestAlbum.available, TestAlbum.available_for_premium_users, TestAlbum.version,
|
||||||
TestAlbum.cover_uri, TestAlbum.content_warning, TestAlbum.original_release_year,
|
TestAlbum.cover_uri, TestAlbum.content_warning, TestAlbum.original_release_year,
|
||||||
TestAlbum.genre, TestAlbum.og_image, TestAlbum.buy, TestAlbum.recent, TestAlbum.very_important,
|
TestAlbum.genre, TestAlbum.og_image, TestAlbum.buy, TestAlbum.recent, TestAlbum.very_important,
|
||||||
|
|
|
@ -3,6 +3,7 @@ from yandex_music import Album
|
||||||
|
|
||||||
class TestAlbum:
|
class TestAlbum:
|
||||||
id = 5239478
|
id = 5239478
|
||||||
|
error = 'not-found'
|
||||||
title = 'In the End'
|
title = 'In the End'
|
||||||
version = 'feat. Mark Van Hoen & Mike Harding'
|
version = 'feat. Mark Van Hoen & Mike Harding'
|
||||||
cover_uri = 'avatars.yandex.net/get-music-content/95061/89c14a7d.a.5239478-1/%%'
|
cover_uri = 'avatars.yandex.net/get-music-content/95061/89c14a7d.a.5239478-1/%%'
|
||||||
|
@ -27,6 +28,7 @@ class TestAlbum:
|
||||||
|
|
||||||
def test_expected_values(self, album, artist_without_tracks, label, track_position, track_without_albums):
|
def test_expected_values(self, album, artist_without_tracks, label, track_position, track_without_albums):
|
||||||
assert album.id == self.id
|
assert album.id == self.id
|
||||||
|
assert album.error == self.error
|
||||||
assert album.title == self.title
|
assert album.title == self.title
|
||||||
assert album.version == self.version
|
assert album.version == self.version
|
||||||
assert album.cover_uri == self.cover_uri
|
assert album.cover_uri == self.cover_uri
|
||||||
|
@ -59,35 +61,26 @@ class TestAlbum:
|
||||||
def test_de_list_none(self, client):
|
def test_de_list_none(self, client):
|
||||||
assert Album.de_list({}, client) == []
|
assert Album.de_list({}, client) == []
|
||||||
|
|
||||||
def test_de_json_required(self, client, artist, label):
|
def test_de_json_required(self, client):
|
||||||
json_dict = {'id_': self.id, 'title': self.title, 'cover_uri': self.cover_uri, 'track_count': self.track_count,
|
json_dict = {'id_': self.id}
|
||||||
'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)
|
album = Album.de_json(json_dict, client)
|
||||||
|
|
||||||
assert album.id == self.id
|
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
|
|
||||||
|
|
||||||
def test_de_json_all(self, client, artist, label, track_position, track):
|
def test_de_json_all(self, client, artist, label, track_position, track):
|
||||||
json_dict = {'id_': self.id, 'title': self.title, 'cover_uri': self.cover_uri, 'track_count': self.track_count,
|
json_dict = {'id_': self.id, 'error': self.error, 'title': self.title, 'cover_uri': self.cover_uri,
|
||||||
'artists': [artist.to_dict()], 'labels': [label.to_dict()], 'available': self.available,
|
'track_count': self.track_count, 'artists': [artist.to_dict()], 'labels': [label.to_dict()],
|
||||||
'available_for_premium_users': self.available_for_premium_users, 'version': self.version,
|
'available': self.available, 'available_for_premium_users': self.available_for_premium_users,
|
||||||
'content_warning': self.content_warning, 'original_release_year': self.original_release_year,
|
'version': self.version, 'content_warning': self.content_warning, 'regions': self.regions,
|
||||||
'genre': self.genre, 'og_image': self.og_image, 'buy': self.buy, 'recent': self.recent,
|
'original_release_year': self.original_release_year, 'genre': self.genre, 'buy': self.buy,
|
||||||
'very_important': self.very_important, 'available_for_mobile': self.available_for_mobile,
|
'og_image': self.og_image, 'recent': self.recent, 'very_important': self.very_important,
|
||||||
'available_partially': self.available_partially, 'bests': self.bests, 'prerolls': self.prerolls,
|
'available_for_mobile': self.available_for_mobile, 'available_partially': self.available_partially,
|
||||||
'volumes': [[track.to_dict()]], 'year': self.year,
|
'bests': self.bests, 'prerolls': self.prerolls, 'volumes': [[track.to_dict()]], 'year': self.year,
|
||||||
'release_date': self.release_date,
|
'release_date': self.release_date, 'type_': self.type, 'track_position': track_position.to_dict()}
|
||||||
'type_': self.type, 'track_position': track_position.to_dict(), 'regions': self.regions}
|
|
||||||
album = Album.de_json(json_dict, client)
|
album = Album.de_json(json_dict, client)
|
||||||
|
|
||||||
assert album.id == self.id
|
assert album.id == self.id
|
||||||
|
assert album.error == self.error
|
||||||
assert album.title == self.title
|
assert album.title == self.title
|
||||||
assert album.version == self.version
|
assert album.version == self.version
|
||||||
assert album.cover_uri == self.cover_uri
|
assert album.cover_uri == self.cover_uri
|
||||||
|
@ -115,11 +108,9 @@ class TestAlbum:
|
||||||
assert album.regions == self.regions
|
assert album.regions == self.regions
|
||||||
|
|
||||||
def test_equality(self, artist, label):
|
def test_equality(self, artist, label):
|
||||||
a = Album(self.id, self.title, self.track_count, [artist], [label], self.available,
|
a = Album(self.id)
|
||||||
self.available_for_premium_users)
|
b = Album(10)
|
||||||
b = Album(10, '', 99, [artist], [label], self.available, self.available_for_premium_users)
|
c = Album(self.id)
|
||||||
c = Album(self.id, self.title, self.track_count, [artist], [label], self.available,
|
|
||||||
self.available_for_premium_users)
|
|
||||||
|
|
||||||
assert a != b
|
assert a != b
|
||||||
assert hash(a) != hash(b)
|
assert hash(a) != hash(b)
|
||||||
|
|
|
@ -9,12 +9,13 @@ from yandex_music import YandexMusicObject
|
||||||
class Album(YandexMusicObject):
|
class Album(YandexMusicObject):
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
id_: int,
|
id_: int,
|
||||||
title: str,
|
error: Optional[str] = None,
|
||||||
track_count: int,
|
title: Optional[str] = None,
|
||||||
artists: List['Artist'],
|
track_count: Optional[int] = None,
|
||||||
labels: List['Label'],
|
artists: List['Artist'] = None,
|
||||||
available: bool,
|
labels: List['Label'] = None,
|
||||||
available_for_premium_users: bool,
|
available: Optional[bool] = None,
|
||||||
|
available_for_premium_users: Optional[bool] = None,
|
||||||
version: Optional[str] = None,
|
version: Optional[str] = None,
|
||||||
cover_uri: Optional[str] = None,
|
cover_uri: Optional[str] = None,
|
||||||
content_warning=None,
|
content_warning=None,
|
||||||
|
@ -28,7 +29,7 @@ class Album(YandexMusicObject):
|
||||||
available_partially: Optional[bool] = None,
|
available_partially: Optional[bool] = None,
|
||||||
bests: Optional[List[int]] = None,
|
bests: Optional[List[int]] = None,
|
||||||
prerolls: Optional[list] = None,
|
prerolls: Optional[list] = None,
|
||||||
volumes: List['Track'] = None,
|
volumes: Optional[List['Track']] = None,
|
||||||
year: Optional[int] = None,
|
year: Optional[int] = None,
|
||||||
release_date: Optional[str] = None,
|
release_date: Optional[str] = None,
|
||||||
type_: Optional[str] = None,
|
type_: Optional[str] = None,
|
||||||
|
@ -37,13 +38,14 @@ class Album(YandexMusicObject):
|
||||||
client: Optional['Client'] = None,
|
client: Optional['Client'] = None,
|
||||||
**kwargs) -> None:
|
**kwargs) -> None:
|
||||||
self.id = id_
|
self.id = id_
|
||||||
|
|
||||||
|
self.error = error
|
||||||
self.title = title
|
self.title = title
|
||||||
self.track_count = track_count
|
self.track_count = track_count
|
||||||
self.artists = artists
|
self.artists = artists
|
||||||
self.labels = labels
|
self.labels = labels
|
||||||
self.available_for_premium_users = available_for_premium_users
|
self.available_for_premium_users = available_for_premium_users
|
||||||
self.available = available
|
self.available = available
|
||||||
|
|
||||||
self.version = version
|
self.version = version
|
||||||
self.cover_uri = cover_uri
|
self.cover_uri = cover_uri
|
||||||
self.genre = genre
|
self.genre = genre
|
||||||
|
@ -65,8 +67,7 @@ class Album(YandexMusicObject):
|
||||||
self.content_warning = content_warning
|
self.content_warning = content_warning
|
||||||
|
|
||||||
self.client = client
|
self.client = client
|
||||||
self._id_attrs = (self.id, self.title, self.track_count, self.artists, self.labels,
|
self._id_attrs = (self.id,)
|
||||||
self.available_for_premium_users, self.available)
|
|
||||||
|
|
||||||
def with_tracks(self, *args, **kwargs) -> Optional['Album']:
|
def with_tracks(self, *args, **kwargs) -> Optional['Album']:
|
||||||
"""Сокращение для::
|
"""Сокращение для::
|
||||||
|
|
読み込み中…
新しいイシューから参照