diff --git a/server/actions.py b/server/actions.py index ce52743..1393d5e 100644 --- a/server/actions.py +++ b/server/actions.py @@ -1,7 +1,6 @@ """Glue between a chosen Hit and a side-effecting download. Mirrors musicfetch's main() dispatch but returns a structured result dict and speakable messages.""" import os -from typing import Optional from . import mf @@ -11,7 +10,7 @@ def _source_label(hit) -> str: def _title(hit) -> str: - return hit.album or hit.title or hit.artist + return hit.album if hit.kind == "album" else (hit.title or hit.album or hit.artist) def started_message(hit) -> str: diff --git a/tests/test_actions.py b/tests/test_actions.py index dbb2527..9f1f58b 100644 --- a/tests/test_actions.py +++ b/tests/test_actions.py @@ -1,3 +1,5 @@ +import pytest + from server import actions, mf @@ -15,14 +17,14 @@ def make_lidarr_album_hit(): def test_started_message_mentions_source_and_title(): msg = actions.started_message(make_yt_hit()) - assert "Under My Skin" in msg + assert "Together" in msg assert "Avril Lavigne" in msg assert "YouTube" in msg def test_done_message_mentions_title(): msg = actions.done_message(make_yt_hit()) - assert "Under My Skin" in msg + assert "Together" in msg assert "Avril Lavigne" in msg @@ -58,3 +60,17 @@ def test_perform_lidarr_album_fallsthrough_to_youtube(monkeypatch): quality="best", root="/media/music") assert yt_calls["hit"] is yt_hit assert result["path"] == "/media/music/Avril Lavigne/youtube" + + +def test_perform_lidarr_album_no_release_no_fallback_raises(monkeypatch): + monkeypatch.setattr(mf, "act_lidarr_album", + lambda hit, root, search_all, dry_run: False) + hit = make_lidarr_album_hit() + with pytest.raises(RuntimeError): + actions.perform_fetch(hit, [hit], quality="best", root="/media/music") + + +def test_failed_message_mentions_title_and_artist(): + msg = actions.failed_message(make_yt_hit()) + assert "Together" in msg + assert "Avril Lavigne" in msg