fad458b2a7
- UIUX 文档:填充 19 个缺口(多主体画像/健康度/AI+看板/增长域/洞察域/创始人端/OODA/助推/商密) - UIUX 文档:插入 6 个新章节(十四~十九),旧章节重编号为二十~三十一,更新目录和交叉引用 - 作业指导书 x5:导航改为 6 域分组,新增 Context Bar/工作模式/Insight Rail/决策线程/多工作区等 UI 概念 - 新建 docs/2-task-uiux.md:50 个代码落地开发任务,按 P0-P6 分优先级 + 8 Sprint 规划 - 后端/前端:大量新增模型、路由、组件(来自之前 Phase 开发)
159 lines
6.1 KiB
Python
159 lines
6.1 KiB
Python
"""Phase 4 路由冒烟测试 — Alpha归因/退出预测/组合/数字孪生/知识图谱/AAR/Pre-mortem/Agent。"""
|
|
|
|
import pytest
|
|
from fastapi.testclient import TestClient
|
|
|
|
|
|
class TestAlphaRouter:
|
|
"""Alpha 归因路由冒烟测试。"""
|
|
|
|
def test_list_interventions_empty(self, client: TestClient, auth_headers: dict):
|
|
"""GET /alpha 空列表应返回 200。"""
|
|
resp = client.get("/api/v1/alpha", headers=auth_headers)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["code"] == 0
|
|
|
|
def test_create_intervention(self, client: TestClient, auth_headers: dict, company_id: str):
|
|
"""POST /alpha 创建干预事件应返回 200。"""
|
|
resp = client.post(
|
|
"/api/v1/alpha",
|
|
json={
|
|
"company_id": company_id,
|
|
"intervention_type": "战略建议",
|
|
"title": "建议调整产品方向",
|
|
"description": "基于市场变化建议调整产品方向",
|
|
"intervention_date": "2025-07-01",
|
|
},
|
|
headers=auth_headers,
|
|
)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["code"] == 0
|
|
|
|
def test_alpha_without_auth(self, client: TestClient):
|
|
"""无认证应返回 401/403。"""
|
|
resp = client.get("/api/v1/alpha")
|
|
assert resp.status_code in (401, 403)
|
|
|
|
|
|
class TestExitPredictionRouter:
|
|
"""退出预测路由冒烟测试。"""
|
|
|
|
def test_list_exit_predictions_empty(self, client: TestClient, auth_headers: dict):
|
|
"""GET /exit-predictions 空列表应返回 200。"""
|
|
resp = client.get("/api/v1/exit-predictions", headers=auth_headers)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["code"] == 0
|
|
|
|
def test_exit_predictions_without_auth(self, client: TestClient):
|
|
"""无认证应返回 401/403。"""
|
|
resp = client.get("/api/v1/exit-predictions")
|
|
assert resp.status_code in (401, 403)
|
|
|
|
|
|
class TestPortfolioRouter:
|
|
"""组合管理路由冒烟测试。"""
|
|
|
|
def test_rebalance(self, client: TestClient, auth_headers: dict):
|
|
"""POST /portfolio/rebalance 应返回 200。"""
|
|
resp = client.post(
|
|
"/api/v1/portfolio/rebalance",
|
|
json={"company_returns": [{"company_id": "c1", "irr": 0.15}, {"company_id": "c2", "irr": 0.05}]},
|
|
headers=auth_headers,
|
|
)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["code"] == 0
|
|
|
|
def test_monte_carlo(self, client: TestClient, auth_headers: dict):
|
|
"""POST /portfolio/monte-carlo 应返回 200。"""
|
|
resp = client.post(
|
|
"/api/v1/portfolio/monte-carlo",
|
|
json={"company_returns": [{"company_id": "c1", "irr": 0.15}], "iterations": 100},
|
|
headers=auth_headers,
|
|
)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["code"] == 0
|
|
|
|
def test_portfolio_without_auth(self, client: TestClient):
|
|
"""无认证应返回 401/403。"""
|
|
resp = client.post("/api/v1/portfolio/rebalance", json={"company_returns": []})
|
|
assert resp.status_code in (401, 403)
|
|
|
|
|
|
class TestDigitalTwinRouter:
|
|
"""数字孪生路由冒烟测试。"""
|
|
|
|
def test_list_twins_empty(self, client: TestClient, auth_headers: dict, company_id: str):
|
|
"""GET /digital-twins?company_id=xxx 空列表应返回 200。"""
|
|
resp = client.get(f"/api/v1/digital-twins?company_id={company_id}", headers=auth_headers)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["code"] == 0
|
|
|
|
def test_digital_twins_without_auth(self, client: TestClient, company_id: str):
|
|
"""无认证应返回 401/403。"""
|
|
resp = client.get(f"/api/v1/digital-twins?company_id={company_id}")
|
|
assert resp.status_code in (401, 403)
|
|
|
|
|
|
class TestKnowledgeGraphRouter:
|
|
"""知识图谱路由冒烟测试。"""
|
|
|
|
def test_build_graph(self, client: TestClient, auth_headers: dict):
|
|
"""POST /knowledge-graph/build 应返回 200。"""
|
|
resp = client.post(
|
|
"/api/v1/knowledge-graph/build",
|
|
json={"management_experiences": "帮助企业完成A轮融资"},
|
|
headers=auth_headers,
|
|
)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["code"] == 0
|
|
|
|
def test_knowledge_graph_without_auth(self, client: TestClient):
|
|
"""无认证应返回 401/403。"""
|
|
resp = client.post("/api/v1/knowledge-graph/build", json={"management_experiences": "test"})
|
|
assert resp.status_code in (401, 403)
|
|
|
|
|
|
class TestAARRouter:
|
|
"""AAR 复盘路由冒烟测试。"""
|
|
|
|
def test_list_aars_empty(self, client: TestClient, auth_headers: dict):
|
|
"""GET /aars 空列表应返回 200。"""
|
|
resp = client.get("/api/v1/aars", headers=auth_headers)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["code"] == 0
|
|
|
|
def test_aars_without_auth(self, client: TestClient):
|
|
"""无认证应返回 401/403。"""
|
|
resp = client.get("/api/v1/aars")
|
|
assert resp.status_code in (401, 403)
|
|
|
|
|
|
class TestPreMortemRouter:
|
|
"""Pre-mortem 路由冒烟测试。"""
|
|
|
|
def test_list_pre_mortems_empty(self, client: TestClient, auth_headers: dict):
|
|
"""GET /pre-mortems 空列表应返回 200。"""
|
|
resp = client.get("/api/v1/pre-mortems", headers=auth_headers)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["code"] == 0
|
|
|
|
def test_pre_mortems_without_auth(self, client: TestClient):
|
|
"""无认证应返回 401/403。"""
|
|
resp = client.get("/api/v1/pre-mortems")
|
|
assert resp.status_code in (401, 403)
|
|
|
|
|
|
class TestAgentExecutionRouter:
|
|
"""Agent 执行路由冒烟测试。"""
|
|
|
|
def test_list_executions_empty(self, client: TestClient, auth_headers: dict):
|
|
"""GET /agent-executions 空列表应返回 200。"""
|
|
resp = client.get("/api/v1/agent-executions", headers=auth_headers)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["code"] == 0
|
|
|
|
def test_agent_executions_without_auth(self, client: TestClient):
|
|
"""无认证应返回 401/403。"""
|
|
resp = client.get("/api/v1/agent-executions")
|
|
assert resp.status_code in (401, 403)
|