epub2pdf: title-based export names, .pdf download headers, security hardening (68 tests green)
This commit is contained in:
@@ -0,0 +1,47 @@
|
||||
"""Job registry behavior: registration shape and the 50-entry eviction cap.
|
||||
|
||||
Unit-level tests against app._register_job — the registry is module-global
|
||||
state that every API test isolates via the autouse fixture.
|
||||
"""
|
||||
import time
|
||||
|
||||
import app
|
||||
|
||||
|
||||
def test_register_job_shape():
|
||||
job_id = app._register_job("x.epub")
|
||||
assert job_id in app.JOBS
|
||||
job = app.JOBS[job_id]
|
||||
assert job["id"] == job_id
|
||||
assert job["epub"] == "x.epub"
|
||||
assert job["status"] == "queued"
|
||||
assert job["progress"] == 0.0
|
||||
assert job["message"] == "queued"
|
||||
assert job["filename"] is None
|
||||
assert job["error"] is None
|
||||
assert job["created"] > 0
|
||||
|
||||
|
||||
def test_job_ids_are_unique():
|
||||
a = app._register_job("a.epub")
|
||||
b = app._register_job("b.epub")
|
||||
assert a != b
|
||||
|
||||
|
||||
def test_registry_evicts_oldest_beyond_50():
|
||||
now = time.time()
|
||||
old_ids = []
|
||||
for i in range(50):
|
||||
jid = app._register_job(f"old{i}.epub")
|
||||
old_ids.append(jid)
|
||||
# Force ascending 'created' so eviction order is deterministic.
|
||||
app.JOBS[jid]["created"] = now - (1000 - i)
|
||||
oldest = old_ids[0]
|
||||
newest_old = old_ids[-1]
|
||||
|
||||
new_id = app._register_job("new.epub")
|
||||
|
||||
assert len(app.JOBS) == 50
|
||||
assert oldest not in app.JOBS, "oldest job must be evicted"
|
||||
assert newest_old in app.JOBS
|
||||
assert new_id in app.JOBS
|
||||
Reference in New Issue
Block a user