Skip to content
Snippets Groups Projects
Commit 69795b5c authored by Eliot Berriot's avatar Eliot Berriot
Browse files

Resolve "Pagination of results in genres in Subsonic API does not work"

parent ae0f7588
No related branches found
No related tags found
No related merge requests found
......@@ -351,6 +351,12 @@ class SubsonicViewSet(viewsets.GenericViewSet):
)
)
queryset = queryset.playable_by(actor)
try:
offset = int(data.get("offset", 0))
except (TypeError, ValueError):
offset = 0
try:
size = int(
data["count"]
......@@ -369,7 +375,7 @@ class SubsonicViewSet(viewsets.GenericViewSet):
)
.prefetch_related("uploads")
.distinct()
.order_by("-creation_date")[:size]
.order_by("-creation_date")[offset : offset + size]
)
data = {
"songsByGenre": {
......
......@@ -520,6 +520,23 @@ def test_get_songs_by_genre(f, tags_field, db, logged_in_api_client, factories):
assert response.data == expected
def test_get_songs_by_genre_offset(logged_in_api_client, factories):
url = reverse("api:subsonic-get_songs_by_genre")
assert url.endswith("getSongsByGenre") is True
track1 = factories["music.Track"](playable=True, set_tags=["Rock"])
factories["music.Track"](playable=True, set_tags=["Rock"])
factories["music.Track"](playable=True, set_tags=["Pop"])
# the API order tracks by creation date DESC, so the second one
# returned by the API is the first one to be created in the test.
expected = {"songsByGenre": {"song": serializers.get_song_list_data([track1])}}
response = logged_in_api_client.get(
url, {"f": "json", "count": 1, "offset": 1, "genre": "rock"}
)
assert response.status_code == 200
assert response.data == expected
@pytest.mark.parametrize("f", ["json"])
def test_search3(f, db, logged_in_api_client, factories):
url = reverse("api:subsonic-search3")
......
Fixed pagination in subsonic getSongsByGenre endpoint (#954)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment