Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 22 additions & 21 deletions business_logic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,10 @@ def test_totals_calculation_on_create(self):
# Verify Line Item Calculations
line_item = checkout_obj.line_items[0]
li_subtotal = next(
(t.amount for t in line_item.totals if t.type == "subtotal"), 0
(t.amount.root for t in line_item.totals if t.type == "subtotal"), 0
)
li_total = next(
(t.amount for t in line_item.totals if t.type == "total"), 0
(t.amount.root for t in line_item.totals if t.type == "total"), 0
)

self.assertEqual(
Expand All @@ -87,22 +87,22 @@ def test_totals_calculation_on_create(self):

# Verify Totals Breakdown
subtotal = next(
(t for t in checkout_obj.totals if t.type == "subtotal"), None
(t for t in checkout_obj.totals.root if t.type == "subtotal"), None
)
total_obj = next(
(t for t in checkout_obj.totals if t.type == "total"), None
(t for t in checkout_obj.totals.root if t.type == "total"), None
)

self.assertIsNotNone(subtotal, "Subtotal missing")
self.assertEqual(
subtotal.amount,
subtotal.amount.root,
expected_price,
f"Subtotal amount should match DB price {expected_price}",
)

self.assertIsNotNone(total_obj, "Total missing")
self.assertEqual(
total_obj.amount,
total_obj.amount.root,
expected_price,
f"Total amount should match DB price {expected_price}",
)
Expand Down Expand Up @@ -158,15 +158,15 @@ def test_totals_recalculation_on_update(self):

updated_checkout = checkout.Checkout(**response.json())
total_obj = next(
(t for t in updated_checkout.totals if t.type == "total"), None
(t for t in updated_checkout.totals.root if t.type == "total"), None
)
expected_total = expected_price * 2
self.assertEqual(
total_obj.amount,
total_obj.amount.root,
expected_total,
msg=(
"Server did not correct totals on update. Expected"
f" {expected_total}, got {total_obj.amount}"
f" {expected_total}, got {total_obj.amount.root}"
),
)

Expand Down Expand Up @@ -226,15 +226,15 @@ def test_discount_flow(self):
expected_total = int(expected_price * 0.9)

total_obj = next(
(t for t in discounted_checkout.totals if t.type == "total"), None
(t for t in discounted_checkout.totals.root if t.type == "total"), None
)
self.assertIsNotNone(total_obj, "Total object missing")
self.assertEqual(
total_obj.amount,
total_obj.amount.root,
expected_total,
msg=(
f"Discount not applied correctly. Expected {expected_total}, got"
f" {total_obj.amount}"
f" {total_obj.amount.root}"
),
)

Expand Down Expand Up @@ -284,13 +284,13 @@ def test_multiple_discounts_accepted(self):
expected_total = int(int(expected_price * 0.9) * 0.8)

total_obj = next(
(t for t in discounted_checkout.totals if t.type == "total"), None
(t for t in discounted_checkout.totals.root if t.type == "total"), None
)
self.assertEqual(
total_obj.amount,
total_obj.amount.root,
expected_total,
f"Multiple discounts failed. Exp {expected_total}, "
f"got {total_obj.amount}",
f"got {total_obj.amount.root}",
)

# Verify both applied discounts are present
Expand Down Expand Up @@ -332,9 +332,9 @@ def test_multiple_discounts_one_rejected(self):
expected_total = int(expected_price * 0.9)

total_obj = next(
(t for t in discounted_checkout.totals if t.type == "total"), None
(t for t in discounted_checkout.totals.root if t.type == "total"), None
)
self.assertEqual(total_obj.amount, expected_total)
self.assertEqual(total_obj.amount.root, expected_total)

# Verify only one applied discount is present
discounts_data = getattr(discounted_checkout, "discounts", {})
Expand Down Expand Up @@ -373,14 +373,15 @@ def test_fixed_amount_discount(self):
expected_total = expected_price - 500

total_obj = next(
(t for t in discounted_checkout.totals if t.type == "total"), None
(t for t in discounted_checkout.totals.root if t.type == "total"), None
)
self.assertIsNotNone(total_obj, "Total object missing")
self.assertEqual(
total_obj.amount,
total_obj.amount.root,
expected_total,
msg=(
f"Fixed discount failed. Exp {expected_total}, got {total_obj.amount}"
f"Fixed discount failed. Exp {expected_total}, got"
f" {total_obj.amount.root}"
),
)

Expand All @@ -399,7 +400,7 @@ def test_fixed_amount_discount(self):
"FIXED500",
)
self.assertEqual(
discounts_obj.applied[0].amount,
discounts_obj.applied[0].amount.root,
500,
)

Expand Down
6 changes: 3 additions & 3 deletions fulfillment_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,15 +121,15 @@ def test_fulfillment_flow(self) -> None:

expected_total = 3500 + option_cost # Base 3500 + shipping
total_obj = next(
(t for t in final_checkout.totals if t.type == "total"), None
(t for t in final_checkout.totals.root if t.type == "total"), None
)
self.assertIsNotNone(total_obj, "Total object missing")
self.assertEqual(
total_obj.amount,
total_obj.amount.root,
expected_total,
msg=(
f"Total not updated correctly. Expected {expected_total}, got"
f" {total_obj.amount}"
f" {total_obj.amount.root}"
),
)

Expand Down
2 changes: 1 addition & 1 deletion integration_test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ def shopping_service_endpoint(self) -> str:

profile_data = discovery_resp.json()
# UCP 01-23 validation changed dicts to lists
shopping_services = profile_data.get("services", {}).get(
shopping_services = profile_data.get("ucp", {}).get("services", {}).get(
"dev.ucp.shopping", []
)
if not shopping_services:
Expand Down
2 changes: 1 addition & 1 deletion invalid_input_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ def test_unknown_discount_code(self):
updated_checkout = checkout.Checkout(**resp_json)
# Verify no discount applied
discount_total = next(
(t for t in updated_checkout.totals if t.type == "discount"), None
(t for t in updated_checkout.totals.root if t.type == "discount"), None
)
self.assertIsNone(
discount_total, "Unknown discount code should not apply discount"
Expand Down
5 changes: 4 additions & 1 deletion protocol_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,10 @@
import integration_test_utils
import httpx
from pydantic import ValidationError
from ucp_sdk.models.schemas.ucp import BusinessSchema, ReverseDomainName
from ucp_sdk.models.schemas.ucp import BusinessSchema
from ucp_sdk.models.schemas.shopping.types.reverse_domain_name import (
ReverseDomainName,
)
from ucp_sdk.models.schemas.shopping import checkout as checkout
from ucp_sdk.models.schemas.shopping.payment import (
Payment,
Expand Down
Loading