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 开发)
154 lines
4.9 KiB
Python
154 lines
4.9 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": "report_test@example.com",
|
|
"password": "password123",
|
|
"name": "测试投资经理",
|
|
"tenant_name": "测试机构",
|
|
"role": "investor",
|
|
},
|
|
)
|
|
resp = client.post(
|
|
"/api/v1/auth/login",
|
|
json={"email": "report_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):
|
|
"""创建测试企业,返回 ID。"""
|
|
resp = client.post(
|
|
"/api/v1/companies",
|
|
json={"name": "月报测试公司", "industry": "AI"},
|
|
headers=auth_headers,
|
|
)
|
|
return resp.json()["data"]["id"]
|
|
|
|
|
|
class TestCreateReport:
|
|
"""创建月报测试。"""
|
|
|
|
def test_create_success(self, client: TestClient, auth_headers: dict, company_id: str):
|
|
"""正常创建月报。"""
|
|
response = client.post(
|
|
"/api/v1/reports",
|
|
json={
|
|
"company_id": company_id,
|
|
"period_year": 2026,
|
|
"period_month": 7,
|
|
"raw_content": "本月营收增长20%",
|
|
},
|
|
headers=auth_headers,
|
|
)
|
|
assert response.status_code == 201
|
|
data = response.json()
|
|
assert data["code"] == 0
|
|
assert data["data"]["period_year"] == 2026
|
|
assert data["data"]["period_month"] == 7
|
|
assert data["data"]["status"] == "draft"
|
|
|
|
def test_create_duplicate(self, client: TestClient, auth_headers: dict, company_id: str):
|
|
"""同年月重复创建应返回 409。"""
|
|
# 先创建一个
|
|
client.post(
|
|
"/api/v1/reports",
|
|
json={"company_id": company_id, "period_year": 2026, "period_month": 6},
|
|
headers=auth_headers,
|
|
)
|
|
# 再创建同月
|
|
response = client.post(
|
|
"/api/v1/reports",
|
|
json={"company_id": company_id, "period_year": 2026, "period_month": 6},
|
|
headers=auth_headers,
|
|
)
|
|
assert response.status_code == 409
|
|
|
|
|
|
class TestListReports:
|
|
"""月报列表测试。"""
|
|
|
|
def test_list_success(self, client: TestClient, auth_headers: dict, company_id: str):
|
|
"""获取月报列表。"""
|
|
response = client.get("/api/v1/reports", headers=auth_headers)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["code"] == 0
|
|
assert data["data"]["total"] >= 1
|
|
|
|
def test_list_by_company(self, client: TestClient, auth_headers: dict, company_id: str):
|
|
"""按企业筛选。"""
|
|
response = client.get(
|
|
f"/api/v1/reports?company_id={company_id}",
|
|
headers=auth_headers,
|
|
)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert all(item["company_id"] == company_id for item in data["data"]["items"])
|
|
|
|
|
|
class TestSubmitReport:
|
|
"""提交月报测试。"""
|
|
|
|
def test_submit_success(self, client: TestClient, auth_headers: dict, company_id: str):
|
|
"""正常提交月报。"""
|
|
create_resp = client.post(
|
|
"/api/v1/reports",
|
|
json={"company_id": company_id, "period_year": 2026, "period_month": 5},
|
|
headers=auth_headers,
|
|
)
|
|
report_id = create_resp.json()["data"]["id"]
|
|
|
|
response = client.post(
|
|
f"/api/v1/reports/{report_id}/submit",
|
|
headers=auth_headers,
|
|
)
|
|
assert response.status_code == 200
|
|
data = response.json()
|
|
assert data["data"]["status"] == "submitted"
|
|
assert data["data"]["submitted_at"] is not None
|
|
|
|
def test_submit_nonexistent(self, client: TestClient, auth_headers: dict):
|
|
"""提交不存在的月报应返回 404。"""
|
|
response = client.post(
|
|
"/api/v1/reports/nonexistent-id/submit",
|
|
headers=auth_headers,
|
|
)
|
|
assert response.status_code == 404
|
|
|
|
|
|
class TestDeleteReport:
|
|
"""删除月报测试。"""
|
|
|
|
def test_delete_success(self, client: TestClient, auth_headers: dict, company_id: str):
|
|
"""正常删除。"""
|
|
create_resp = client.post(
|
|
"/api/v1/reports",
|
|
json={"company_id": company_id, "period_year": 2026, "period_month": 4},
|
|
headers=auth_headers,
|
|
)
|
|
report_id = create_resp.json()["data"]["id"]
|
|
|
|
response = client.delete(
|
|
f"/api/v1/reports/{report_id}",
|
|
headers=auth_headers,
|
|
)
|
|
assert response.status_code == 200
|
|
|
|
# 验证已删除
|
|
get_resp = client.get(
|
|
f"/api/v1/reports/{report_id}",
|
|
headers=auth_headers,
|
|
)
|
|
assert get_resp.status_code == 404
|