Skip to content

Commit

Permalink
Merge pull request #39 from kutu-dev/feat/get-music-folder
Browse files Browse the repository at this point in the history
Implement and test get_music_folder
  • Loading branch information
kutu-dev authored Oct 8, 2023
2 parents a7c6114 + 42277ba commit 6201b69
Show file tree
Hide file tree
Showing 6 changed files with 67 additions and 26 deletions.
20 changes: 19 additions & 1 deletion src/knuckles/browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,24 @@ def get_music_folders(self) -> list[MusicFolder]:

return [MusicFolder(self.subsonic, **music_folder) for music_folder in response]

def get_music_folder(self, id_: str) -> MusicFolder | None:
"""Get a desired music folder.
:param id_: The id of the music folder to get.
:type id_: str
:return: A music folder object that correspond with the given id
or None if is no music folder is found.
:rtype: Genre | None
"""

music_folders = self.get_music_folders()

for music_folder in music_folders:
if music_folder.id == id_:
return music_folder

return None

def get_genres(self) -> list[Genre]:
"""Calls the "getGenres" endpoint of the API.
Expand All @@ -51,7 +69,7 @@ def get_genre(self, name: str) -> Genre | None:
:param name: The name of the genre to get.
:type name: str
:return: A genre object that correspond with the given name
or None if is no genre found.
or None if is no genre is found.
:rtype: Genre | None
"""

Expand Down
2 changes: 1 addition & 1 deletion src/knuckles/podcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def get_podcasts(self, with_episodes: bool = True) -> list[Channel]:

return [Channel(self.subsonic, **channel) for channel in response]

def get_podcast(self, id_: str, with_episodes: bool = True) -> Channel:
def get_podcast(self, id_: str, with_episodes: bool | None = None) -> Channel:
"""Calls the "getPodcasts" endpoint of the API with a specific ID
to only return the desired podcast channel.
Expand Down
14 changes: 14 additions & 0 deletions tests/api/test_browsing.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,20 @@ def test_get_music_folders(
assert response[0].name == music_folders[0]["name"]


@responses.activate
def test_get_music_folder(
subsonic: Subsonic,
mock_get_music_folders: Response,
music_folders: list[dict[str, Any]],
) -> None:
responses.add(mock_get_music_folders)

response = subsonic.browsing.get_music_folder(music_folders[0]["id"])

assert response.id == music_folders[0]["id"]
assert response.name == music_folders[0]["name"]


@responses.activate
def test_get_genres(
subsonic: Subsonic, mock_get_genres: Response, genre: dict[str, Any]
Expand Down
34 changes: 16 additions & 18 deletions tests/api/test_podcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,11 @@ def test_get_podcasts_without_episodes(
@responses.activate
def test_get_podcast_default(
subsonic: Subsonic,
mock_get_podcast_with_episodes: Response,
mock_get_podcast_default: Response,
channel: dict[str, Any],
episode: dict[str, Any],
) -> None:
responses.add(mock_get_podcast_with_episodes)
responses.add(mock_get_podcast_default)

response = subsonic.podcast.get_podcast(channel["id"])

Expand All @@ -70,6 +70,20 @@ def test_get_podcast_default(
assert response.cover_art.id == channel["coverArt"]
assert response.original_image_url == channel["originalImageUrl"]
assert response.status == channel["status"]


@responses.activate
def test_get_podcast_with_episodes(
subsonic: Subsonic,
mock_get_podcast_with_episodes: Response,
channel: dict[str, Any],
episode: dict[str, Any],
) -> None:
responses.add(mock_get_podcast_with_episodes)

response = subsonic.podcast.get_podcast(channel["id"], True)

assert response.id == channel["id"]
assert type(response.episodes) is list
assert response.episodes[0].id == episode["id"]
assert response.episodes[0].stream_id == episode["streamId"]
Expand All @@ -90,22 +104,6 @@ def test_get_podcast_default(
assert response.episodes[0].path == episode["path"]


@responses.activate
def test_get_podcast_with_episodes(
subsonic: Subsonic,
mock_get_podcast_with_episodes: Response,
channel: dict[str, Any],
episode: dict[str, Any],
) -> None:
responses.add(mock_get_podcast_with_episodes)

response = subsonic.podcast.get_podcast(channel["id"], True)

assert response.id == channel["id"]
assert type(response.episodes) is list
assert response.episodes[0].id == episode["id"]


@responses.activate
def test_get_podcast_without_episodes(
subsonic: Subsonic,
Expand Down
11 changes: 11 additions & 0 deletions tests/mocks/podcast.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,17 @@ def mock_get_podcasts_without_episodes(
)


@pytest.fixture
def mock_get_podcast_default(
mock_generator: MockGenerator, channel: dict[str, Any], episode: dict[str, Any]
) -> Response:
return mock_generator(
"getPodcasts",
{"id": channel["id"]},
{"podcasts": [{**channel, "episode": [episode]}]},
)


@pytest.fixture
def mock_get_podcast_with_episodes(
mock_generator: MockGenerator, channel: dict[str, Any], episode: dict[str, Any]
Expand Down
12 changes: 6 additions & 6 deletions tests/models/test_channel.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@
@responses.activate
def test_generate(
subsonic: Subsonic,
mock_get_podcast_with_episodes: Response,
mock_get_podcast_default: Response,
channel: dict[str, Any],
) -> None:
responses.add(mock_get_podcast_with_episodes)
responses.add(mock_get_podcast_default)

response = subsonic.podcast.get_podcast(channel["id"])
response.title = "Foo"
Expand All @@ -24,11 +24,11 @@ def test_generate(
@responses.activate
def test_create(
subsonic: Subsonic,
mock_get_podcast_with_episodes: Response,
mock_get_podcast_default: Response,
mock_create_podcast_channel: Response,
channel: dict[str, Any],
) -> None:
responses.add(mock_get_podcast_with_episodes)
responses.add(mock_get_podcast_default)
responses.add(mock_create_podcast_channel)

response = subsonic.podcast.get_podcast(channel["id"])
Expand All @@ -40,11 +40,11 @@ def test_create(
@responses.activate
def test_delete(
subsonic: Subsonic,
mock_get_podcast_with_episodes: Response,
mock_get_podcast_default: Response,
mock_delete_podcast_channel: Response,
channel: dict[str, Any],
) -> None:
responses.add(mock_get_podcast_with_episodes)
responses.add(mock_get_podcast_default)
responses.add(mock_delete_podcast_channel)

response = subsonic.podcast.get_podcast(channel["id"])
Expand Down

0 comments on commit 6201b69

Please sign in to comment.