""" 利润核算模块测试 —— /api/profit """ import uuid import pytest from httpx import AsyncClient class TestProfitReport: """GET /api/profit/report""" async def test_profit_report(self, client: AsyncClient, admin_headers): """利润报表(可能为空) → 200""" resp = await client.get("/api/profit/report", headers=admin_headers) assert resp.status_code == 200 async def test_profit_report_with_dates(self, client: AsyncClient, admin_headers): """带日期范围 → 200""" resp = await client.get( "/api/profit/report?start_date=2026-01-01&end_date=2026-03-31", headers=admin_headers ) assert resp.status_code == 200 class TestCostSnapshot: """POST /api/profit/snapshot/{order_id}""" async def test_snapshot_nonexistent_order(self, client: AsyncClient, admin_headers): """不存在的订单快照 → 404 或空""" fake_id = uuid.uuid4() resp = await client.post( f"/api/profit/snapshot/{fake_id}", headers=admin_headers ) # 可能返回 200 + 空结果,也可能 404 assert resp.status_code in (200, 404, 500)