fix: unify error response format with error_code, message and domain fields
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -14,7 +14,7 @@ def test_register_location_success(client: TestClient):
|
||||
|
||||
|
||||
def test_register_location_duplicate(client: TestClient):
|
||||
"""重复上架 — 应返回 409"""
|
||||
"""重复上架 — 应返回 409,包含统一错误格式"""
|
||||
client.post(
|
||||
"/CargoTrace/location",
|
||||
json={"zongpai_no": "26C999", "location_code": "A01-02-03"},
|
||||
@@ -25,26 +25,29 @@ def test_register_location_duplicate(client: TestClient):
|
||||
)
|
||||
assert resp.status_code == 409
|
||||
data = resp.json()
|
||||
assert data["detail"]["error_code"] == "DUPLICATE_LOCATION"
|
||||
assert "existing_location" in data["detail"]["detail"]
|
||||
assert data["error_code"] == "DUPLICATE_LOCATION"
|
||||
assert data["location_code"] == "A01-02-03"
|
||||
assert "registered_at" in data
|
||||
|
||||
|
||||
def test_register_location_invalid_zongpai(client: TestClient):
|
||||
"""无效总排号 — 应返回 422"""
|
||||
"""无效总排号 — 应返回 400"""
|
||||
resp = client.post(
|
||||
"/CargoTrace/location",
|
||||
json={"zongpai_no": "INVALID", "location_code": "A01-02-03"},
|
||||
)
|
||||
assert resp.status_code == 422
|
||||
assert resp.status_code == 400
|
||||
assert resp.json()["error_code"] == "INVALID_ZONGPAI"
|
||||
|
||||
|
||||
def test_register_location_invalid_location(client: TestClient):
|
||||
"""无效货位号 — 应返回 422"""
|
||||
"""无效货位号 — 应返回 400"""
|
||||
resp = client.post(
|
||||
"/CargoTrace/location",
|
||||
json={"zongpai_no": "26T999", "location_code": "bad-location"},
|
||||
)
|
||||
assert resp.status_code == 422
|
||||
assert resp.status_code == 400
|
||||
assert resp.json()["error_code"] == "INVALID_LOCATION"
|
||||
|
||||
|
||||
def test_register_location_trans_location(client: TestClient):
|
||||
|
||||
Reference in New Issue
Block a user