chore: 502 bei propfind-fail, min_length path, exact-call assertion

This commit is contained in:
2026-05-04 22:45:23 +02:00
parent 8c50ab008c
commit a91150c41f
2 changed files with 27 additions and 10 deletions

View File

@@ -4,8 +4,8 @@ from pathlib import PurePosixPath
from urllib.parse import unquote from urllib.parse import unquote
import httpx import httpx
from fastapi import APIRouter, BackgroundTasks, Header, status from fastapi import APIRouter, BackgroundTasks, Header, HTTPException, status
from pydantic import BaseModel from pydantic import BaseModel, Field
from app.config import get_settings from app.config import get_settings
from app.ingest.extractors import SUPPORTED_TYPES from app.ingest.extractors import SUPPORTED_TYPES
@@ -19,7 +19,7 @@ router = APIRouter()
class BulkRequest(BaseModel): class BulkRequest(BaseModel):
path: str path: str = Field(min_length=1)
PROPFIND_BODY = """<?xml version="1.0"?> PROPFIND_BODY = """<?xml version="1.0"?>
@@ -74,12 +74,19 @@ async def bulk_import(
settings = get_settings() settings = get_settings()
verify_secret(x_webhook_secret, settings.webhook_secret) verify_secret(x_webhook_secret, settings.webhook_secret)
files = await list_files_recursive( try:
settings.nextcloud_webdav_url, files = await list_files_recursive(
settings.nextcloud_user, settings.nextcloud_webdav_url,
settings.nextcloud_app_password, settings.nextcloud_user,
body.path, settings.nextcloud_app_password,
) body.path,
)
except (RuntimeError, httpx.HTTPError, ET.ParseError) as exc:
logger.exception(
"bulk listing failed",
extra={"event": "bulk_listing_failed", "path": body.path, "error": str(exc)},
)
raise HTTPException(status_code=502, detail="webdav listing failed") from exc
dispatched = 0 dispatched = 0
for f in files: for f in files:

View File

@@ -1,6 +1,9 @@
from unittest.mock import AsyncMock from unittest.mock import AsyncMock, call
from fastapi.testclient import TestClient from fastapi.testclient import TestClient
from app.webhook.models import EventType
def _make_app(monkeypatch): def _make_app(monkeypatch):
monkeypatch.setenv("NEXTCLOUD_WEBDAV_URL", "http://nc") monkeypatch.setenv("NEXTCLOUD_WEBDAV_URL", "http://nc")
@@ -45,6 +48,13 @@ def test_bulk_import_lists_and_dispatches(monkeypatch):
assert r.status_code == 202 assert r.status_code == 202
body = r.json() body = r.json()
assert body["dispatched"] == 2 # only .pdf and .docx, not the json sidecar assert body["dispatched"] == 2 # only .pdf and .docx, not the json sidecar
process_mock.assert_has_calls(
[
call("Documents/THB/Studium/2.Semester/Databases/a.pdf", EventType.CREATED),
call("Documents/THB/Studium/2.Semester/Databases/b.docx", EventType.CREATED),
]
)
assert process_mock.await_count == 2
def test_bulk_import_rejects_wrong_secret(monkeypatch): def test_bulk_import_rejects_wrong_secret(monkeypatch):