feat(music): list and select playlist songs by their position

This commit is contained in:
imSp4rky
2026-11-30 12:39:51 -07:00
parent 40114fff19
commit 70ace41201
16 changed files with 222 additions and 38 deletions
+58
View File
@@ -5,6 +5,7 @@ from __future__ import annotations
import json
import logging
from threading import Lock
from typing import Any
import click
import pytest
@@ -87,6 +88,63 @@ def test_a_lost_session_reopens_and_replays_the_call_under_the_new_ids(monkeypat
assert service._title_alias == {"ep3-aaaa": "ep3-bbbb"}
def rest_song(id_: str, album: str, position: Any = None, track: int = 1) -> dict:
return {"type": "song", "id": id_, "name": "N", "artist": "A", "album": album, "track": track, "position": position}
@pytest.mark.parametrize(
("before", "after", "alias"),
[
pytest.param(
[rest_song("song-z", "Z", 1), rest_song("song-b", "B", 2)],
[rest_song("song-b", "B", 1), rest_song("song-z", "Z", 2)],
{},
id="reordered-playlist",
),
pytest.param(
[rest_song("song-clean", "Z", 1), rest_song("song-explicit", "Z", 2)],
[rest_song("song-explicit", "Z", 1)],
{},
id="two-versions-of-one-single",
),
pytest.param(
[rest_song("song-z", "Z"), rest_song("song-b", "B")],
[rest_song("song-z", "Z", 1), rest_song("song-b", "B", 2)],
{},
id="server-updated",
),
pytest.param(
[rest_song("song-x-old", "X"), rest_song("song-y-old", "X", track=2)],
[rest_song("song-x-new", "X"), rest_song("song-y-new", "X", track=2)],
{"song-x-old": "song-x-new", "song-y-old": "song-y-new"},
id="album-without-positions",
),
],
)
@responses.activate
def test_a_reopened_session_never_takes_another_song_for_a_playlist_song(monkeypatch, before, after, alias):
service = make_service()
service._titles = [build_title(info, "TEST", "x") for info in before]
monkeypatch.setattr(service, "authenticate", lambda credential=None: setattr(service, "_session_id", "s2"))
responses.add(responses.GET, f"{SERVER}/api/health", json={"status": "ok", "draining": False})
responses.add(responses.GET, f"{SERVER}/api/session/s2/titles", json={"titles": after})
assert service.reopen()
assert service._title_alias == alias
@responses.activate
def test_a_malformed_song_position_on_reopen_is_one_error_line(monkeypatch):
service = make_service()
monkeypatch.setattr(service, "authenticate", lambda credential=None: setattr(service, "_session_id", "s2"))
responses.add(responses.GET, f"{SERVER}/api/health", json={"status": "ok", "draining": False})
listing = {"titles": [rest_song("song-z", "Z", "x")]}
responses.add(responses.GET, f"{SERVER}/api/session/s2/titles", json=listing)
with pytest.raises(RemoteError, match="The remote server sent malformed titles: Expected position"):
service.reopen()
@pytest.mark.parametrize(
"broken",
[