From 79aaadf5325111c00e0b0940e1c0e9bb274d3c76 Mon Sep 17 00:00:00 2001 From: "Il'ya (Marshal)" Date: Sun, 20 Feb 2022 23:02:46 +0100 Subject: [PATCH] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20=D1=82=D0=B5=D1=81=D1=82=D1=8B=20=D0=BD=D0=B0=20?= =?UTF-8?q?=D0=B2=D1=8B=D0=B1=D1=80=D0=BE=D1=81=20=D0=B8=D1=81=D0=BA=D0=BB?= =?UTF-8?q?=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF=D1=80=D0=B8=20?= =?UTF-8?q?=D0=BD=D0=B0=D0=BB=D0=B8=D1=87=D0=B8=D0=B8=20=D0=BF=D0=BE=D0=BB?= =?UTF-8?q?=D1=8F=20error=20=D0=B2=20=D0=BC=D0=BE=D0=B4=D0=B5=D0=BB=D1=8F?= =?UTF-8?q?=D1=85=20Album,=20Artist,=20Cover,=20Track;=20=D0=B2=20=D0=BA?= =?UTF-8?q?=D0=BB=D0=B0=D1=81=D1=81=D0=B5=20Artist=20=D0=B8=D1=81=D0=BA?= =?UTF-8?q?=D0=BB=D1=8E=D1=87=D0=B5=D0=BD=D0=B8=D0=B5=20=D1=81=20=D0=BE?= =?UTF-8?q?=D1=88=D0=B8=D0=B1=D0=BA=D0=BE=D0=B9=20=D0=B1=D1=83=D0=B4=D0=B5?= =?UTF-8?q?=D1=82=20=D0=B2=D1=8B=D0=B1=D1=80=D0=B0=D1=81=D1=8B=D0=B2=D0=B0?= =?UTF-8?q?=D1=82=D1=8C=D1=81=D1=8F=20=D0=BF=D1=80=D0=B8=20=D0=BD=D0=B0?= =?UTF-8?q?=D0=BB=D0=B8=D1=87=D0=B8=D0=B8=20=D0=BF=D0=BE=D0=BB=D1=8F=20rea?= =?UTF-8?q?son.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tests/test_album.py | 11 +++++++++-- tests/test_artist.py | 14 ++++++++++++-- tests/test_cover.py | 7 +++++++ tests/test_track.py | 7 +++++++ yandex_music/artist/artist.py | 2 +- 5 files changed, 36 insertions(+), 5 deletions(-) diff --git a/tests/test_album.py b/tests/test_album.py index 715e303..ad1cd70 100644 --- a/tests/test_album.py +++ b/tests/test_album.py @@ -1,9 +1,12 @@ +import pytest + from yandex_music import Album +from yandex_music.exceptions import YandexMusicError class TestAlbum: id = 5239478 - error = 'not-found' + error = None title = 'In the End' version = 'feat. Mark Van Hoen & Mike Harding' cover_uri = 'avatars.yandex.net/get-music-content/95061/89c14a7d.a.5239478-1/%%' @@ -47,6 +50,10 @@ class TestAlbum: likes_count = 2 available_regions = ['kg', 'tm', 'by', 'kz', 'md', 'ru', 'am', 'ge', 'uz', 'tj', 'il', 'az', 'ua'] + def test_raise_on_model_error(self): + with pytest.raises(YandexMusicError): + Album(error='not-found') + def test_expected_values( self, album, @@ -109,7 +116,7 @@ class TestAlbum: assert Album.de_list({}, client) == [] def test_de_json_required(self, client): - json_dict = {'id': self.id} + json_dict = {} album = Album.de_json(json_dict, client) def test_de_json_all(self, client, artist, label, track_position, track, album_without_nested_albums, deprecation): diff --git a/tests/test_artist.py b/tests/test_artist.py index edcf696..28ed39d 100644 --- a/tests/test_artist.py +++ b/tests/test_artist.py @@ -1,10 +1,13 @@ +import pytest + from yandex_music import Artist +from yandex_music.exceptions import YandexMusicError class TestArtist: id = 10987 - error = 'not-found' - reason = 'not-found' + error = None + reason = None name = 'Elvis Presley' various = False composer = None @@ -29,6 +32,13 @@ class TestArtist: end_date = None ya_money_id = '4100170623944' + def test_raise_on_model_error(self): + with pytest.raises(YandexMusicError): + Artist(id=self.id, error='not_found') + + with pytest.raises(YandexMusicError): + Artist(id=self.id, reason='not_found') + def test_expected_values( self, artist, cover, counts, ratings, link, track_without_artists_and_albums, description, artist_decomposed ): diff --git a/tests/test_cover.py b/tests/test_cover.py index ce82c37..0849f2e 100644 --- a/tests/test_cover.py +++ b/tests/test_cover.py @@ -1,4 +1,7 @@ +import pytest + from yandex_music import Cover +from yandex_music.exceptions import YandexMusicError class TestCover: @@ -14,6 +17,10 @@ class TestCover: copyright_cline = 'imago stock&people' error = None + def test_raise_on_model_error(self): + with pytest.raises(YandexMusicError): + Cover(error='not_found') + def test_expected_values(self, cover): assert cover.type == self.type assert cover.uri == self.uri diff --git a/tests/test_track.py b/tests/test_track.py index 79eb34a..6c4e1e1 100644 --- a/tests/test_track.py +++ b/tests/test_track.py @@ -1,4 +1,7 @@ +import pytest + from yandex_music import Track +from yandex_music.exceptions import YandexMusicError class TestTrack: @@ -37,6 +40,10 @@ class TestTrack: ) is_suitable_for_children = True + def test_raise_on_model_error(self): + with pytest.raises(YandexMusicError): + Track(id=self.id, error='not-found') + def test_expected_values( self, track, diff --git a/yandex_music/artist/artist.py b/yandex_music/artist/artist.py index 1e22d3f..fda1266 100644 --- a/yandex_music/artist/artist.py +++ b/yandex_music/artist/artist.py @@ -80,7 +80,7 @@ class Artist(YandexMusicObject): client: 'Client' = None def __post_init__(self): - if self.error: + if self.error or self.reason: raise YandexMusicError(self.error) self._id_attrs = (self.id, self.name, self.cover)