From a17035e7aa034af06b51efa60c44a2d4fde36510 Mon Sep 17 00:00:00 2001 From: Kutu Date: Thu, 10 Aug 2023 19:36:50 +0200 Subject: [PATCH] Add tests for the play queue methods --- tests/api/test_bookmarks.py | 35 +++++++++++++++++++++++++++++++- tests/mocks/bookmarks.py | 31 +++++++++++++++++++++++++++- tests/models/test_song.py | 6 +++--- tests/models/test_song_queue.py | 36 +++++++++++++++++++++++++++++++++ 4 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 tests/models/test_song_queue.py diff --git a/tests/api/test_bookmarks.py b/tests/api/test_bookmarks.py index 58c0239..1b4e462 100644 --- a/tests/api/test_bookmarks.py +++ b/tests/api/test_bookmarks.py @@ -2,9 +2,10 @@ import responses from dateutil import parser -from knuckles import Subsonic from responses import Response +from knuckles import Subsonic + @responses.activate def test_get_bookmarks( @@ -77,3 +78,35 @@ def test_delete_bookmark( response = subsonic.bookmarks.delete_bookmark(song["id"]) assert type(response) == Subsonic + + +@responses.activate +def test_get_play_queue( + subsonic: Subsonic, + mock_get_play_queue: Response, + username: str, + song: dict[str, Any], + play_queue: dict[str, Any], + client: str, +) -> None: + responses.add(mock_get_play_queue) + + response = subsonic.bookmarks.get_play_queue() + + assert response.user.username == username + assert response.current.id == song["id"] + assert response.changed == parser.parse(play_queue["changed"]) + assert response.changed_by == client + assert response.songs[0].id == song["id"] + + +@responses.activate +def test_save_play_queue( + subsonic: Subsonic, + mock_save_play_queue: Response, + song: dict[str, Any], + play_queue: dict[str, Any], +) -> None: + responses.add(mock_save_play_queue) + + subsonic.bookmarks.save_play_queue([song["id"]], song["id"], play_queue["position"]) diff --git a/tests/mocks/bookmarks.py b/tests/mocks/bookmarks.py index 1fbb177..4d501b4 100644 --- a/tests/mocks/bookmarks.py +++ b/tests/mocks/bookmarks.py @@ -41,6 +41,35 @@ def mock_create_bookmark( @pytest.fixture def mock_delete_bookmark( - mock_generator: MockGenerator, song: dict[str, Any], bookmark: dict[str, Any] + mock_generator: MockGenerator, song: dict[str, Any] ) -> Response: return mock_generator("deleteBookmark", {"id": song["id"]}) + + +@pytest.fixture +def play_queue(song: dict[str, Any], username: str, client: str) -> dict[str, Any]: + return { + "entry": [song], + "current": song["id"], + "position": 18283, + "username": username, + "changed": "2023-06-19T08:04:36.238963605Z", + "changedBy": client, + } + + +@pytest.fixture +def mock_get_play_queue( + mock_generator: MockGenerator, play_queue: dict[str, Any] +) -> Response: + return mock_generator("getPlayQueue", {}, {"playQueue": play_queue}) + + +@pytest.fixture +def mock_save_play_queue( + mock_generator: MockGenerator, song: dict[str, Any], play_queue: dict[str, Any] +) -> Response: + return mock_generator( + "savePlayQueue", + {"id": song["id"], "current": song["id"], "position": play_queue["position"]}, + ) diff --git a/tests/models/test_song.py b/tests/models/test_song.py index 42f3037..7da05e0 100644 --- a/tests/models/test_song.py +++ b/tests/models/test_song.py @@ -3,9 +3,9 @@ import pytest import responses -from knuckles import Song, Subsonic from responses import Response +from knuckles import Song, Subsonic from tests.conftest import MockGenerator @@ -17,7 +17,7 @@ def test_generate( ) -> None: responses.add(mock_get_song) - requested_song: Song = subsonic.browsing.get_song(song["id"]) + requested_song = subsonic.browsing.get_song(song["id"]) requested_song.title = "Foo" requested_song = requested_song.generate() @@ -34,7 +34,7 @@ def test_song_star( responses.add(mock_get_song) responses.add(mock_star_song) - requested_song: Song = subsonic.browsing.get_song(song["id"]) + requested_song = subsonic.browsing.get_song(song["id"]) assert type(requested_song.star()) is Song diff --git a/tests/models/test_song_queue.py b/tests/models/test_song_queue.py new file mode 100644 index 0000000..5089cc2 --- /dev/null +++ b/tests/models/test_song_queue.py @@ -0,0 +1,36 @@ +from typing import Any + +import responses +from knuckles import Subsonic +from responses import Response + + +@responses.activate +def test_generate( + subsonic: Subsonic, + mock_get_play_queue: Response, + username: dict[str, Any], +) -> None: + responses.add(mock_get_play_queue) + + requested_queue = subsonic.bookmarks.get_play_queue() + requested_queue.username = "Foo" + requested_queue = requested_queue.generate() + + assert requested_queue.user.username == username + + +@responses.activate +def test_save( + subsonic: Subsonic, + mock_get_play_queue: Response, + mock_save_play_queue: Response, +) -> None: + responses.add(mock_get_play_queue) + responses.add(mock_save_play_queue) + + requested_queue = subsonic.bookmarks.get_play_queue() + requested_queue = requested_queue.save() + + assert True is False + # assert type(requested_queue) is PlayQueue