Public Access
Tag albums service: album lookup API for Home Assistant and assignment web page
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,32 @@
|
||||
import json
|
||||
|
||||
import httpx
|
||||
|
||||
from tag_albums.library import MusicLibrary
|
||||
|
||||
|
||||
def test_search_albums_parses_music_assistant_response():
|
||||
calls = []
|
||||
|
||||
def handler(request: httpx.Request) -> httpx.Response:
|
||||
calls.append(request)
|
||||
if request.url.path == "/api/config/config_entries/entry":
|
||||
return httpx.Response(200, json=[{"entry_id": "ma-entry"}])
|
||||
body = json.loads(request.content)
|
||||
assert body == {"config_entry_id": "ma-entry", "name": "lateralus", "media_type": ["album"], "limit": 12}
|
||||
return httpx.Response(200, json={"service_response": {"albums": [
|
||||
{"name": "Lateralus", "artists": [{"name": "Tool"}, {"name": "Guest"}], "image": "http://img/1"},
|
||||
{"name": "No Artist", "artists": []},
|
||||
]}})
|
||||
|
||||
client = httpx.Client(base_url="http://ha", transport=httpx.MockTransport(handler))
|
||||
library = MusicLibrary("http://ha", "token", client=client)
|
||||
|
||||
albums = library.search_albums("lateralus")
|
||||
assert [(a.artist, a.album, a.image) for a in albums] == [
|
||||
("Tool", "Lateralus", "http://img/1"),
|
||||
("", "No Artist", None),
|
||||
]
|
||||
library.search_albums("lateralus")
|
||||
# The Music Assistant config entry is looked up once, then cached.
|
||||
assert sum(c.url.path == "/api/config/config_entries/entry" for c in calls) == 1
|
||||
Reference in New Issue
Block a user