test_chat.py 629 B

123456789101112131415161718192021
  1. import pytest
  2. from httpx import AsyncClient, ASGITransport
  3. from app.main import app
  4. pytestmark = pytest.mark.usefixtures("init_checkpointer")
  5. @pytest.mark.asyncio
  6. async def test_chat_endpoint():
  7. transport = ASGITransport(app=app)
  8. async with AsyncClient(transport=transport, base_url="http://test") as client:
  9. resp = await client.post("/api/v1/chat", json={
  10. "query": "你好",
  11. "user_id": 1,
  12. "conversation_id": "",
  13. })
  14. assert resp.status_code == 200
  15. data = resp.json()
  16. assert "answer" in data
  17. assert isinstance(data.get("tasks"), list)