Behebe die fehlschlagenden Paperless-Tests und lasse test.yml nur noch nach dem Dev-Deploy laufen.
Deploy Development / deploy (push) Successful in 52s
Deploy Development / deploy (push) Successful in 52s
Der Hinweis zu Tags und Zusatzfeld sitzt wieder in paperless_documents, damit die Signatur von _paperless_get bleibt. Der Push-Trigger entfällt, weil er einen zweiten Lauf auf derselben Testdatenbank startete. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
6e1b0916a6
commit
bee48bf4a5
4 files changed
+32
-17
No files matched your search
@@ -418,9 +418,13 @@ def paperless_documents(conn, owner_id: UUID, query: str, connector_id: UUID | N
|
||||
names = _paperless_lookup(row["id"], base, row["secret"])
|
||||
params = _paperless_params(query, options, names["custom_fields"])
|
||||
# Observed on a real instance: all-tags together with a custom field makes Paperless answer 500.
|
||||
clash = "," in params.get("tags__id__all", "") and "custom_field_query" in params
|
||||
hint = "Das tritt auf, wenn „Alle gewählten Tags“ mit einem Zusatzfeld zusammentrifft. Wähle „Mindestens eines“ oder lass das Zusatzfeld weg." if clash else ""
|
||||
payload = _paperless_get(base, row["secret"], "/api/documents/", params, hint)
|
||||
try:
|
||||
payload = _paperless_get(base, row["secret"], "/api/documents/", params)
|
||||
except Problem as problem:
|
||||
clash = "," in params.get("tags__id__all", "") and "custom_field_query" in params
|
||||
if clash and "HTTP 5" in problem.detail:
|
||||
raise unprocessable(f"{problem.detail} Das tritt auf, wenn „Alle gewählten Tags“ mit einem Zusatzfeld zusammentrifft. Wähle „Mindestens eines“ oder lass das Zusatzfeld weg.") from problem
|
||||
raise
|
||||
assert_still_owned(conn, row["id"], owner_id)
|
||||
terms = _search_terms(query, (options or {}).get("title"))
|
||||
items = []
|
||||
@@ -1008,7 +1012,7 @@ def _filename(disposition: str | None) -> str:
|
||||
return value.replace("\\", "").replace("/", "")[:180]
|
||||
|
||||
|
||||
def _paperless_get(base: str, token: str, path: str, params: dict, hint: str = "") -> dict:
|
||||
def _paperless_get(base: str, token: str, path: str, params: dict) -> dict:
|
||||
url = f"{base}{path}?{urlencode(params)}"
|
||||
request = Request(url, headers={"Authorization": f"Token {token}", "Accept": "application/json"})
|
||||
try:
|
||||
@@ -1017,8 +1021,7 @@ def _paperless_get(base: str, token: str, path: str, params: dict, hint: str = "
|
||||
except HTTPError as exc:
|
||||
if exc.code in {401, 403}:
|
||||
raise unprocessable("Paperless hat den Schlüssel abgelehnt.") from exc
|
||||
advice = f" {hint}" if hint and exc.code >= 500 else ""
|
||||
raise unprocessable(f"Paperless hat die Anfrage nicht beantwortet ({_refusal(exc, path)}).{advice}") from exc
|
||||
raise unprocessable(f"Paperless hat die Anfrage nicht beantwortet ({_refusal(exc, path)}).") from exc
|
||||
except (URLError, TimeoutError, json.JSONDecodeError) as exc:
|
||||
raise unprocessable("Paperless ist nicht erreichbar.") from exc
|
||||
|
||||
|
||||
@@ -12,6 +12,7 @@ from email.parser import BytesParser
|
||||
|
||||
import pytest
|
||||
|
||||
from app.core.errors import unprocessable
|
||||
from app.media.port import MemoryAdapter
|
||||
from app.sourceaccess import borrow_original, complete_borrow
|
||||
from app.sourceregistry import SourceModule, unregister_source, register_source
|
||||
@@ -593,9 +594,12 @@ def test_paperless_custom_field_filters_use_the_instance_fields(client, db, monk
|
||||
]
|
||||
}
|
||||
if path == "/api/documents/":
|
||||
if failing:
|
||||
raise unprocessable(failing[0])
|
||||
return {"count": 0, "results": []}
|
||||
return {"results": []}
|
||||
|
||||
failing = []
|
||||
monkeypatch.setattr(sources, "_paperless_get", fake_get)
|
||||
ada = Actor(client, "ada-custom@example.test", "Ada Custom")
|
||||
register(db, ada.email, ada.name)
|
||||
@@ -652,6 +656,21 @@ def test_paperless_custom_field_filters_use_the_instance_fields(client, db, monk
|
||||
params={"connector_id": first["id"], "custom": "kein json"},
|
||||
status=422,
|
||||
)
|
||||
# Paperless answers 500 for all-tags together with a custom field: the message names that pairing.
|
||||
failing.append("Paperless hat die Anfrage nicht beantwortet (HTTP 500 auf /api/documents/).")
|
||||
row = json.dumps([{"field": "2", "op": "exists", "value": True}])
|
||||
|
||||
def refused(extra):
|
||||
return ada.request(
|
||||
"GET",
|
||||
"/api/v1/sources/paperless/documents",
|
||||
params={"connector_id": first["id"], "custom": row, **extra},
|
||||
status=422,
|
||||
)
|
||||
|
||||
assert "Alle gewählten Tags" in str(refused({"tag": "1,2"}))
|
||||
assert "Alle gewählten Tags" not in str(refused({"tag": "1,2", "tag_mode": "any"}))
|
||||
assert "Alle gewählten Tags" not in str(refused({"tag": "1"}))
|
||||
|
||||
|
||||
def test_paperless_refusal_names_the_status_and_reason(monkeypatch):
|
||||
@@ -677,13 +696,6 @@ def test_paperless_refusal_names_the_status_and_reason(monkeypatch):
|
||||
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/).")
|
||||
with pytest.raises(Problem) as caught:
|
||||
sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {}, "Hinweis.")
|
||||
assert caught.value.detail.endswith("(HTTP 500 auf /api/documents/). Hinweis.")
|
||||
monkeypatch.setattr(sources, "urlopen", refuse(400, b"{}"))
|
||||
with pytest.raises(Problem) as caught:
|
||||
sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {}, "Hinweis.")
|
||||
assert "Hinweis" not in caught.value.detail
|
||||
monkeypatch.setattr(sources, "urlopen", refuse(403, b"{}"))
|
||||
with pytest.raises(Problem) as caught:
|
||||
sources._paperless_get("https://paper.example.test", "token-alpha", "/api/documents/", {})
|
||||
|
||||
Reference in new issue
Block a user