"""T2.12 驾驶舱增强测试 — 热力图 + 趋势对比接口。""" import pytest from fastapi.testclient import TestClient class TestDashboardHeatmap: """热力图接口测试。""" def test_heatmap_empty(self, client: TestClient, auth_headers: dict): """无企业时应返回空列表。""" resp = client.get("/api/v1/dashboard/heatmap", headers=auth_headers) assert resp.status_code == 200 assert resp.json()["code"] == 0 assert isinstance(resp.json()["data"], list) def test_heatmap_with_company(self, client: TestClient, auth_headers: dict, company_id: str): """有企业时应返回热力图数据。""" resp = client.get("/api/v1/dashboard/heatmap", headers=auth_headers) assert resp.status_code == 200 data = resp.json()["data"] assert len(data) >= 1 assert "company_id" in data[0] assert "company_name" in data[0] assert "scores" in data[0] def test_heatmap_no_auth(self, client: TestClient): """未认证应返回 401。""" resp = client.get("/api/v1/dashboard/heatmap") assert resp.status_code == 401 class TestDashboardTrends: """趋势对比接口测试。""" def test_trends_empty(self, client: TestClient, auth_headers: dict): """无评分数据时应返回空列表。""" resp = client.get("/api/v1/dashboard/trends", headers=auth_headers) assert resp.status_code == 200 assert isinstance(resp.json()["data"], list) def test_trends_with_months_param(self, client: TestClient, auth_headers: dict): """指定 months 参数应正常返回。""" resp = client.get("/api/v1/dashboard/trends?months=3", headers=auth_headers) assert resp.status_code == 200 data = resp.json()["data"] assert isinstance(data, list) def test_trends_with_company_id(self, client: TestClient, auth_headers: dict, company_id: str): """指定企业 ID 应正常返回。""" resp = client.get( f"/api/v1/dashboard/trends?company_id={company_id}&months=6", headers=auth_headers, ) assert resp.status_code == 200 data = resp.json()["data"] assert isinstance(data, list) def test_trends_invalid_months(self, client: TestClient, auth_headers: dict): """无效 months 参数应返回 422。""" resp = client.get("/api/v1/dashboard/trends?months=0", headers=auth_headers) assert resp.status_code == 422 def test_trends_no_auth(self, client: TestClient): """未认证应返回 401。""" resp = client.get("/api/v1/dashboard/trends") assert resp.status_code == 401