Nenne in der Paperless-Fehlermeldung Statuscode, Pfad und Grund, damit sich eine abgelehnte Abfrage zuordnen lässt.
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
38406d3293
commit
0f2b7a8fab
2 files changed
+43
-1
No files matched your search
@@ -10,6 +10,8 @@ import io
|
||||
import zipfile
|
||||
from email.parser import BytesParser
|
||||
|
||||
import pytest
|
||||
|
||||
from app.media.port import MemoryAdapter
|
||||
from app.sourceaccess import borrow_original, complete_borrow
|
||||
from app.sourceregistry import SourceModule, unregister_source, register_source
|
||||
@@ -652,6 +654,35 @@ def test_paperless_custom_field_filters_use_the_instance_fields(client, db, monk
|
||||
)
|
||||
|
||||
|
||||
def test_paperless_refusal_names_the_status_and_reason(monkeypatch):
|
||||
import io
|
||||
from urllib.error import HTTPError
|
||||
|
||||
import app.sources as sources
|
||||
from app.core.errors import Problem
|
||||
|
||||
def refuse(code, body):
|
||||
def fake(request, timeout=0):
|
||||
raise HTTPError(request.full_url, code, "x", {}, io.BytesIO(body))
|
||||
|
||||
return fake
|
||||
|
||||
monkeypatch.setattr(sources, "urlopen", refuse(400, '{"custom_field_query": ["Ungültig"]}'.encode()))
|
||||
with pytest.raises(Problem) as caught:
|
||||
sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {"page_size": "20"})
|
||||
assert "HTTP 400 auf /api/documents/" in caught.value.detail
|
||||
assert "custom_field_query" in caught.value.detail
|
||||
assert "token-alpha" not in caught.value.detail
|
||||
monkeypatch.setattr(sources, "urlopen", refuse(500, b"<html>Fehler</html>"))
|
||||
with pytest.raises(Problem) as caught:
|
||||
sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {})
|
||||
assert caught.value.detail.endswith("(HTTP 500 auf /api/documents/).")
|
||||
monkeypatch.setattr(sources, "urlopen", refuse(403, b"{}"))
|
||||
with pytest.raises(Problem) as caught:
|
||||
sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {})
|
||||
assert "Schlüssel abgelehnt" in caught.value.detail
|
||||
|
||||
|
||||
def test_paperless_thumbnail_is_bound_to_the_owners_instance(client, db, monkeypatch):
|
||||
import app.sources as sources
|
||||
|
||||
|
||||
Reference in new issue
Block a user