Files
musicfetch/tests/test_lidarr_messages.py

121 lines
4.9 KiB
Python

"""The spoken message must match what the server really did."""
from server import actions, mf
def _artist_hit(name="Michael Jackson"):
return mf.Hit(source="lidarr", kind="artist", title=name, artist=name,
payload={"artist": {"artistName": name}})
def _album_hit():
return mf.Hit(source="lidarr", kind="album", title="Lay Cold", album="Lay Cold",
artist="Overgrown", payload={"album": {"title": "Lay Cold"}})
def _yt_hit():
return mf.Hit(source="youtube", kind="track", title="Lay Cold", artist="Overgrown",
album="Lay Cold", payload={"videoId": "abc"})
def test_artist_message_never_says_x_by_x():
"""The old bug: "Finished downloading 'Michael Jackson' by Michael Jackson."."""
hit = _artist_hit()
for msg in (actions.started_message(hit),
actions.done_message(hit, {"outcome": "artist_added"}),
actions.done_message(hit, {"outcome": "artist_existing"}),
actions.failed_message(hit)):
assert "'Michael Jackson' by Michael Jackson" not in msg
def test_artist_added_message_does_not_claim_a_download():
msg = actions.done_message(_artist_hit(), {"outcome": "artist_added"})
assert "Added Michael Jackson to Lidarr" in msg
assert "Nothing was downloaded" in msg
assert "Finished downloading" not in msg
def test_artist_existing_message_says_nothing_was_added():
msg = actions.done_message(_artist_hit(), {"outcome": "artist_existing"})
assert "already in Lidarr" in msg
assert "Nothing was added" in msg
def test_album_grabbed_message_says_download_client():
"""Falls back to the hit when the result does not name the album."""
msg = actions.done_message(_album_hit(), {"outcome": "album_grabbed"})
assert "Sent 'Lay Cold' by Overgrown to the download client." == msg
def test_youtube_fallback_message_names_youtube():
"""True whether no indexer had it or Lidarr refused the release."""
msg = actions.done_message(_album_hit(), {"outcome": "youtube_fallback"})
assert "Lidarr could not get 'Lay Cold' by Overgrown" in msg
assert "YouTube Music" in msg
def test_started_message_for_an_artist_does_not_say_downloading():
assert actions.started_message(_artist_hit()) == "Looking up Michael Jackson in Lidarr."
def test_started_message_for_a_lidarr_album_says_searching_indexers():
msg = actions.started_message(_album_hit())
assert "Searching indexers now." in msg
def test_youtube_messages_are_unchanged():
assert actions.started_message(_yt_hit()).startswith("Found 'Lay Cold' by Overgrown on YouTube Music")
assert actions.done_message(_yt_hit()) == "Finished downloading 'Lay Cold' by Overgrown."
def test_choice_message_asks_which_one():
msg = actions.choice_message(_album_hit(), {
"artist": "Overgrown", "album": "Lay Cold", "artist_state": "existing",
"album_state": "existing", "choices": [{"n": 1}, {"n": 2}]})
assert "Overgrown is already in Lidarr." in msg
assert "I found 2 releases for 'Lay Cold' by Overgrown. Which one?" in msg
def test_choice_message_mentions_a_new_artist_and_new_monitor():
msg = actions.choice_message(_album_hit(), {
"artist": "Overgrown", "album": "Lay Cold", "artist_state": "added",
"album_state": "monitored", "choices": [{"n": 1}]})
assert "Added Overgrown to Lidarr." in msg
assert "Now monitoring 'Lay Cold'." in msg
assert "I found 1 release for" in msg
def test_choice_message_falls_back_to_the_hit():
msg = actions.choice_message(_album_hit(), {"choices": [{"n": 1}]})
assert "'Lay Cold' by Overgrown" in msg
def test_no_release_message_is_honest():
msg = actions.done_message(_album_hit(), {
"outcome": "no_release", "artist": "Overgrown", "album": "Lay Cold",
"artist_state": "added", "album_state": "monitored"})
assert "no indexer has a release" in msg
assert "download" not in msg.lower()
def test_album_grabbed_message_names_the_release_when_known():
msg = actions.done_message(_album_hit(), {
"outcome": "album_grabbed", "artist": "Overgrown", "album": "Lay Cold",
"release": "FLAC, 312 MB, 24 seeders, Redacted"})
assert msg == ("Sent 'Lay Cold' by Overgrown to the download client. "
"FLAC, 312 MB, 24 seeders, Redacted.")
def test_fail_text_speaks_a_fetch_error_and_hides_anything_else():
hit = _album_hit()
assert actions.fail_text(hit, actions.FetchError("Overgrown is in Lidarr, but ...")) \
== "Overgrown is in Lidarr, but ..."
assert actions.fail_text(hit, OSError("[Errno 2] No such file: 'yt-dlp'")) \
== "Failed to fetch 'Lay Cold' by Overgrown."
def test_grab_message_names_the_release():
msg = actions.grab_message({"artist": "Overgrown", "album": "Lay Cold",
"release": "FLAC, 312 MB, 24 seeders, Redacted"})
assert msg == ("Sent 'Lay Cold' by Overgrown to the download client. "
"FLAC, 312 MB, 24 seeders, Redacted.")