所有需求实现完成

This commit is contained in:
Your Name
2026-02-01 15:57:42 +08:00
parent e651b92d7c
commit 6e1174a59a
16 changed files with 2354 additions and 173 deletions
+63 -5
View File
@@ -10,6 +10,64 @@ def _auth_header(token: str) -> dict:
return {"Authorization": f"Bearer {token}"}
# ---------- POST /api/projects/statisticsAPI 文档第 3 节)----------
def test_statistics_without_token_returns_401(client):
"""项目统计无 token 时返回 401"""
r = client.post("/api/projects/statistics", json={})
assert r.status_code == 401
def test_statistics_with_token_default_returns_200_with_total_and_by_type(client, auth_token):
"""有 token 且未传 statisticsType(或传全部)时返回 200,含 total、statisticsType、byType"""
r = client.post(
"/api/projects/statistics",
headers=_auth_header(auth_token),
json={},
)
assert r.status_code == 200
body = r.json()
assert "total" in body
assert isinstance(body["total"], int)
assert "statisticsType" in body
assert body["statisticsType"] == "全部"
assert "byType" in body
assert isinstance(body["byType"], dict)
def test_statistics_with_statistics_type_all_returns_by_type(client, auth_token):
"""statisticsType=全部 时返回 byType 各类型数量"""
r = client.post(
"/api/projects/statistics",
headers=_auth_header(auth_token),
json={"statisticsType": "全部"},
)
assert r.status_code == 200
body = r.json()
assert body.get("statisticsType") == "全部"
assert "byType" in body
for _, count in body["byType"].items():
assert isinstance(count, (int, float))
def test_statistics_with_specific_type_returns_200_with_total_and_list(client, auth_token):
"""statisticsType 为具体类型时返回 200,含 total、statisticsType、list"""
r = client.post(
"/api/projects/statistics",
headers=_auth_header(auth_token),
json={"statisticsType": "基建工程"},
)
assert r.status_code == 200
body = r.json()
assert "total" in body
assert isinstance(body["total"], int)
assert "statisticsType" in body
assert body["statisticsType"] == "基建工程"
assert "list" in body
assert isinstance(body["list"], list)
# ---------- POST /api/projects/list ----------
@@ -495,7 +553,7 @@ def test_e2e_login_then_get_project_list(client):
def test_e2e_login_then_create_project_then_list_includes_it(client):
"""E2E:登录(市场部)→ 创建项目 → 获取列表,列表中包含新建项目"""
"""E2E:登录(市场部)→ 创建项目 → 按名称搜索列表,列表中包含新建项目"""
token = _login_and_get_token(client, "market", "123456")
project_name = "E2E流程新建项目"
contract_code = "HT-E2E-001"
@@ -509,14 +567,14 @@ def test_e2e_login_then_create_project_then_list_includes_it(client):
list_r = client.post(
"/api/projects/list",
headers=_auth_header(token),
json={"page": 1, "pageSize": 100},
json={"page": 1, "pageSize": 20, "searchType": "name", "keyword": project_name},
)
assert list_r.status_code == 200
items = list_r.json().get("list", [])
ids = [p["id"] for p in items]
assert pid in ids
names = [p.get("projectName") for p in items if p.get("id") == pid]
assert project_name in names or len(names) >= 1
assert pid in ids, f"新建项目 id {pid} 应在搜索结果中,list ids: {ids[:5]}..."
found = next((p for p in items if p.get("id") == pid), None)
assert found is not None and found.get("projectName") == project_name
def test_e2e_login_then_create_then_detail_then_update_then_detail_reflects(client):