feat: 实现受控真实下单安全边界 (#99)
This commit is contained in:
@@ -274,6 +274,7 @@ class HttpAdminGatewayTest(unittest.TestCase):
|
||||
"type": "purchase",
|
||||
"version": 1,
|
||||
"priority": 0,
|
||||
"execution_mode": "live",
|
||||
"payload": {
|
||||
"goods_url": "https://example.test/goods/PUR-001",
|
||||
"goods_id": "737116531267",
|
||||
@@ -292,11 +293,12 @@ class HttpAdminGatewayTest(unittest.TestCase):
|
||||
ClientInfo("CLIENT-001"),
|
||||
ClaimCapabilities(
|
||||
supported_types=(TaskType.COLLECT, TaskType.PURCHASE),
|
||||
purchase_mode="dry_run",
|
||||
purchase_mode="live",
|
||||
),
|
||||
)
|
||||
|
||||
self.assertEqual(task.task_type, TaskType.PURCHASE)
|
||||
self.assertEqual(task.execution_mode, "live")
|
||||
self.assertEqual(task.payload["max_price_cent"], 4200)
|
||||
|
||||
for missing in ("goods_id", "options", "quantity", "max_price_cent"):
|
||||
@@ -318,6 +320,23 @@ class HttpAdminGatewayTest(unittest.TestCase):
|
||||
raised.exception.code, "ADMIN_INVALID_RESPONSE"
|
||||
)
|
||||
|
||||
invalid_mode_task = dict(valid_task)
|
||||
invalid_mode_task["execution_mode"] = "unsafe"
|
||||
invalid_gateway = HttpAdminGateway(
|
||||
opener=RecordingOpener(
|
||||
FakeResponse(200, {"task": invalid_mode_task})
|
||||
)
|
||||
)
|
||||
with self.assertRaises(AdminGatewayError) as raised:
|
||||
invalid_gateway.claim_next(
|
||||
ClientInfo("CLIENT-001"),
|
||||
ClaimCapabilities(
|
||||
supported_types=(TaskType.COLLECT, TaskType.PURCHASE),
|
||||
purchase_mode="live",
|
||||
),
|
||||
)
|
||||
self.assertEqual(raised.exception.code, "ADMIN_INVALID_RESPONSE")
|
||||
|
||||
def test_claim_204_returns_none(self):
|
||||
gateway = HttpAdminGateway(opener=RecordingOpener(FakeResponse(204, {})))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user