Initial productized Importarr service
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
from importarr.config import Settings
|
||||
from importarr.state import State
|
||||
|
||||
|
||||
def test_path_must_be_under_root(tmp_path):
|
||||
settings = Settings(download_root=tmp_path / "manual")
|
||||
try:
|
||||
settings.resolve_under_download_root("/etc")
|
||||
except ValueError:
|
||||
pass
|
||||
else:
|
||||
raise AssertionError("expected ValueError")
|
||||
|
||||
|
||||
def test_manual_batch_completes_when_empty(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("IMPORTARR_STATE_PATH", str(tmp_path / "initial.db"))
|
||||
import importarr.main as main
|
||||
download = tmp_path / "downloads"
|
||||
movies = tmp_path / "movies"
|
||||
tv = tmp_path / "tv"
|
||||
batch = download / "Release"
|
||||
batch.mkdir(parents=True)
|
||||
(batch / "Movie.mkv").write_bytes(b"movie")
|
||||
monkeypatch.setattr(main, "settings", Settings(download_root=download, movies_root=movies, tv_root=tv, state_path=tmp_path / "state.db"))
|
||||
monkeypatch.setattr(main, "state", State(tmp_path / "state.db"))
|
||||
main.state.add_manual_batch(batch)
|
||||
assert main._import_manual_batches(main.Importer(movies, tv)) == 1
|
||||
rows = main.state.list_manual_batches()
|
||||
assert rows[0]["status"] == "completed"
|
||||
assert (movies / "Movie.mkv").exists()
|
||||
@@ -0,0 +1,41 @@
|
||||
from pathlib import Path
|
||||
|
||||
from importarr.readiness import classify_history_item
|
||||
|
||||
|
||||
ROOT = Path("/tmp/downloads/manual")
|
||||
|
||||
|
||||
def item(**kwargs):
|
||||
data = {"nzo_id": "1", "category": "manual", "status": "Completed", "storage": str(ROOT / "Movie")}
|
||||
data.update(kwargs)
|
||||
return data
|
||||
|
||||
|
||||
def test_completed_manual_is_ready():
|
||||
result = classify_history_item(item(), set(), "manual", ROOT)
|
||||
assert result.ready
|
||||
|
||||
|
||||
def test_wrong_category_ignored():
|
||||
result = classify_history_item(item(category="*"), set(), "manual", ROOT)
|
||||
assert result.state == "ignored"
|
||||
|
||||
|
||||
def test_queue_item_not_ready():
|
||||
result = classify_history_item(item(), {"1"}, "manual", ROOT)
|
||||
assert result.state == "processing"
|
||||
|
||||
|
||||
def test_post_processing_not_ready():
|
||||
for status in ["Queued", "Repairing", "Extracting", "Moving"]:
|
||||
assert classify_history_item(item(status=status), set(), "manual", ROOT).state == "processing"
|
||||
|
||||
|
||||
def test_empty_storage_unknown():
|
||||
assert classify_history_item(item(storage=""), set(), "manual", ROOT).state == "unknown"
|
||||
|
||||
|
||||
def test_unpack_path_not_ready():
|
||||
result = classify_history_item(item(storage=str(ROOT / "_UNPACK_Movie")), set(), "manual", ROOT)
|
||||
assert result.state == "processing"
|
||||
@@ -0,0 +1,20 @@
|
||||
from importarr.scanner import scan_videos
|
||||
|
||||
|
||||
def test_one_row_per_video_with_context(tmp_path):
|
||||
root = tmp_path / "manual"
|
||||
nested = root / "Release.Name" / "hashdir"
|
||||
nested.mkdir(parents=True)
|
||||
(nested / "abc123.mkv").write_bytes(b"x")
|
||||
(nested / "sample.mp4").write_bytes(b"x")
|
||||
rows = scan_videos(root)
|
||||
assert len(rows) == 1
|
||||
assert str(rows[0].relative_path) == "Release.Name/hashdir/abc123.mkv"
|
||||
|
||||
|
||||
def test_transient_folders_ignored(tmp_path):
|
||||
root = tmp_path / "manual"
|
||||
unpack = root / "_UNPACK_Show"
|
||||
unpack.mkdir(parents=True)
|
||||
(unpack / "show.mkv").write_bytes(b"x")
|
||||
assert scan_videos(root) == []
|
||||
@@ -0,0 +1,20 @@
|
||||
def test_health_contains_build_info(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("IMPORTARR_STATE_PATH", str(tmp_path / "state.db"))
|
||||
import importarr.main as main
|
||||
|
||||
payload = main.health()
|
||||
assert payload["status"] == "ok"
|
||||
assert payload["name"] == "Importarr"
|
||||
assert payload["version"]
|
||||
|
||||
|
||||
def test_status_contains_service_configuration(tmp_path, monkeypatch):
|
||||
monkeypatch.setenv("IMPORTARR_STATE_PATH", str(tmp_path / "state.db"))
|
||||
import importarr.main as main
|
||||
|
||||
payload = main.status()
|
||||
assert payload["build"]["name"] == "Importarr"
|
||||
assert "download_root" in payload
|
||||
assert "movies_root" in payload
|
||||
assert "tv_root" in payload
|
||||
assert "auth_enabled" in payload
|
||||
Reference in New Issue
Block a user