ForcePilot/test/api/test_chat_resume_batch_questions.py
Wenjie Zhang f2096b4004 feat: 增强问题工具功能,支持多问题处理
- 新增问题和选项规范化工具函数 (question_utils.py)
- 优化 resume_agent_chat 接口的 answer 参数处理,支持列表类型
- 前端 HumanApprovalModal 支持多问题标签页切换
- 改进问题工具组件交互体验
- 添加批量问题测试用例
- 更新文档
2026-03-17 03:39:48 +08:00

65 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

"""
Integration tests for batch question resume payload validation.
"""
from __future__ import annotations
import pytest
pytestmark = [pytest.mark.asyncio, pytest.mark.integration]
async def test_resume_rejects_non_dict_answer(test_client, admin_headers):
response = await test_client.post(
"/api/chat/agent/dummy-agent/resume",
json={"thread_id": "thread-test", "answer": "approve"},
headers=admin_headers,
)
assert response.status_code == 422
assert "answer 必须是对象映射" in response.text
async def test_resume_rejects_empty_answer_map(test_client, admin_headers):
response = await test_client.post(
"/api/chat/agent/dummy-agent/resume",
json={"thread_id": "thread-test", "answer": {}},
headers=admin_headers,
)
assert response.status_code == 422
assert "answer 不能为空" in response.text
async def test_resume_rejects_empty_question_id(test_client, admin_headers):
response = await test_client.post(
"/api/chat/agent/dummy-agent/resume",
json={"thread_id": "thread-test", "answer": {"": "选项A"}},
headers=admin_headers,
)
assert response.status_code == 422
assert "question_id 不能为空" in response.text
async def test_resume_rejects_empty_answer_text(test_client, admin_headers):
response = await test_client.post(
"/api/chat/agent/dummy-agent/resume",
json={"thread_id": "thread-test", "answer": {"q1": " "}},
headers=admin_headers,
)
assert response.status_code == 422
assert "answer 不能为空" in response.text
async def test_resume_accepts_batch_answer_map(test_client, admin_headers):
response = await test_client.post(
"/api/chat/agent/dummy-agent/resume",
json={"thread_id": "thread-test", "answer": {"q1": "选项A", "q2": ["选项B", "选项C"]}},
headers=admin_headers,
)
# 通过参数校验后会进入流式逻辑dummy-agent 不存在时也会以 200 返回 error chunk。
assert response.status_code == 200