From a133d6ff54008352054de196a8c31cec03d3035a Mon Sep 17 00:00:00 2001 From: Kutu Date: Sat, 16 Sep 2023 00:34:41 +0200 Subject: [PATCH 1/2] Add tests for OpenSubsonic extensions --- tests/api/test_system.py | 13 +++++++++++++ tests/mocks/system.py | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/tests/api/test_system.py b/tests/api/test_system.py index 8947415..a134879 100644 --- a/tests/api/test_system.py +++ b/tests/api/test_system.py @@ -43,3 +43,16 @@ def test_auth_without_token( subsonic.api.use_token = False assert subsonic.system.ping().status == "ok" + + +@responses.activate +def test_get_open_subsonic_extensions( + subsonic: Subsonic, + mock_get_open_subsonic_extensions: Response, + open_subsonic_extensions: dict[str, Any], +) -> None: + responses.add(mock_get_open_subsonic_extensions) + + response = subsonic.system.get_open_subsonic_extensions() + + assert response == open_subsonic_extensions diff --git a/tests/mocks/system.py b/tests/mocks/system.py index 3671e39..63d144d 100644 --- a/tests/mocks/system.py +++ b/tests/mocks/system.py @@ -31,3 +31,19 @@ def mock_get_license( @pytest.fixture def mock_auth_without_token(mock_generator: MockGenerator, password: str) -> Response: return mock_generator("ping", {"p": password}) + + +@pytest.fixture +def open_subsonic_extensions() -> dict[str, Any]: + return {"template": [1, 2], "extension2": [2, 3]} + + +@pytest.fixture +def mock_get_open_subsonic_extensions( + mock_generator: MockGenerator, open_subsonic_extensions: dict[str, Any] +) -> Response: + return mock_generator( + "getOpenSubsonicExtensions", + {}, + {"openSubsonicExtensions": open_subsonic_extensions}, + ) From 70c2aa67f4a11917dd0678c88596005dd7aec263 Mon Sep 17 00:00:00 2001 From: Kutu Date: Sat, 16 Sep 2023 00:58:46 +0200 Subject: [PATCH 2/2] Commit missing file --- src/knuckles/system.py | 16 ++++++++++++++++ tests/api/test_system.py | 6 ++++-- tests/mocks/system.py | 16 ++++++++++++++-- 3 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/knuckles/system.py b/src/knuckles/system.py index 5a31c0b..69c752f 100644 --- a/src/knuckles/system.py +++ b/src/knuckles/system.py @@ -1,7 +1,15 @@ +from dataclasses import dataclass + from .api import Api from .models.system import License, SubsonicResponse +@dataclass +class OpenSubsonicExtension: + name: str + versions: list[int] + + class System: """Class that contains all the methods needed to interact with the systems calls in the Subsonic API. @@ -34,3 +42,11 @@ def get_license(self) -> License: response = self.api.request("getLicense")["license"] return License(**response) + + def get_open_subsonic_extensions(self) -> list[OpenSubsonicExtension]: + response = self.api.request("getOpenSubsonicExtensions")[ + "openSubsonicExtensions" + ] + return [ + OpenSubsonicExtension(name, versions) for name, versions in response.items() + ] diff --git a/tests/api/test_system.py b/tests/api/test_system.py index a134879..6c59d04 100644 --- a/tests/api/test_system.py +++ b/tests/api/test_system.py @@ -49,10 +49,12 @@ def test_auth_without_token( def test_get_open_subsonic_extensions( subsonic: Subsonic, mock_get_open_subsonic_extensions: Response, - open_subsonic_extensions: dict[str, Any], + open_subsonic_extension_name: str, + open_subsonic_extension_versions: list[int], ) -> None: responses.add(mock_get_open_subsonic_extensions) response = subsonic.system.get_open_subsonic_extensions() - assert response == open_subsonic_extensions + assert response[0].name == open_subsonic_extension_name + assert response[0].versions == open_subsonic_extension_versions diff --git a/tests/mocks/system.py b/tests/mocks/system.py index 63d144d..b022e02 100644 --- a/tests/mocks/system.py +++ b/tests/mocks/system.py @@ -34,8 +34,20 @@ def mock_auth_without_token(mock_generator: MockGenerator, password: str) -> Res @pytest.fixture -def open_subsonic_extensions() -> dict[str, Any]: - return {"template": [1, 2], "extension2": [2, 3]} +def open_subsonic_extension_name() -> str: + return "extensionName" + + +@pytest.fixture +def open_subsonic_extension_versions() -> list[int]: + return [1, 2] + + +@pytest.fixture +def open_subsonic_extensions( + open_subsonic_extension_name: str, open_subsonic_extension_versions: list[int] +) -> dict[str, Any]: + return {open_subsonic_extension_name: open_subsonic_extension_versions} @pytest.fixture