From a1d297ac309b2b53428c1f522e754df31a6ee07a Mon Sep 17 00:00:00 2001 From: CC Worker Date: Sat, 6 Jun 2026 18:41:23 +0000 Subject: [PATCH] test(exam): replace StorageAdmin with fake class in scan tests Co-Authored-By: Claude Opus 4.8 --- tests/test_exam_batches.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/tests/test_exam_batches.py b/tests/test_exam_batches.py index 37d90a5..d7e9401 100644 --- a/tests/test_exam_batches.py +++ b/tests/test_exam_batches.py @@ -251,8 +251,7 @@ def test_scan_rejects_non_pdf_mime(): assert r.status_code == 415 -def test_scan_rejects_spoofed_pdf(monkeypatch): - monkeypatch.setattr(batches_mod.StorageAdmin, "upload_file", lambda *a, **k: None, raising=False) +def test_scan_rejects_spoofed_pdf(): c = make_client(_batch_store()) r = c.post("/api/exam/batches/b1/scans", files={"file": ("x.pdf", b"not really a pdf", "application/pdf")}, data={"matching_method": "manual"}) assert r.status_code == 415 # magic-byte sniff @@ -265,8 +264,13 @@ def test_scan_rejects_oversize(monkeypatch): assert r.status_code == 413 +class _FakeStorage: + def upload_file(self, *a, **k): + return None + + def test_scan_manual_match_happy(monkeypatch): - monkeypatch.setattr(batches_mod.StorageAdmin, "upload_file", lambda self, *a, **k: None, raising=False) + monkeypatch.setattr(batches_mod, "StorageAdmin", _FakeStorage) store = _batch_store() c = make_client(store) r = c.post("/api/exam/batches/b1/scans", @@ -279,7 +283,7 @@ def test_scan_manual_match_happy(monkeypatch): def test_scan_denied_for_non_owner(monkeypatch): - monkeypatch.setattr(batches_mod.StorageAdmin, "upload_file", lambda self, *a, **k: None, raising=False) + monkeypatch.setattr(batches_mod, "StorageAdmin", _FakeStorage) store = _batch_store() c = make_client(store, user_id="someone-else") r = c.post("/api/exam/batches/b1/scans", files={"file": ("x.pdf", b"%PDF-1.7", "application/pdf")}, data={"matching_method": "manual"})