From 9e92bfc70861fd273c821375a6f733f69182cd68 Mon Sep 17 00:00:00 2001 From: Il`ya Semyonov Date: Mon, 30 Nov 2020 19:17:23 +0100 Subject: [PATCH] =?UTF-8?q?=D0=98=D1=81=D0=BF=D1=80=D0=B0=D0=B2=D0=BB?= =?UTF-8?q?=D0=B5=D0=BD=D0=B0=20=D0=B4=D0=B5=D1=81=D0=B5=D1=80=D0=B8=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D0=B7=D0=B0=D1=86=D0=B8=D1=8F=20=D0=B0=D0=BB=D1=8C?= =?UTF-8?q?=D0=B1=D0=BE=D0=BC=D0=BE=D0=B2.=20=D0=A3=D0=B4=D0=B0=D0=BB?= =?UTF-8?q?=D1=91=D0=BD=20=D0=BA=D0=BB=D0=B0=D1=81=D1=81=20`Label`.=20?= =?UTF-8?q?=D0=92=D0=BC=D0=B5=D1=81=D1=82=D0=BE=20=D0=BD=D0=B5=D0=B3=D0=BE?= =?UTF-8?q?=20=D1=82=D0=B5=D0=BF=D0=B5=D1=80=D1=8C=20=D0=BC=D0=B0=D1=81?= =?UTF-8?q?=D1=81=D0=B8=D0=B2=20=D1=81=D1=82=D1=80=D0=BE=D0=BA.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- docs/source/yandex_music.album.label.rst | 7 --- tests/__init__.py | 1 - tests/conftest.py | 29 ++++------ tests/test_album.py | 13 +++-- tests/test_label.py | 42 -------------- yandex_music/__init__.py | 3 +- yandex_music/album/album.py | 11 ++-- yandex_music/album/label.py | 71 ------------------------ 8 files changed, 25 insertions(+), 152 deletions(-) delete mode 100644 docs/source/yandex_music.album.label.rst delete mode 100644 tests/test_label.py delete mode 100644 yandex_music/album/label.py diff --git a/docs/source/yandex_music.album.label.rst b/docs/source/yandex_music.album.label.rst deleted file mode 100644 index bd2f193..0000000 --- a/docs/source/yandex_music.album.label.rst +++ /dev/null @@ -1,7 +0,0 @@ -yandex_music.Label -================== - -.. autoclass:: yandex_music.Label - :members: - :undoc-members: - :show-inheritance: diff --git a/tests/__init__.py b/tests/__init__.py index d08edbf..160bd53 100644 --- a/tests/__init__.py +++ b/tests/__init__.py @@ -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 diff --git a/tests/conftest.py b/tests/conftest.py index 036b49f..b44db2d 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -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) diff --git a/tests/test_album.py b/tests/test_album.py index 4d71a87..a84c72f 100644 --- a/tests/test_album.py +++ b/tests/test_album.py @@ -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) diff --git a/tests/test_label.py b/tests/test_label.py deleted file mode 100644 index 2285c87..0000000 --- a/tests/test_label.py +++ /dev/null @@ -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 diff --git a/yandex_music/__init__.py b/yandex_music/__init__.py index 0c161af..81fa568 100644 --- a/yandex_music/__init__.py +++ b/yandex_music/__init__.py @@ -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', diff --git a/yandex_music/album/album.py b/yandex_music/album/album.py index 9f7039d..ddc77f9 100644 --- a/yandex_music/album/album.py +++ b/yandex_music/album/album.py @@ -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'): diff --git a/yandex_music/album/label.py b/yandex_music/album/label.py deleted file mode 100644 index 4fe5391..0000000 --- a/yandex_music/album/label.py +++ /dev/null @@ -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