test_analyze.py 950 B

123456789101112131415161718192021222324252627282930
  1. import pytest
  2. from httpx import AsyncClient, ASGITransport
  3. from app.main import app
  4. @pytest.mark.asyncio
  5. async def test_analyze_endpoint():
  6. transport = ASGITransport(app=app)
  7. async with AsyncClient(transport=transport, base_url="http://test") as client:
  8. resp = await client.post("/api/v1/analyze", json={
  9. "report_id": 1,
  10. "user_id": 1,
  11. "focus": "overall",
  12. })
  13. assert resp.status_code == 200
  14. data = resp.json()
  15. assert "analysis" in data
  16. @pytest.mark.asyncio
  17. async def test_analyze_missing_report():
  18. transport = ASGITransport(app=app)
  19. async with AsyncClient(transport=transport, base_url="http://test") as client:
  20. resp = await client.post("/api/v1/analyze", json={
  21. "report_id": -1,
  22. "user_id": 1,
  23. })
  24. assert resp.status_code == 200
  25. data = resp.json()
  26. assert isinstance(data.get("analysis"), str)