Files
geMoldInsight/tests/test_api_inventory_master_data.py
T
cjw 64dc85bd14 批次5:inventory服务下沉收口 + Pydantic v2 / datetime弃用清零
- inventory业务层下沉(薄路由+service orchestration模式):
  - customer/supplier/warehouse -> master_data_service
  - material_routes(价格历史/趋势/供应商关联)-> material_service
  - product_routes(CRUD/BOM/from-task跨模块桥接)-> product_service
  - dashboard_routes(首页统计/低库存预警)-> dashboard_service
- inventory侧新增service回归覆盖(dashboard 2 / master_data 10 /
  material 10 / product 14),含跨模块桥接测试种子
- Pydantic v2弃用清零:全仓14处 class Config 全部迁移到
  model_config = ConfigDict(from_attributes=True)(含 shared auth)
- datetime.utcnow() 弃用清零:auth_service 3处统一改 datetime.now(timezone.utc)
- 同步文档:STATUS / ROADMAP / TECH_DEBT(D12清偿)/ AGENTS 代码地图

测试基线:126 passed, 4 skipped(无deprecation warning)

Co-Authored-By: Claude Code <noreply@anthropic.com>
2026-09-22 16:13:45 +08:00

181 lines
5.8 KiB
Python

import pytest
@pytest.mark.anyio
async def test_customer_list_search_filters_active_rows(client):
create_resp = await client.post(
"/api/customers",
json={"name": "目标客户Alpha", "contact_person": "张三"},
)
assert create_resp.status_code == 201
customer_id = create_resp.json()["id"]
delete_resp = await client.delete(f"/api/customers/{customer_id}")
assert delete_resp.status_code == 200
kept_resp = await client.post(
"/api/customers",
json={"name": "目标客户Beta", "contact_person": "李四"},
)
assert kept_resp.status_code == 201
resp = await client.get("/api/customers", params={"search": "目标客户"})
assert resp.status_code == 200
rows = resp.json()
names = [row["name"] for row in rows]
assert "目标客户Beta" in names
assert "目标客户Alpha" not in names
@pytest.mark.anyio
async def test_customer_create_auto_generates_code(client):
resp = await client.post(
"/api/customers",
json={"name": "自动编码客户", "phone": "123456"},
)
assert resp.status_code == 201
body = resp.json()
assert body["code"].startswith("C")
assert body["name"] == "自动编码客户"
@pytest.mark.anyio
async def test_customer_update_returns_latest_fields(client):
create_resp = await client.post(
"/api/customers",
json={"name": "旧客户名", "email": "old@example.com"},
)
assert create_resp.status_code == 201
customer_id = create_resp.json()["id"]
update_resp = await client.put(
f"/api/customers/{customer_id}",
json={"code": "C-CUSTOM", "name": "新客户名", "email": "new@example.com"},
)
assert update_resp.status_code == 200
body = update_resp.json()
assert body["code"] == "C-CUSTOM"
assert body["name"] == "新客户名"
assert body["email"] == "new@example.com"
@pytest.mark.anyio
async def test_customer_delete_soft_deletes_row(client):
create_resp = await client.post(
"/api/customers",
json={"name": "待删除客户"},
)
assert create_resp.status_code == 201
customer_id = create_resp.json()["id"]
delete_resp = await client.delete(f"/api/customers/{customer_id}")
assert delete_resp.status_code == 200
assert delete_resp.json()["message"] == "客户已删除"
list_resp = await client.get("/api/customers", params={"search": "待删除客户"})
assert list_resp.status_code == 200
assert all(row["id"] != customer_id for row in list_resp.json())
@pytest.mark.anyio
async def test_supplier_list_search_filters_active_rows(client):
create_resp = await client.post(
"/api/suppliers",
json={"name": "目标供应商Alpha", "contact_person": "王五"},
)
assert create_resp.status_code == 201
supplier_id = create_resp.json()["id"]
delete_resp = await client.delete(f"/api/suppliers/{supplier_id}")
assert delete_resp.status_code == 200
kept_resp = await client.post(
"/api/suppliers",
json={"name": "目标供应商Beta", "contact_person": "赵六"},
)
assert kept_resp.status_code == 201
resp = await client.get("/api/suppliers", params={"search": "目标供应商"})
assert resp.status_code == 200
rows = resp.json()
names = [row["name"] for row in rows]
assert "目标供应商Beta" in names
assert "目标供应商Alpha" not in names
@pytest.mark.anyio
async def test_supplier_create_auto_generates_code(client):
resp = await client.post(
"/api/suppliers",
json={"name": "自动编码供应商", "phone": "123456"},
)
assert resp.status_code == 201
body = resp.json()
assert body["code"].startswith("S")
assert body["name"] == "自动编码供应商"
@pytest.mark.anyio
async def test_supplier_update_returns_latest_fields(client):
create_resp = await client.post(
"/api/suppliers",
json={"name": "旧供应商名", "email": "old-s@example.com"},
)
assert create_resp.status_code == 201
supplier_id = create_resp.json()["id"]
update_resp = await client.put(
f"/api/suppliers/{supplier_id}",
json={"code": "S-CUSTOM", "name": "新供应商名", "email": "new-s@example.com"},
)
assert update_resp.status_code == 200
body = update_resp.json()
assert body["code"] == "S-CUSTOM"
assert body["name"] == "新供应商名"
assert body["email"] == "new-s@example.com"
@pytest.mark.anyio
async def test_supplier_delete_soft_deletes_row(client):
create_resp = await client.post(
"/api/suppliers",
json={"name": "待删除供应商"},
)
assert create_resp.status_code == 201
supplier_id = create_resp.json()["id"]
delete_resp = await client.delete(f"/api/suppliers/{supplier_id}")
assert delete_resp.status_code == 200
assert delete_resp.json()["message"] == "供应商已删除"
list_resp = await client.get("/api/suppliers", params={"search": "待删除供应商"})
assert list_resp.status_code == 200
assert all(row["id"] != supplier_id for row in list_resp.json())
@pytest.mark.anyio
async def test_warehouse_list_orders_default_first(client):
create_resp = await client.post(
"/api/warehouses",
json={"code": "W002", "name": "普通仓库"},
)
assert create_resp.status_code == 201
resp = await client.get("/api/warehouses")
assert resp.status_code == 200
rows = resp.json()
assert rows[0]["is_default"] is True
assert rows[0]["name"] == "默认仓库"
@pytest.mark.anyio
async def test_warehouse_create_auto_generates_code(client):
resp = await client.post(
"/api/warehouses",
json={"name": "自动编码仓库", "manager": "管理员A"},
)
assert resp.status_code == 201
body = resp.json()
assert body["code"].startswith("W")
assert body["name"] == "自动编码仓库"