|
|
@@ -0,0 +1,44 @@
|
|
|
+import pytest
|
|
|
+from httpx import AsyncClient, ASGITransport
|
|
|
+from app.main import app
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.asyncio
|
|
|
+async def test_health_check():
|
|
|
+ transport = ASGITransport(app=app)
|
|
|
+ async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
|
+ resp = await client.get("/health")
|
|
|
+ assert resp.status_code == 200
|
|
|
+ assert resp.json() == {"status": "ok"}
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.asyncio
|
|
|
+async def test_recommend_empty_tags():
|
|
|
+ """空标签应返回空列表"""
|
|
|
+ transport = ASGITransport(app=app)
|
|
|
+ async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
|
+ resp = await client.post("/api/v1/recommend", json={
|
|
|
+ "user_id": 1,
|
|
|
+ "tags": [],
|
|
|
+ "query": "推荐一些适合孩子的活动",
|
|
|
+ "limit": 3,
|
|
|
+ })
|
|
|
+ assert resp.status_code == 200
|
|
|
+ data = resp.json()
|
|
|
+ assert "items" in data
|
|
|
+
|
|
|
+
|
|
|
+@pytest.mark.asyncio
|
|
|
+async def test_recommend_with_tags():
|
|
|
+ """带标签应返回推荐结果"""
|
|
|
+ transport = ASGITransport(app=app)
|
|
|
+ async with AsyncClient(transport=transport, base_url="http://test") as client:
|
|
|
+ resp = await client.post("/api/v1/recommend", json={
|
|
|
+ "user_id": 1,
|
|
|
+ "tags": ["益生菌", "肠胃"],
|
|
|
+ "limit": 3,
|
|
|
+ })
|
|
|
+ assert resp.status_code == 200
|
|
|
+ data = resp.json()
|
|
|
+ assert "items" in data
|
|
|
+ assert "source" in data
|