test: add integration tests for location API

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
Misaka_Company
2026-05-11 11:16:33 +08:00
parent d68d602411
commit 6a4ea34e24
3 changed files with 86 additions and 0 deletions

View File

@@ -0,0 +1,57 @@
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"