add(chore): bulk requests
This commit is contained in:
@@ -106,3 +106,31 @@ def test_import_rejects_path_outside_download_dir(client):
|
||||
"path": str(outside), "is_dir": False, "files": [str(outside)], "request_id": req_id,
|
||||
}]})
|
||||
assert resp.json()["results"][0]["ok"] is False
|
||||
|
||||
|
||||
def test_bulk_requests_and_split_scan(client):
|
||||
root = client.tmp_path / "library" / "audio"
|
||||
lib_id = client.post("/api/libraries", json={
|
||||
"name": "Hoerspiele", "media_type": "audiobook", "root_path": str(root),
|
||||
}).json()["id"]
|
||||
resp = client.post("/api/requests/bulk", json={
|
||||
"library_id": lib_id, "series": "Die drei ???", "volume_from": 1, "volume_to": 3,
|
||||
})
|
||||
assert resp.status_code == 200
|
||||
created = resp.json()
|
||||
assert [r["title"] for r in created] == [
|
||||
"Die drei ??? Folge 01", "Die drei ??? Folge 02", "Die drei ??? Folge 03",
|
||||
]
|
||||
|
||||
folder = client.downloads / "Die drei Fragezeichen Sammlung"
|
||||
folder.mkdir()
|
||||
for n in (1, 2, 3):
|
||||
(folder / f"Die drei Fragezeichen - Folge {n:03d}.mp3").write_bytes(b"a")
|
||||
|
||||
# default scan: one audiobook unit; split scan: three individual files
|
||||
assert len(client.get("/api/import/scan").json()["items"]) == 1
|
||||
items = client.get("/api/import/scan", params={"split_dirs": "true"}).json()["items"]
|
||||
assert len(items) == 3
|
||||
by_name = {i["name"]: i["suggested_request_id"] for i in items}
|
||||
expected = {f"Die drei Fragezeichen - Folge {n:03d}": created[n - 1]["id"] for n in (1, 2, 3)}
|
||||
assert by_name == expected
|
||||
|
||||
+12
-1
@@ -4,7 +4,7 @@ from wordarr.importer.matcher import best_matches, normalize
|
||||
|
||||
|
||||
def req(id, title, authors="", media_type="ebook"):
|
||||
return SimpleNamespace(id=id, title=title, authors=authors, media_type=media_type)
|
||||
return SimpleNamespace(id=id, title=title, authors=authors, media_type=media_type, volume=None)
|
||||
|
||||
|
||||
def test_normalize():
|
||||
@@ -36,3 +36,14 @@ def test_media_type_filter():
|
||||
"is_dir": False, "files": ["/d/dune.epub"]}]
|
||||
out = best_matches(items, requests)
|
||||
assert out[0]["suggested_request_id"] is None
|
||||
|
||||
|
||||
def test_volume_number_must_match():
|
||||
r1 = req(1, "Die drei ??? Folge 001", "", media_type="audiobook")
|
||||
r1.volume = 1
|
||||
r123 = req(2, "Die drei ??? Folge 123", "", media_type="audiobook")
|
||||
r123.volume = 123
|
||||
items = [{"path": "/d/f.mp3", "name": "Die drei Fragezeichen - Folge 123 - Der Superpapagei",
|
||||
"media_type": "audiobook", "is_dir": False, "files": ["/d/f.mp3"]}]
|
||||
out = best_matches(items, [r1, r123])
|
||||
assert out[0]["suggested_request_id"] == 2
|
||||
|
||||
Reference in New Issue
Block a user