ForcePilot/backend/test/api/test_chat_resume_batch_questions.py
Wenjie Zhang 410dd47c14 refactor: 将后端代码迁移至 backend 目录
- 将 server/, src/, scripts/, test/ 等目录移动到 backend/ 目录下
- 使用 git rename 保留文件历史记录
- 更新 docker-compose.yml 和 api.Dockerfile 配置

WIP: 项目结构重构进行中
2026-03-24 11:08:12 +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