51dc8dc4f6
- FastAPI + Qdrant + Redis + Ollama 技术栈 - L1→L2→L3→chunk 四层分层检索(dense + sparse RRF 融合) - 文档三级总结与 2.5 级回退 - query 解析路由与分类 - /admin 管理页面
39 lines
1.2 KiB
Python
39 lines
1.2 KiB
Python
"""知识分类 API 测试(Qdrant 为 mock,不真实联网)"""
|
||
|
||
from collections.abc import Iterator
|
||
|
||
import pytest
|
||
from fastapi.testclient import TestClient
|
||
|
||
from app.main import app
|
||
from app.models.knowledge import UNCATEGORIZED, load_taxonomy
|
||
from app.services.qdrant import QdrantService
|
||
|
||
|
||
@pytest.fixture
|
||
def client(monkeypatch: pytest.MonkeyPatch) -> Iterator[TestClient]:
|
||
"""TestClient,lifespan 中的 Qdrant 集合初始化替换为空操作"""
|
||
|
||
async def _noop_ensure_collections(self: QdrantService) -> None:
|
||
return None
|
||
|
||
monkeypatch.setattr(QdrantService, "ensure_collections", _noop_ensure_collections)
|
||
with TestClient(app) as test_client:
|
||
yield test_client
|
||
|
||
|
||
def test_list_categories(client: TestClient) -> None:
|
||
"""categories 返回完整 taxonomy,且含 uncategorized"""
|
||
resp = client.get("/api/v1/knowledge/categories")
|
||
|
||
assert resp.status_code == 200
|
||
body = resp.json()
|
||
assert body["code"] == 0
|
||
|
||
expected = load_taxonomy()
|
||
data = body["data"]
|
||
assert data["count"] == len(expected)
|
||
names = [c["name"] for c in data["categories"]]
|
||
assert names == [c.name for c in expected]
|
||
assert UNCATEGORIZED in names
|