37 lines
1.1 KiB
Python
37 lines
1.1 KiB
Python
"""统一任务接口响应结构回归测试。"""
|
||
from pathlib import Path
|
||
import sys
|
||
|
||
from flask import Flask
|
||
|
||
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "api"))
|
||
|
||
from insurance.generation import task_service
|
||
from insurance.generation.routes import workspace_bp
|
||
|
||
|
||
def test_task_detail_returns_task_as_direct_data(monkeypatch):
|
||
"""任务详情不能重复包裹 code/data,否则前端轮询读不到 status。"""
|
||
monkeypatch.setattr(
|
||
task_service,
|
||
"get_task",
|
||
lambda task_id, user_id: {
|
||
"code": 0,
|
||
"data": {"id": task_id, "userId": user_id, "status": "running"},
|
||
},
|
||
)
|
||
|
||
app = Flask(__name__)
|
||
app.config["GUEST_MODE"] = True
|
||
app.register_blueprint(workspace_bp, url_prefix="/insurance/workspace")
|
||
|
||
response = app.test_client().get(
|
||
"/insurance/workspace/tasks/task-1",
|
||
headers={"Authorization": "Bearer guest_test"},
|
||
)
|
||
|
||
assert response.status_code == 200
|
||
body = response.get_json()
|
||
assert body["data"]["status"] == "running"
|
||
assert "data" not in body["data"]
|