815cbf9d8c
- 更新 .gitignore:全面覆盖环境变量、数据库、日志、缓存、上传文件 - 移除误跟踪的 server/venv/、crm_data.db、.env 文件 - 新增 server/.env.example 模板 - 新增合同管理、利润核算、AI教练等功能模块 - 新增 Playwright e2e 测试套件 - 前后端多项功能升级和 bug 修复
71 lines
2.5 KiB
Python
71 lines
2.5 KiB
Python
"""
|
|
复盘报告模块测试 —— /api/reports
|
|
覆盖: 确认存档 / 历史列表 / 修改 / 删除
|
|
注: SSE 流式 /generate 需要 Dify,在此 mock/跳过
|
|
"""
|
|
import uuid
|
|
import pytest
|
|
from httpx import AsyncClient
|
|
from tests.conftest import ADMIN_USER_ID
|
|
|
|
|
|
class TestReportConfirm:
|
|
"""POST /api/reports/confirm"""
|
|
|
|
async def test_confirm_report(self, client: AsyncClient, admin_headers):
|
|
"""确认存档复盘报告 → 200"""
|
|
resp = await client.post("/api/reports/confirm", headers=admin_headers, json={
|
|
"start_date": "2026-03-01",
|
|
"end_date": "2026-03-31",
|
|
"content_md": "# 3月复盘报告\n\n本月完成10笔订单...",
|
|
"report_type": "monthly",
|
|
})
|
|
assert resp.status_code == 200
|
|
data = resp.json()["data"]
|
|
assert data["status"] == "confirmed"
|
|
|
|
|
|
class TestReportHistory:
|
|
"""GET /api/reports/history"""
|
|
|
|
async def test_list_report_history(self, client: AsyncClient, admin_headers):
|
|
"""报告历史 → 200"""
|
|
resp = await client.get("/api/reports/history", headers=admin_headers)
|
|
assert resp.status_code == 200
|
|
data = resp.json()["data"]
|
|
assert "total" in data
|
|
assert "items" in data
|
|
|
|
|
|
class TestReportCRUD:
|
|
"""PUT / DELETE /api/reports/{id}"""
|
|
|
|
async def test_update_nonexistent_report(self, client: AsyncClient, admin_headers):
|
|
"""修改不存在的报告 → 404"""
|
|
fake_id = uuid.uuid4()
|
|
resp = await client.put(f"/api/reports/{fake_id}", headers=admin_headers, json={
|
|
"content_md": "updated content",
|
|
})
|
|
assert resp.status_code == 404
|
|
|
|
async def test_delete_nonexistent_report(self, client: AsyncClient, admin_headers):
|
|
"""删除不存在的报告 → 404"""
|
|
fake_id = uuid.uuid4()
|
|
resp = await client.delete(f"/api/reports/{fake_id}", headers=admin_headers)
|
|
assert resp.status_code == 404
|
|
|
|
async def test_create_and_delete_report(self, client: AsyncClient, admin_headers):
|
|
"""创建→删除 完整链路"""
|
|
# 创建
|
|
create_resp = await client.post("/api/reports/confirm", headers=admin_headers, json={
|
|
"start_date": "2026-02-01",
|
|
"end_date": "2026-02-28",
|
|
"content_md": "# 2月复盘\n\n测试内容",
|
|
})
|
|
assert create_resp.status_code == 200
|
|
report_id = create_resp.json()["data"]["id"]
|
|
|
|
# 删除
|
|
del_resp = await client.delete(f"/api/reports/{report_id}", headers=admin_headers)
|
|
assert del_resp.status_code == 200
|