Skip to content

Commit f5f1357

Browse files
committed
fix: validate payment handler structure from profile instead of hardcoded list
Replace hardcoded expected handler IDs (google_pay, mock_payment_handler, shop_pay) with structural validation that: - Discovers handlers from the business profile dynamically - Validates required fields (id, version) are present - Validates handler group names follow reverse-DNS convention - Works against any UCP merchant, not just the Flower Shop This makes the protocol conformance tests server-agnostic. Addresses #13
1 parent 7ca5aee commit f5f1357

1 file changed

Lines changed: 33 additions & 26 deletions

File tree

protocol_test.py

Lines changed: 33 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -180,32 +180,39 @@ def test_discovery(self):
180180
f"Missing expected capabilities in discovery: {missing_caps}",
181181
)
182182

183-
# Verify Payment Handlers
184-
handlers = {
185-
h.get("id")
186-
for handlers in data.get("payment_handlers", {}).values()
187-
for h in (handlers if isinstance(handlers, list) else [handlers])
188-
}
189-
expected_handlers = {"google_pay", "mock_payment_handler", "shop_pay"}
190-
missing_handlers = expected_handlers - handlers
191-
self.assertFalse(
192-
missing_handlers,
193-
f"Missing expected payment handlers: {missing_handlers}",
194-
)
195-
196-
# Specific check for Shop Pay config
197-
shop_pay = next(
198-
(
199-
h
200-
for handlers in data.get("payment_handlers", {}).values()
201-
for h in (handlers if isinstance(handlers, list) else [handlers])
202-
if h.get("id") == "shop_pay"
203-
),
204-
None,
205-
)
206-
self.assertIsNotNone(shop_pay, "Shop Pay handler not found")
207-
self.assertEqual(shop_pay.get("name"), "com.shopify.shop_pay")
208-
self.assertIn("shop_id", shop_pay.get("config"))
183+
# Verify Payment Handlers - structural validation (server-agnostic)
184+
if data.get("payment_handlers"):
185+
handler_count = 0
186+
for handler_name, handler_list in data.get(
187+
"payment_handlers", {}
188+
).items():
189+
# Validate handler group name follows reverse-DNS convention
190+
self.assertRegex(
191+
str(handler_name),
192+
r"^[a-z][a-z0-9]*(\.[a-z][a-z0-9_]*)+$",
193+
f"Payment handler group name '{handler_name}' "
194+
"does not follow reverse-DNS convention",
195+
)
196+
for h in (
197+
handler_list
198+
if isinstance(handler_list, list)
199+
else [handler_list]
200+
):
201+
handler_count += 1
202+
# Validate required fields are present and non-empty
203+
self.assertTrue(
204+
h.get("id"),
205+
"Payment handler missing 'id'",
206+
)
207+
self.assertIsNotNone(
208+
h.get("version"),
209+
f"Payment handler '{h.get('id')}' missing 'version'",
210+
)
211+
self.assertGreater(
212+
handler_count,
213+
0,
214+
"payment_handlers is present but contains no handlers",
215+
)
209216

210217
# Verify shopping capability
211218
shopping_services = data.get("services", {}).get("dev.ucp.shopping")

0 commit comments

Comments
 (0)