Skip to content

Commit acb0709

Browse files
sbeashwarytheesoft
authored andcommitted
fix: handle discovery response with and without ucp wrapper
The latest samples server (01-23) returns profile fields at the top level without a "ucp" wrapper key. Older servers wrap under {"ucp": {...}}. Use data.get("ucp", data) to handle both formats. Also adds required id and line_item_ids fields to fulfillment method and group in create payload (required by latest server).
1 parent 4e07e22 commit acb0709

2 files changed

Lines changed: 7 additions & 4 deletions

File tree

integration_test_utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,7 @@ def shopping_service_endpoint(self) -> str:
394394
discovery_resp = self.client.get("/.well-known/ucp")
395395
self.assert_response_status(discovery_resp, 200)
396396
data = discovery_resp.json()
397-
profile = BusinessSchema(**data["ucp"])
397+
profile = BusinessSchema(**(data.get("ucp", data)))
398398
rdn = ReverseDomainName(root="dev.ucp.shopping")
399399
service_list = profile.services.get(rdn)
400400
if not service_list:
@@ -502,9 +502,12 @@ def create_checkout_payload(
502502
)
503503
)
504504
group = fulfillment_group_create_req.FulfillmentGroupCreateRequest(
505+
id="group_1",
506+
line_item_ids=[],
505507
selected_option_id="std-ship"
506508
)
507509
method = fulfillment_method_create_req.FulfillmentMethodCreateRequest(
510+
id="method_1",
508511
type="shipping",
509512
line_item_ids=[],
510513
destinations=[destination],

protocol_test.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ def test_discovery_urls(self):
8787
response = self.client.get("/.well-known/ucp")
8888
self.assert_response_status(response, 200)
8989
data = response.json()
90-
profile = BusinessSchema(**data["ucp"])
90+
profile = BusinessSchema(**(data.get("ucp", data)))
9191

9292
url_entries = self._extract_document_urls(profile)
9393
failures = []
@@ -146,7 +146,7 @@ def test_discovery(self):
146146
data = response.json()
147147

148148
# Validate schema using SDK model
149-
profile = BusinessSchema(**data["ucp"])
149+
profile = BusinessSchema(**(data.get("ucp", data)))
150150

151151
self.assertIn(
152152
profile.version.root,
@@ -227,7 +227,7 @@ def test_version_negotiation(self):
227227
discovery_resp = self.client.get("/.well-known/ucp")
228228
self.assert_response_status(discovery_resp, 200)
229229
discovery_data = discovery_resp.json()
230-
profile = BusinessSchema(**discovery_data["ucp"])
230+
profile = BusinessSchema(**(discovery_data.get("ucp", discovery_data)))
231231
rdn = ReverseDomainName(root="dev.ucp.shopping")
232232
shopping_services = profile.services[rdn]
233233
rest_binding = next(

0 commit comments

Comments
 (0)