From fccd6db08940350f12b8b86416e95c233533321e Mon Sep 17 00:00:00 2001 From: sascha Date: Tue, 1 Sep 2026 08:40:53 +0200 Subject: [PATCH] feat: add Butler-mediated Paperless PDF import --- tests/test_app.py | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/tests/test_app.py b/tests/test_app.py index fe4a29b..67c0621 100644 --- a/tests/test_app.py +++ b/tests/test_app.py @@ -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")