ForcePilot/backend/test/api/test_chat_resume_batch_questions.py
Wenjie Zhang e4ae12dc75 refactor: 重构并清理多个模块的测试
- 移除了文件系统和沙盒路由器的过时集成测试。
- 更新了文件系统路由器测试,确保正确的身份验证和线程所有权检查。
- 调整了沙盒端到端测试,以改进附件处理和命令执行。
- 修改了设置路由器测试,对未授权访问返回404而不是401/403。
- 增强了任务路由器测试,以处理精简模式场景并确保任务创建和查询按预期工作。
- 优化了查看器文件系统测试,使用附件上传代替直接文件写入。
- 改进了技能后端测试中的错误处理,为越界访问引发适当的异常。
2026-03-25 06:32:14 +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 "Input should be a valid dictionary" 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