81 lines
2.4 KiB
Python
81 lines
2.4 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
|
|
# --- GET /box/info 测试 ---
|
|
|
|
|
|
def test_box_info_success(client: TestClient):
|
|
"""查询真实存在的总排号 → 200"""
|
|
resp = client.get(
|
|
"/CargoTrace/box/info", params={"zongpai_no": "26BW0011"}
|
|
)
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["zongpai_no"] == "26BW0011"
|
|
assert data["paichan_no"] == "W00009"
|
|
assert "work_order_no" in data
|
|
assert data["work_order_no"] is None or isinstance(data["work_order_no"], str)
|
|
assert data["quantity"] == 80
|
|
assert "existing_boxes" in data
|
|
assert "max_box_no" in data
|
|
assert data["suggested_box_no"] == data["max_box_no"] + 1
|
|
|
|
|
|
def test_box_info_invalid_zongpai(client: TestClient):
|
|
"""无效总排号格式 → 400"""
|
|
resp = client.get(
|
|
"/CargoTrace/box/info", params={"zongpai_no": "INVALID"}
|
|
)
|
|
assert resp.status_code == 400
|
|
assert resp.json()["error_code"] == "INVALID_ZONGPAI"
|
|
|
|
|
|
def test_box_info_not_found(client: TestClient):
|
|
"""格式合法但 ERP 中不存在 → 404"""
|
|
resp = client.get(
|
|
"/CargoTrace/box/info", params={"zongpai_no": "26B99999"}
|
|
)
|
|
assert resp.status_code == 404
|
|
assert resp.json()["error_code"] == "ZONGPAI_NOT_FOUND"
|
|
|
|
|
|
# --- POST /box 测试 ---
|
|
|
|
|
|
def test_box_save_invalid_zongpai(client: TestClient):
|
|
"""无效总排号 → 400"""
|
|
resp = client.post(
|
|
"/CargoTrace/box",
|
|
json={"zongpai_no": "INVALID", "box_no": 1, "quantity": 10},
|
|
)
|
|
assert resp.status_code == 400
|
|
assert resp.json()["error_code"] == "INVALID_ZONGPAI"
|
|
|
|
|
|
def test_box_save_invalid_box_no(client: TestClient):
|
|
"""箱号 <= 0 → 400"""
|
|
resp = client.post(
|
|
"/CargoTrace/box",
|
|
json={"zongpai_no": "26BW0011", "box_no": 0, "quantity": 10},
|
|
)
|
|
assert resp.status_code == 400
|
|
|
|
|
|
def test_box_save_invalid_quantity(client: TestClient):
|
|
"""数量 <= 0 → 400"""
|
|
resp = client.post(
|
|
"/CargoTrace/box",
|
|
json={"zongpai_no": "26BW0011", "box_no": 1, "quantity": 0},
|
|
)
|
|
assert resp.status_code == 400
|
|
|
|
|
|
def test_box_save_zongpai_not_found(client: TestClient):
|
|
"""ERP 中不存在的总排号 → 404"""
|
|
resp = client.post(
|
|
"/CargoTrace/box",
|
|
json={"zongpai_no": "26B99999", "box_no": 1, "quantity": 10},
|
|
)
|
|
assert resp.status_code == 404
|
|
assert resp.json()["error_code"] == "ZONGPAI_NOT_FOUND"
|