feat: staging-dir + clean import_album library helpers
This commit is contained in:
@@ -0,0 +1,49 @@
|
||||
import os
|
||||
|
||||
from lyra_worker.library import clear_staging_root, import_album, staging_dir
|
||||
|
||||
|
||||
def test_staging_dir_path():
|
||||
assert staging_dir("/music", "job-1") == "/music/.staging/job-1"
|
||||
|
||||
|
||||
def test_import_album_moves_audio_and_cover_into_fresh_final(tmp_path):
|
||||
staging = tmp_path / "stg"
|
||||
(staging / "sub").mkdir(parents=True)
|
||||
(staging / "01 A.flac").write_bytes(b"a")
|
||||
(staging / "02 B.flac").write_bytes(b"b")
|
||||
(staging / "sub" / "cover.jpg").write_bytes(b"img") # streamrip leaves art in a subfolder
|
||||
(staging / "notes.txt").write_text("junk")
|
||||
final = tmp_path / "lib" / "Artist" / "Album"
|
||||
|
||||
result = import_album(str(staging), str(final))
|
||||
|
||||
assert result == str(final)
|
||||
assert sorted(os.listdir(final)) == ["01 A.flac", "02 B.flac", "cover.jpg"] # audio + cover only
|
||||
|
||||
|
||||
def test_import_album_replaces_existing_final(tmp_path):
|
||||
final = tmp_path / "lib" / "Artist" / "Album"
|
||||
final.mkdir(parents=True)
|
||||
(final / "old.flac").write_bytes(b"old") # a stale lower-quality copy
|
||||
staging = tmp_path / "stg"
|
||||
staging.mkdir()
|
||||
(staging / "01 New.flac").write_bytes(b"new")
|
||||
|
||||
import_album(str(staging), str(final))
|
||||
|
||||
assert sorted(os.listdir(final)) == ["01 New.flac"] # old copy fully replaced
|
||||
|
||||
|
||||
def test_import_album_tolerates_missing_staging(tmp_path):
|
||||
final = tmp_path / "Artist" / "Album"
|
||||
import_album(str(tmp_path / "does-not-exist"), str(final))
|
||||
assert os.path.isdir(final) and os.listdir(final) == []
|
||||
|
||||
|
||||
def test_clear_staging_root_removes_staging(tmp_path):
|
||||
stg = tmp_path / ".staging" / "j1"
|
||||
stg.mkdir(parents=True)
|
||||
(stg / "x").write_bytes(b"")
|
||||
clear_staging_root(str(tmp_path))
|
||||
assert not (tmp_path / ".staging").exists()
|
||||
Reference in New Issue
Block a user