Files
wordarr/tests/test_matcher.py
T
SteppenstreunerandClaude Fable 5 508ae5f26e Add wordarr: request & import manager for ebooks, comics and audiobooks
FastAPI + SQLite backend with vanilla-JS web UI. Requests via Open
Library / Audible / AniList metadata search (or manual entry) with
per-request target library selection. Manual import flow: scan the
download dir, fuzzy-match files against missing requests, review,
then move+rename into the library per configurable naming templates.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
2026-08-28 12:34:07 +02:00

39 lines
1.4 KiB
Python

from types import SimpleNamespace
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)
def test_normalize():
assert normalize("J.R.R._Tolkien-The_Hobbit[retail].epub") == "j r r tolkien the hobbit"
def test_match_finds_right_request():
requests = [
req(1, "The Hobbit", "J.R.R. Tolkien"),
req(2, "Dune", "Frank Herbert"),
]
items = [{"path": "/d/x.epub", "name": "Frank Herbert - Dune (1965) retail", "media_type": "ebook",
"is_dir": False, "files": ["/d/x.epub"]}]
out = best_matches(items, requests)
assert out[0]["suggested_request_id"] == 2
def test_no_match_for_unrelated_file():
requests = [req(1, "The Hobbit", "Tolkien")]
items = [{"path": "/d/y.epub", "name": "Cooking for Dummies 2019", "media_type": "ebook",
"is_dir": False, "files": ["/d/y.epub"]}]
out = best_matches(items, requests)
assert out[0]["suggested_request_id"] is None
def test_media_type_filter():
requests = [req(1, "Dune", "Herbert", media_type="audiobook")]
items = [{"path": "/d/dune.epub", "name": "Herbert - Dune", "media_type": "ebook",
"is_dir": False, "files": ["/d/dune.epub"]}]
out = best_matches(items, requests)
assert out[0]["suggested_request_id"] is None