v0.98.0: playlist Get Info (right-click): created, songs changed, last played on any machine, the link it was imported from, and a cover any playlist can have

This commit is contained in:
2026-11-17 22:47:25 -08:00
parent f21c31940f
commit 2964158281
12 changed files with 465 additions and 5 deletions
+88
View File
@@ -498,3 +498,91 @@ def test_a_missing_file_with_no_nfc_twin_stays_missing(tmp_path, qapp):
manager.add_track(track)
assert not manager.repair_location(track)
assert track.location == str(tmp_path / "gone.mp3")
# --------------------------------------------------------------------------
# I. playlist Get Info: created, last played, imported from, cover
from lintunes.models.playlist import Playlist # noqa: E402
from lintunes.storage.playlist_plays import PlaylistPlays # noqa: E402
def test_created_and_source_round_trip_and_are_set_on_creation(tmp_path,
qapp):
p = Playlist(name="P", persistent_id="AB", date_created="2026-11-17T00:00:00+00:00",
source_url="https://music.apple.com/x")
back = Playlist.from_dict(p.to_dict())
assert (back.date_created, back.source_url) == (p.date_created,
p.source_url)
assert "source_url" not in Playlist(name="Q").to_dict() # nothing extra
manager = _manager(tmp_path)
made = manager.create_playlist("New", source_url="https://x/y")
assert made.date_created and made.source_url == "https://x/y"
assert manager.create_folder("F").date_created
def test_last_played_is_the_newest_stamp_of_any_machine(tmp_path):
mine = PlaylistPlays(tmp_path, "aaa")
other = PlaylistPlays(tmp_path, "bbb")
assert mine.record("P1", "2026-11-01T10:00:00+00:00")
assert not mine.record("P1", "2026-11-01T10:00:30+00:00") # < a minute
assert other.record("P1", "2026-11-02T09:00:00+00:00")
assert mine.last_played("P1") == "2026-11-02T09:00:00+00:00"
assert mine.last_played("P2") is None
# Each machine writes only its own file.
assert sorted(p.name for p in (tmp_path / "playlist_plays").iterdir()) \
== ["aaa.json", "bbb.json"]
def test_playing_from_a_playlist_stamps_it(window, qapp):
manager = window._manager
playlist = manager.create_playlist("Played")
manager.add_track(_t(5, "X", "Song"))
window._now_playing_context = f"playlist:{playlist.persistent_id}"
window._on_track_changed(manager.library.tracks[5])
assert manager.playlist_last_played(playlist.persistent_id)
assert manager.playlist_last_played("nope") is None
def test_the_dialog_reports_name_and_cover_changes(qapp):
from lintunes.gui.playlist_info_dialog import PlaylistInfoDialog
playlist = Playlist(name="Mix", persistent_id="AB",
source_url="https://music.apple.com/us/playlist/x/pl.1")
dialog = PlaylistInfoDialog(playlist, [_t(1, "A", "B", 200)], art=JPEG)
assert dialog.new_name() == "" and dialog.art_change() is None
dialog._name.setText("Mix 2")
dialog._on_remove()
assert dialog.new_name() == "Mix 2" and dialog.art_change() == b""
dialog._on_art_staged(PNG, "image/png")
assert dialog.art_change() == PNG
def test_get_info_ok_renames_and_sets_the_cover(window, qapp, monkeypatch,
tmp_path):
from lintunes.gui import main_window as mw
from PyQt6.QtGui import QColor, QImage
manager = window._manager
playlist = manager.create_playlist("Old")
image = QImage(4, 4, QImage.Format.Format_RGB32)
image.fill(QColor("blue"))
bmp = tmp_path / "c.bmp" # not JPEG/PNG: re-encoded
image.save(str(bmp))
class _Dialog:
def __init__(self, *a, **kw):
pass
def exec(self):
return True
def new_name(self):
return "New Name"
def art_change(self):
return bmp.read_bytes()
monkeypatch.setattr(mw, "PlaylistInfoDialog", _Dialog)
window._playlist_info(playlist.persistent_id)
assert playlist.name == "New Name"
saved = playlist_art.find(manager.data_dir, playlist.persistent_id)
assert saved.suffix == ".png"
_Dialog.art_change = lambda self: b""
window._playlist_info(playlist.persistent_id)
assert playlist_art.find(manager.data_dir, playlist.persistent_id) is None