精简后端功能模块并补充教学互动

This commit is contained in:
刘金宝
2026-06-08 16:49:45 +08:00
parent 11b1712b01
commit f0cdc454b3
18 changed files with 1120 additions and 1194 deletions
+41 -15
View File
@@ -86,9 +86,6 @@ def run_api_contract_tests() -> None:
auth_me_operation = openapi_payload["paths"]["/api/v1/auth/me"]["get"]
assert any("HTTPBearer" in item for item in auth_me_operation.get("security", []))
assert "HTTPBearer" in openapi_payload["components"]["securitySchemes"]
assert "/api/v1/imports/case-sql/preview" not in openapi_payload["paths"]
assert "/api/v1/imports/case-sql/apply" not in openapi_payload["paths"]
assert "/api/v1/cases/{case_id}/delete-preview" not in openapi_payload["paths"]
assert "delete" not in openapi_payload["paths"]["/api/v1/cases/{case_id}"]
assert "/api/v1/training-config/recommended" in openapi_payload["paths"]
assert "/api/v1/training-config/options" in openapi_payload["paths"]
@@ -98,11 +95,52 @@ def run_api_contract_tests() -> None:
assert "/api/v1/sessions/{session_id}/physical-exams/{item_code}" in openapi_payload["paths"]
assert "/api/v1/sessions/{session_id}/auxiliary-exams/{item_code}" in openapi_payload["paths"]
assert "/api/v1/evaluations/{evaluation_id}/download-pdf" in openapi_payload["paths"]
assert "/api/v1/teaching/cases/{case_id}/items" in openapi_payload["paths"]
assert "/api/v1/teaching/evaluation" in openapi_payload["paths"]
cases = client.get("/api/v1/cases", headers=headers)
assert cases.status_code == 200
case_id = cases.json()["data"]["items"][0]["id"]
teaching_items = client.get(f"/api/v1/teaching/cases/{case_id}/items", headers=headers)
assert teaching_items.status_code == 200
teaching_data = teaching_items.json()["data"]
assert teaching_data["case"]["case_id"] == case_id
assert teaching_data["questions"]
assert teaching_data["questions"][0]["options"]
assert teaching_data["questions"][0]["answer"]
assert "analysis" in teaching_data["questions"][0]
teaching_answers = [
{"question_id": item["question_id"], "selected_answer": item["answer"]}
for item in teaching_data["questions"]
]
teaching_evaluation = client.post(
"/api/v1/teaching/evaluation",
headers=headers,
json={"case_id": case_id, "answers": teaching_answers, "score_type": "percentage"},
)
assert teaching_evaluation.status_code == 200
teaching_evaluation_id = teaching_evaluation.json()["data"]["evaluation_id"]
assert teaching_evaluation.json()["data"]["session_id"]
assert teaching_evaluation.json()["data"]["score_details"]
teaching_detail = client.get(f"/api/v1/evaluations/{teaching_evaluation_id}", headers=headers)
assert teaching_detail.status_code == 200
assert teaching_detail.json()["data"]["evaluation_id"] == teaching_evaluation_id
teaching_pdf_download = client.get(f"/api/v1/evaluations/{teaching_evaluation_id}/download-pdf", headers=headers)
assert teaching_pdf_download.status_code == 200
assert teaching_pdf_download.headers["content-type"].startswith("application/pdf")
assert teaching_pdf_download.content.startswith(b"%PDF")
cross_user_teaching_detail = client.get(
f"/api/v1/evaluations/{teaching_evaluation_id}",
headers={"Authorization": "Bearer api_user_002_token", "X-Entry-Scene": "api_test"},
)
assert cross_user_teaching_detail.status_code == 404
assert cross_user_teaching_detail.json()["code"] == "EVALUATION_NOT_FOUND"
recommended_config = client.get(f"/api/v1/training-config/recommended?case_id={case_id}", headers=headers)
assert recommended_config.status_code == 200
assert recommended_config.json()["data"]["recommended"]["visit_environment"] == "outpatient"
@@ -320,18 +358,6 @@ def run_api_contract_tests() -> None:
assert teaching_hint.status_code == 400
assert teaching_hint.json()["code"] == "SESSION_STATUS_INVALID"
llm_fast = client.post("/api/v1/llm/test/deepseek-fast", headers=headers, json={"message": "hello"})
assert llm_fast.status_code == 200
assert llm_fast.json()["code"] == "OK"
assert llm_fast.json()["data"]["stream"] is False
llm_reason = client.post("/api/v1/llm/test/deepseek-reason", headers=headers, json={"message": "hello"})
assert llm_reason.status_code == 200
assert llm_reason.json()["code"] == "OK"
assert "total_latency_ms" in llm_reason.json()["data"]
if __name__ == "__main__":
run_api_contract_tests()
print("api contract tests passed")