48 lines
1.8 KiB
Python
48 lines
1.8 KiB
Python
from importarr.state import State
|
|
|
|
|
|
def test_delete_queue_items_by_state_can_target_reason(tmp_path):
|
|
state = State(tmp_path / "state.db")
|
|
state.upsert_queue_item(source_type="sab", source_id="stale", name="Stale", state="ignored", reason="SAB category is not owned by Importarr")
|
|
state.upsert_queue_item(source_type="sab", source_id="other", name="Other", state="ignored", reason="other reason")
|
|
|
|
assert state.delete_queue_items_by_state("sab", "ignored", "SAB category is not owned by Importarr") == 1
|
|
|
|
rows = state.list_queue_items()
|
|
assert len(rows) == 1
|
|
assert rows[0]["source_id"] == "other"
|
|
|
|
|
|
def test_upsert_preserves_terminal_state_by_default(tmp_path):
|
|
state = State(tmp_path / "state.db")
|
|
state.upsert_queue_item(source_type="manual", source_id="a", name="A.mkv", state="failed", reason="boom")
|
|
|
|
updated = state.upsert_queue_item(source_type="manual", source_id="a", name="A.mkv", state="ready", reason="rescanned")
|
|
|
|
assert updated["state"] == "failed"
|
|
assert updated["reason"] == "boom"
|
|
|
|
|
|
def test_claim_next_queue_item_marks_importing(tmp_path):
|
|
state = State(tmp_path / "state.db")
|
|
state.upsert_queue_item(source_type="manual", source_id="a", name="A.mkv", state="ready")
|
|
|
|
row = state.claim_next_queue_item("worker-1")
|
|
|
|
assert row is not None
|
|
assert row["state"] == "importing"
|
|
assert row["claimed_by"] == "worker-1"
|
|
|
|
|
|
def test_release_stale_claims_requeues_importing_items(tmp_path):
|
|
state = State(tmp_path / "state.db")
|
|
state.upsert_queue_item(source_type="manual", source_id="a", name="A.mkv", state="ready")
|
|
state.claim_next_queue_item("worker-1")
|
|
|
|
released = state.release_stale_claims("worker-1")
|
|
row = state.get_queue_item(1)
|
|
|
|
assert released == 1
|
|
assert row["state"] == "retrying"
|
|
assert row["claimed_by"] is None
|