test_outline_l2_batch.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. from __future__ import annotations
  2. from decimal import Decimal
  3. from fastapi.testclient import TestClient
  4. from finrep_algo_agent.config import Settings, get_settings
  5. from finrep_algo_agent.main import app
  6. from finrep_algo_agent.schemas.outline import (
  7. ChapterCandidate,
  8. ChapterL1Result,
  9. OutlineL1Request,
  10. OutlineL1Response,
  11. )
  12. def test_outline_l2_batch_stub_mixed_s1_s2() -> None:
  13. def _stub_settings() -> Settings:
  14. return Settings(stub_skills=True)
  15. app.dependency_overrides[get_settings] = _stub_settings
  16. try:
  17. client = TestClient(app)
  18. l1_req = OutlineL1Request(
  19. report_type="项目融资",
  20. agreement_amount=Decimal("40"),
  21. chapter_candidates=[
  22. ChapterCandidate(chapter_id="a1", chapter_name="章A"),
  23. ChapterCandidate(chapter_id="a2", chapter_name="章B"),
  24. ],
  25. )
  26. l1_resp = OutlineL1Response(
  27. chapter_results=[
  28. ChapterL1Result(
  29. chapter_id="a1",
  30. chapter_name="章A",
  31. presentation_enum="S2",
  32. paragraph_count_enum="P0",
  33. reason="不呈现",
  34. ),
  35. ChapterL1Result(
  36. chapter_id="a2",
  37. chapter_name="章B",
  38. presentation_enum="S1",
  39. paragraph_count_enum="P2",
  40. reason="呈现",
  41. ),
  42. ],
  43. overall_logic="总逻辑占位",
  44. )
  45. r = client.post(
  46. "/v1/outline/l2/batch",
  47. json={
  48. "l1_task_snapshot": l1_req.model_dump(mode="json"),
  49. "l1_response": l1_resp.model_dump(mode="json"),
  50. },
  51. )
  52. assert r.status_code == 200, r.text
  53. body = r.json()
  54. assert body["overall_logic"] == "总逻辑占位"
  55. assert len(body["chapters"]) == 2
  56. assert body["chapters"][0]["chapter_id"] == "a1"
  57. assert body["chapters"][0]["l2"]["chapter_structure"] == []
  58. assert body["chapters"][1]["chapter_id"] == "a2"
  59. assert body["chapters"][1]["l2"]["chapter_structure"]
  60. finally:
  61. app.dependency_overrides.clear()