From a975353c057c4e480ef332f025bc184608ef87ab Mon Sep 17 00:00:00 2001 From: Kutu Date: Sat, 16 Sep 2023 19:31:37 +0200 Subject: [PATCH] Add tests for artist info --- tests/api/test_browsing.py | 27 +++++++++++++++++++++++++-- tests/mocks/browsing.py | 28 ++++++++++++++++++++++++++++ tests/models/test_artist.py | 20 ++++++++++++++++++++ 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/tests/api/test_browsing.py b/tests/api/test_browsing.py index 611c5bb..ed5414e 100644 --- a/tests/api/test_browsing.py +++ b/tests/api/test_browsing.py @@ -2,9 +2,8 @@ import responses from dateutil import parser -from responses import Response - from knuckles import CoverArt, Subsonic +from responses import Response @responses.activate @@ -175,3 +174,27 @@ def test_get_album_info( assert response.medium_image_url == album_info["mediumImageUrl"] assert response.large_image_url == album_info["largeImageUrl"] assert response.large_image_url == album_info["largeImageUrl"] + + +@responses.activate +def test_get_artist_info( + subsonic: Subsonic, + mock_get_artist_info: Response, + artist: dict[str, Any], + artist_info: dict[str, Any], +) -> None: + responses.add(mock_get_artist_info) + + response = subsonic.browsing.get_artist_info( + artist["id"], len(artist_info["similarArtist"]), False + ) + + assert response.biography == artist_info["biography"] + assert response.music_brainz_id == artist_info["musicBrainzId"] + assert response.last_fm_url == artist_info["lastFmUrl"] + assert response.small_image_url == artist_info["smallImageUrl"] + assert response.medium_image_url == artist_info["mediumImageUrl"] + assert response.large_image_url == artist_info["largeImageUrl"] + assert response.large_image_url == artist_info["largeImageUrl"] + assert len(response.similar_artists) == len(artist_info["similarArtist"]) + assert response.similar_artists[0].name == artist["name"] diff --git a/tests/mocks/browsing.py b/tests/mocks/browsing.py index fb5ae82..9e1dc3f 100644 --- a/tests/mocks/browsing.py +++ b/tests/mocks/browsing.py @@ -160,3 +160,31 @@ def mock_get_album_info( return mock_generator( "getAlbumInfo2", {"id": album["id"]}, {"albumInfo": album_info} ) + + +@pytest.fixture +def artist_info(artist: dict[str, Any]) -> dict[str, Any]: + return { + "biography": {}, + "musicBrainzId": "1", + "lastFmUrl": "", + "smallImageUrl": "http://localhost:8989/play/art/f20070e8e11611cc53542a38801d60fa/artist/2/thumb34.jpg", + "mediumImageUrl": "http://localhost:8989/play/art/2b9b6c057cd4bf21089ce7572e7792b6/artist/2/thumb64.jpg", + "largeImageUrl": "http://localhost:8989/play/art/e18287c23a75e263b64c31b3d64c1944/artist/2/thumb174.jpg", + "similarArtist": [artist], + } + + +@pytest.fixture +def mock_get_artist_info( + mock_generator: MockGenerator, artist: dict[str, Any], artist_info: dict[str, Any] +) -> Response: + return mock_generator( + "getArtistInfo2", + { + "id": artist["id"], + "count": len(artist_info["similarArtist"]), + "includeNotPresent": False, + }, + {"artistInfo2": artist_info}, + ) diff --git a/tests/models/test_artist.py b/tests/models/test_artist.py index d78321a..57a303f 100644 --- a/tests/models/test_artist.py +++ b/tests/models/test_artist.py @@ -10,6 +10,7 @@ def test_generate( subsonic: Subsonic, mock_get_artist: Response, artist: dict[str, Any], + artist_info: dict[str, Any], ) -> None: responses.add(mock_get_artist) @@ -18,3 +19,22 @@ def test_generate( requested_artist = requested_artist.generate() assert requested_artist.name == artist["name"] + assert requested_artist.info.biography == artist_info["biography"] + + +@responses.activate +def test_get_artist_info( + subsonic: Subsonic, + mock_get_artist: Response, + mock_get_artist_info: Response, + artist: dict[str, Any], + artist_info: dict[str, Any], +) -> None: + responses.add(mock_get_artist) + responses.add(mock_get_artist_info) + + requested_artist = subsonic.browsing.get_artist(artist["id"]) + get_artist_info = requested_artist.get_artist_info() + + assert get_artist_info.biography == artist_info["biography"] + assert requested_artist.info.notes == artist_info["notes"]