Skip to content

Commit

Permalink
Исправлена десериализация альбомов. Удалён класс Label. Вместо него…
Browse files Browse the repository at this point in the history
… теперь массив строк.
  • Loading branch information
MarshalX committed Nov 30, 2020
1 parent 410f433 commit 9e92bfc
Show file tree
Hide file tree
Showing 8 changed files with 25 additions and 152 deletions.
7 changes: 0 additions & 7 deletions docs/source/yandex_music.album.label.rst

This file was deleted.

1 change: 0 additions & 1 deletion tests/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@
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
Expand Down
29 changes: 12 additions & 17 deletions tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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, \
Expand All @@ -13,7 +13,7 @@
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, \
Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand Down
13 changes: 7 additions & 6 deletions tests/test_album.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -46,7 +47,7 @@ def test_expected_values(self, album, artist_without_tracks, label, track_positi
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
Expand Down Expand Up @@ -87,9 +88,9 @@ def test_de_json_required(self, client):

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,
Expand All @@ -110,7 +111,7 @@ def test_de_json_all(self, client, artist, label, track_position, track, album_w
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
Expand Down Expand Up @@ -139,7 +140,7 @@ def test_de_json_all(self, client, artist, label, track_position, track, album_w
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)
Expand Down
42 changes: 0 additions & 42 deletions tests/test_label.py

This file was deleted.

3 changes: 1 addition & 2 deletions yandex_music/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
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
Expand Down Expand Up @@ -133,7 +132,7 @@

__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',
Expand Down
11 changes: 5 additions & 6 deletions yandex_music/album/album.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
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):
Expand All @@ -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`): Дополнительная информация об альбоме.
Expand Down Expand Up @@ -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): Дополнительная информация об альбоме.
Expand Down Expand Up @@ -98,7 +98,7 @@ def __init__(self,
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,
Expand Down Expand Up @@ -228,9 +228,8 @@ def de_json(cls, data: dict, client: 'Client') -> Optional['Album']:
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'):
Expand Down
71 changes: 0 additions & 71 deletions yandex_music/album/label.py

This file was deleted.

0 comments on commit 9e92bfc

Please sign in to comment.