diff --git a/src/knuckles/browsing.py b/src/knuckles/browsing.py index 91b62c1..02986bc 100644 --- a/src/knuckles/browsing.py +++ b/src/knuckles/browsing.py @@ -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. @@ -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 """ diff --git a/src/knuckles/podcast.py b/src/knuckles/podcast.py index 86427d7..0c982d6 100644 --- a/src/knuckles/podcast.py +++ b/src/knuckles/podcast.py @@ -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. diff --git a/tests/api/test_browsing.py b/tests/api/test_browsing.py index c3543b0..ba7ea35 100644 --- a/tests/api/test_browsing.py +++ b/tests/api/test_browsing.py @@ -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] diff --git a/tests/api/test_podcast.py b/tests/api/test_podcast.py index 2bd994f..07df330 100644 --- a/tests/api/test_podcast.py +++ b/tests/api/test_podcast.py @@ -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"]) @@ -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"] @@ -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, diff --git a/tests/mocks/podcast.py b/tests/mocks/podcast.py index 7a3f98a..a8489ba 100644 --- a/tests/mocks/podcast.py +++ b/tests/mocks/podcast.py @@ -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] diff --git a/tests/models/test_channel.py b/tests/models/test_channel.py index 0a0f753..bcc07df 100644 --- a/tests/models/test_channel.py +++ b/tests/models/test_channel.py @@ -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" @@ -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"]) @@ -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"])