Files
selfrelease fad458b2a7 docs(uiux): UIUX 设计方案大改 + 5 份作业指导书对齐 + 开发任务文档
- UIUX 文档:填充 19 个缺口(多主体画像/健康度/AI+看板/增长域/洞察域/创始人端/OODA/助推/商密)
- UIUX 文档:插入 6 个新章节(十四~十九),旧章节重编号为二十~三十一,更新目录和交叉引用
- 作业指导书 x5:导航改为 6 域分组,新增 Context Bar/工作模式/Insight Rail/决策线程/多工作区等 UI 概念
- 新建 docs/2-task-uiux.md:50 个代码落地开发任务,按 P0-P6 分优先级 + 8 Sprint 规划
- 后端/前端:大量新增模型、路由、组件(来自之前 Phase 开发)
2026-07-19 11:53:38 +08:00

138 lines
4.3 KiB
Python

"""风险事件 CRUD 测试。"""
import pytest
from fastapi.testclient import TestClient
@pytest.fixture
def auth_headers(client: TestClient):
"""注册并登录。"""
client.post(
"/api/v1/auth/register",
json={
"email": "risk_test@example.com",
"password": "password123",
"name": "测试投资经理",
"tenant_name": "测试机构",
"role": "investor",
},
)
resp = client.post(
"/api/v1/auth/login",
json={"email": "risk_test@example.com", "password": "password123"},
)
token = resp.json()["data"]["access_token"]
return {"Authorization": f"Bearer {token}"}
@pytest.fixture
def company_id(client: TestClient, auth_headers: dict):
"""创建测试企业。"""
resp = client.post(
"/api/v1/companies",
json={"name": "风险测试公司", "industry": "AI"},
headers=auth_headers,
)
return resp.json()["data"]["id"]
class TestCreateRisk:
"""创建风险事件。"""
def test_create_success(self, client: TestClient, auth_headers: dict, company_id: str):
response = client.post(
"/api/v1/risks",
json={
"company_id": company_id,
"type": "financial",
"severity": "high",
"title": "现金流预警",
"description": "月度烧钱率超过预期",
"suggested_action": "建议与创始人沟通融资计划",
},
headers=auth_headers,
)
assert response.status_code == 201
data = response.json()
assert data["code"] == 0
assert data["data"]["title"] == "现金流预警"
assert data["data"]["status"] == "open"
assert data["data"]["severity"] == "high"
def test_create_without_auth(self, client: TestClient):
response = client.post(
"/api/v1/risks",
json={"company_id": "x", "type": "financial", "title": "测试"},
)
assert response.status_code == 401
class TestListRisks:
"""风险列表。"""
def test_list_success(self, client: TestClient, auth_headers: dict, company_id: str):
# 先创建一条
client.post(
"/api/v1/risks",
json={"company_id": company_id, "type": "operational", "title": "人员流失"},
headers=auth_headers,
)
response = client.get("/api/v1/risks", headers=auth_headers)
assert response.status_code == 200
data = response.json()
assert data["data"]["total"] >= 1
def test_list_by_status(self, client: TestClient, auth_headers: dict, company_id: str):
response = client.get(
"/api/v1/risks?status=open",
headers=auth_headers,
)
assert response.status_code == 200
data = response.json()
assert all(item["status"] == "open" for item in data["data"]["items"])
class TestUpdateRisk:
"""更新风险事件。"""
def test_update_status(self, client: TestClient, auth_headers: dict, company_id: str):
create_resp = client.post(
"/api/v1/risks",
json={"company_id": company_id, "type": "ai_specific", "title": "AI 依赖风险"},
headers=auth_headers,
)
risk_id = create_resp.json()["data"]["id"]
response = client.put(
f"/api/v1/risks/{risk_id}",
json={"status": "in_progress", "assigned_to": "someone"},
headers=auth_headers,
)
assert response.status_code == 200
data = response.json()
assert data["data"]["status"] == "in_progress"
class TestDeleteRisk:
"""删除风险事件。"""
def test_delete_success(self, client: TestClient, auth_headers: dict, company_id: str):
create_resp = client.post(
"/api/v1/risks",
json={"company_id": company_id, "type": "org", "title": "组织架构风险"},
headers=auth_headers,
)
risk_id = create_resp.json()["data"]["id"]
response = client.delete(
f"/api/v1/risks/{risk_id}",
headers=auth_headers,
)
assert response.status_code == 200
get_resp = client.get(
f"/api/v1/risks/{risk_id}",
headers=auth_headers,
)
assert get_resp.status_code == 404