Files
AIOA/ai-service/tests/test_leave_progress.py
T
2026-07-18 19:20:07 +08:00

58 lines
2.2 KiB
Python

from fastapi.testclient import TestClient
from app.main import app, get_progress_gateway
from app.models import LeaveProgressAnswerRequest
class FakeProgressGateway:
async def answer_progress(self, request: LeaveProgressAnswerRequest) -> str:
assert request.context.requestId == "leave-1"
assert request.context.activeTaskNames == ["主管审批"]
return "当前状态为审批中,正在等待主管审批。"
def test_answers_only_from_authorized_structured_context() -> None:
app.dependency_overrides[get_progress_gateway] = lambda: FakeProgressGateway()
try:
response = TestClient(app).post(
"/v1/leave-progress/answer",
json={
"question": "我的请假到哪一步了?",
"timezone": "Asia/Shanghai",
"context": {
"requestId": "leave-1",
"type": "ANNUAL",
"status": "PENDING",
"startsAt": "2026-07-20T01:00:00Z",
"endsAt": "2026-07-20T09:00:00Z",
"activeTaskNames": ["主管审批"],
"completedTaskNames": [],
"processEnded": False,
"timelineEventTypes": ["LEAVE_REQUEST_SUBMITTED"],
},
},
)
finally:
app.dependency_overrides.clear()
assert response.status_code == 200
assert response.json() == {"answer": "当前状态为审批中,正在等待主管审批。", "model": "qwen-plus"}
assert "processVariables" not in response.text
def test_rejects_unknown_context_fields() -> None:
response = TestClient(app).post(
"/v1/leave-progress/answer",
json={
"question": "进度?",
"timezone": "Asia/Shanghai",
"context": {
"requestId": "leave-1", "type": "ANNUAL", "status": "PENDING",
"startsAt": "2026-07-20T01:00:00Z", "endsAt": "2026-07-20T09:00:00Z",
"activeTaskNames": [], "completedTaskNames": [], "processEnded": False,
"timelineEventTypes": [], "processVariables": {"approverId": "secret"},
},
},
)
assert response.status_code == 422