fix(import): never treat the download dir itself as one audiobook
This commit is contained in:
@@ -965,3 +965,32 @@ def test_scan_and_import_survive_a_name_that_is_not_utf8(client):
|
||||
"Die drei ??? und die Fußball-Falle - Part 02.mp3",
|
||||
]
|
||||
assert not folder.exists()
|
||||
|
||||
|
||||
def test_loose_files_in_the_download_root_do_not_swallow_everything(client):
|
||||
"""Two loose audio files directly in the download dir used to make the whole
|
||||
root look like one audiobook - and its early return hid every subfolder."""
|
||||
(client.downloads / "Teil 01.mp3").write_bytes(b"")
|
||||
(client.downloads / "Teil 02.mp3").write_bytes(b"")
|
||||
for folge in ("Folge 1", "Folge 2"):
|
||||
d = client.downloads / "Serie" / folge
|
||||
d.mkdir(parents=True)
|
||||
for i in (1, 2):
|
||||
(d / f"{i:02d}.mp3").write_bytes(b"")
|
||||
|
||||
items = client.get("/api/import/scan").json()["items"]
|
||||
assert sorted(i["name"] for i in items) == ["Folge 1", "Folge 2", "Teil 01", "Teil 02"]
|
||||
# the folders stay grouped, the loose files are listed on their own
|
||||
by_name = {i["name"]: i for i in items}
|
||||
assert by_name["Folge 1"]["is_dir"] and len(by_name["Folge 1"]["files"]) == 2
|
||||
assert not by_name["Teil 01"]["is_dir"] and len(by_name["Teil 01"]["files"]) == 1
|
||||
|
||||
|
||||
def test_a_single_folder_with_many_files_is_still_one_audiobook(client):
|
||||
"""The fix must not break the normal case one level down."""
|
||||
d = client.downloads / "Ein Hoerbuch"
|
||||
d.mkdir()
|
||||
for i in (1, 2, 3):
|
||||
(d / f"{i:02d}.mp3").write_bytes(b"")
|
||||
items = client.get("/api/import/scan").json()["items"]
|
||||
assert len(items) == 1 and items[0]["is_dir"] and len(items[0]["files"]) == 3
|
||||
|
||||
Reference in New Issue
Block a user