Skip to content

Commit

Permalink
Add tests for artist info
Browse files Browse the repository at this point in the history
  • Loading branch information
kutu-dev committed Sep 16, 2023
1 parent 44281ad commit a975353
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 2 deletions.
27 changes: 25 additions & 2 deletions tests/api/test_browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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"]
28 changes: 28 additions & 0 deletions tests/mocks/browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -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},
)
20 changes: 20 additions & 0 deletions tests/models/test_artist.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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"]

0 comments on commit a975353

Please sign in to comment.