test: add DELETE endpoint tests and ingest integration tests

This commit is contained in:
2026-07-05 01:38:50 +08:00
parent 4114a168b4
commit 441ba8ab86
3 changed files with 63 additions and 1 deletions
+28
View File
@@ -110,3 +110,31 @@ class TestSecurity:
json={"file_path": "C:\\Windows\\System32\\config\\SAM"},
)
assert response.status_code in (400, 403)
class TestDeleteEndpoint:
"""删除端点."""
def test_delete_nonexistent(self, client):
"""删除不存在的文件返回 404."""
response = client.delete("/api/v1/documents/nonexistent.md")
assert response.status_code == 404
def test_delete_ingested(self, client):
"""删除已入库文件后搜索不再返回."""
# 入库
ingest_resp = client.post(
"/api/v1/ingest",
json={"content": "# Test Delete\nHello.", "file_name": "delete-test.md"},
)
assert ingest_resp.status_code == 200, f"ingest failed: {ingest_resp.json()}"
# 删除
response = client.delete("/api/v1/documents/delete-test.md")
assert response.status_code == 200, f"delete failed: {response.json()}"
# 搜索验证已删除
search_resp = client.post(
"/api/v1/search", json={"query": "Test Delete", "top_k": 3}
)
results = search_resp.json()["results"]
sources = [r["source_file"] for r in results]
assert "delete-test.md" not in sources