feat: Butler-mediated Paperless PDF import #47

Merged
sascha merged 2 commits from feature/paperless-import-20260901 into main 2026-09-01 08:40:55 +02:00
Showing only changes of commit fccd6db089 - Show all commits

View file

@ -46,6 +46,41 @@ def test_health_exposes_current_version():
assert response.json()["version"] == app.VERSION == "2.3.5"
def test_paperless_import_queues_pdf_through_butler(monkeypatch):
captured = {}
def fake_upload(host, command, payload, timeout):
captured.update(host=host, command=command, payload=payload, timeout=timeout)
return 0, "", ""
monkeypatch.setattr(app, "_ssh_bytes", fake_upload)
pdf = b"%PDF-1.7\nvalid-test-payload"
with TestClient(app.app) as client:
response = client.post(
"/paperless/import?filename=Hausordnung%20Stand%2009.05.2022.pdf",
content=pdf,
headers={"Authorization": "Bearer test-token", "Content-Type": "application/pdf"},
)
assert response.status_code == 200
body = response.json()
assert body["status"] == "queued"
assert body["filename"].startswith("Hausordnung_Stand_09.05.2022-")
assert captured["host"] == app.PAPERLESS_SSH
assert captured["payload"] == pdf
assert app.PAPERLESS_CONSUME_DIR in captured["command"]
def test_paperless_import_rejects_non_pdf(monkeypatch):
monkeypatch.setattr(app, "_ssh_bytes", lambda *args: (_ for _ in ()).throw(AssertionError("must not upload")))
with TestClient(app.app) as client:
response = client.post(
"/paperless/import?filename=bad.pdf",
content=b"not a pdf",
headers={"Authorization": "Bearer test-token"},
)
assert response.status_code == 400
def test_ui_serves_self_contained_operator_console():
with TestClient(app.app) as client:
response = client.get("/ui")