"""T3.14 客户成功运营模型测试。""" import pytest from fastapi.testclient import TestClient class TestQBR: """QBR 季度业务回顾接口测试。""" def test_generate_qbr_success(self, client: TestClient, auth_headers: dict): """生成 QBR 报告。""" resp = client.post( "/api/v1/customer-success/qbr", json={"company_id": "test-id", "quarter_data": "Q3 营收增长 20%,客户数 50,流失率 5%"}, headers=auth_headers, ) assert resp.status_code == 200 assert isinstance(resp.json()["data"], dict) def test_generate_qbr_no_auth(self, client: TestClient): """未认证应返回 401。""" resp = client.post("/api/v1/customer-success/qbr", json={}) assert resp.status_code == 401 class TestExpansion: """扩展机会识别接口测试。""" def test_identify_expansion_success(self, client: TestClient, auth_headers: dict): """识别扩展机会。""" resp = client.post( "/api/v1/customer-success/expansion", json={"company_data": "AI 教育产品,已在 K12 市场站稳,考虑扩展到职业教育"}, headers=auth_headers, ) assert resp.status_code == 200 assert resp.json()["data"] is not None def test_identify_expansion_no_auth(self, client: TestClient): """未认证应返回 401。""" resp = client.post("/api/v1/customer-success/expansion", json={}) assert resp.status_code == 401 class TestChurnRisk: """流失风险预警接口测试。""" def test_get_churn_risk_success(self, client: TestClient, auth_headers: dict): """获取流失风险预警。""" resp = client.get("/api/v1/customer-success/churn-risk", headers=auth_headers) assert resp.status_code == 200 assert resp.json()["data"] is not None def test_get_churn_risk_no_auth(self, client: TestClient): """未认证应返回 401。""" resp = client.get("/api/v1/customer-success/churn-risk") assert resp.status_code == 401