"""投后报告导出测试。""" import pytest from fastapi.testclient import TestClient @pytest.fixture def auth_headers(client: TestClient): client.post( "/api/v1/auth/register", json={ "email": "export_test@example.com", "password": "password123", "name": "测试投资经理", "tenant_name": "测试机构", "role": "investor", }, ) resp = client.post( "/api/v1/auth/login", json={"email": "export_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 TestReportExport: """投后报告导出。""" def test_summary_success(self, client: TestClient, auth_headers: dict, company_id: str): """获取报告汇总。""" response = client.get( f"/api/v1/reports-export/{company_id}/summary", headers=auth_headers, ) assert response.status_code == 200 data = response.json() assert data["code"] == 0 assert data["data"]["company"]["name"] == "导出测试公司" def test_summary_nonexistent(self, client: TestClient, auth_headers: dict): """不存在的企业应返回 404。""" response = client.get( "/api/v1/reports-export/nonexistent/summary", headers=auth_headers, ) assert response.status_code == 404 def test_export_json(self, client: TestClient, auth_headers: dict, company_id: str): """导出 JSON 报告。""" response = client.get( f"/api/v1/reports-export/{company_id}/pdf", headers=auth_headers, ) assert response.status_code == 200 assert "attachment" in response.headers.get("content-disposition", "")