Skip to content

Commit

Permalink
Merge pull request #28 from kutu-dev/feat/opensubsonic-extensions
Browse files Browse the repository at this point in the history
Add tests for OpenSubsonic extensions
  • Loading branch information
kutu-dev authored Sep 15, 2023
2 parents a27dae5 + 70c2aa6 commit 44281ad
Show file tree
Hide file tree
Showing 3 changed files with 59 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/knuckles/system.py
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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()
]
15 changes: 15 additions & 0 deletions tests/api/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,18 @@ 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_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[0].name == open_subsonic_extension_name
assert response[0].versions == open_subsonic_extension_versions
28 changes: 28 additions & 0 deletions tests/mocks/system.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,3 +31,31 @@ 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_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
def mock_get_open_subsonic_extensions(
mock_generator: MockGenerator, open_subsonic_extensions: dict[str, Any]
) -> Response:
return mock_generator(
"getOpenSubsonicExtensions",
{},
{"openSubsonicExtensions": open_subsonic_extensions},
)

0 comments on commit 44281ad

Please sign in to comment.