58 lines
1.8 KiB
Python
58 lines
1.8 KiB
Python
from fastapi.testclient import TestClient
|
|
|
|
|
|
def test_register_location_success(client: TestClient):
|
|
"""正常上架 — 应返回 200"""
|
|
resp = client.post(
|
|
"/CargoTrace/location",
|
|
json={"zongpai_no": "26B999", "location_code": "A01-02-03"},
|
|
)
|
|
assert resp.status_code == 200
|
|
data = resp.json()
|
|
assert data["zongpai_no"] == "26B999"
|
|
assert data["location_code"] == "A01-02-03"
|
|
|
|
|
|
def test_register_location_duplicate(client: TestClient):
|
|
"""重复上架 — 应返回 409"""
|
|
client.post(
|
|
"/CargoTrace/location",
|
|
json={"zongpai_no": "26C999", "location_code": "A01-02-03"},
|
|
)
|
|
resp = client.post(
|
|
"/CargoTrace/location",
|
|
json={"zongpai_no": "26C999", "location_code": "A02-01-01"},
|
|
)
|
|
assert resp.status_code == 409
|
|
data = resp.json()
|
|
assert data["detail"]["error_code"] == "DUPLICATE_LOCATION"
|
|
assert "existing_location" in data["detail"]["detail"]
|
|
|
|
|
|
def test_register_location_invalid_zongpai(client: TestClient):
|
|
"""无效总排号 — 应返回 422"""
|
|
resp = client.post(
|
|
"/CargoTrace/location",
|
|
json={"zongpai_no": "INVALID", "location_code": "A01-02-03"},
|
|
)
|
|
assert resp.status_code == 422
|
|
|
|
|
|
def test_register_location_invalid_location(client: TestClient):
|
|
"""无效货位号 — 应返回 422"""
|
|
resp = client.post(
|
|
"/CargoTrace/location",
|
|
json={"zongpai_no": "26T999", "location_code": "bad-location"},
|
|
)
|
|
assert resp.status_code == 422
|
|
|
|
|
|
def test_register_location_trans_location(client: TestClient):
|
|
"""转运特殊货位 — 应返回 200"""
|
|
resp = client.post(
|
|
"/CargoTrace/location",
|
|
json={"zongpai_no": "26BW0999", "location_code": "TRANS-01"},
|
|
)
|
|
assert resp.status_code == 200
|
|
assert resp.json()["location_code"] == "TRANS-01"
|