fix: 校验采购尺码候选边界 (#256)
This commit is contained in:
@@ -1052,6 +1052,54 @@ class U2PddPurchaseAdapterTest(unittest.TestCase):
|
||||
)
|
||||
adapter.close()
|
||||
|
||||
def test_invalid_candidate_list_never_requests_remote_resolution(self):
|
||||
for values, expected_reason in (
|
||||
(
|
||||
(DimensionValue("M", True), DimensionValue("M", False)),
|
||||
"candidate_duplicated",
|
||||
),
|
||||
(
|
||||
tuple(
|
||||
DimensionValue(f"尺码{index}", True)
|
||||
for index in range(101)
|
||||
),
|
||||
"candidate_count_exceeded",
|
||||
),
|
||||
):
|
||||
with self.subTest(expected_reason=expected_reason):
|
||||
device = FakeDevice()
|
||||
adapter = U2PddPurchaseAdapter(
|
||||
"USB-001",
|
||||
device_service=PddDeviceService(
|
||||
connector=lambda _serial: device
|
||||
),
|
||||
sleeper=lambda _seconds: None,
|
||||
select_color_fn=lambda *_args, **_kwargs: True,
|
||||
select_size_fn=lambda *_args, **_kwargs: False,
|
||||
size_candidate_collector=lambda _device, items=values: (
|
||||
SpecDimension("size", "尺码", items)
|
||||
),
|
||||
)
|
||||
adapter.open_goods(GOODS_URL)
|
||||
|
||||
with self.assertRaises(PddPurchaseError) as raised:
|
||||
adapter.select_options(
|
||||
{"color": "黑色", "size": "不存在"}
|
||||
)
|
||||
|
||||
self.assertNotIsInstance(
|
||||
raised.exception, PddPurchaseSpecResolutionRequired
|
||||
)
|
||||
self.assertEqual(
|
||||
raised.exception.code,
|
||||
"PURCHASE_SIZE_CANDIDATE_SCAN_INCOMPLETE",
|
||||
)
|
||||
self.assertEqual(
|
||||
raised.exception.diagnostics["candidate_validation"],
|
||||
expected_reason,
|
||||
)
|
||||
adapter.close()
|
||||
|
||||
def test_size_without_selected_color_never_requests_remote_resolution(self):
|
||||
device = FakeDevice()
|
||||
scans = []
|
||||
|
||||
Reference in New Issue
Block a user