Skip to content
Open
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
15 changes: 10 additions & 5 deletions business_logic_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,12 +300,14 @@ def test_multiple_discounts_accepted(self):
discounted_checkout, expected_price, expected_discount=expected_discount
)

# Verify both applied discounts are present
# Verify both submitted codes are present in the applied list. The applied
# list also carries any automatic discounts (discount.md: applied contains
# code-based + automatic), so assert membership rather than an exact count.
discounts_data = getattr(discounted_checkout, "discounts", {})
discounts_obj = (
discount.DiscountsObject(**discounts_data) if discounts_data else None
)
self.assertTrue(discounts_obj and len(discounts_obj.applied) == 2)
self.assertTrue(discounts_obj and discounts_obj.applied)
applied_codes = [d.code for d in discounts_obj.applied]
self.assertIn(valid_code_1, applied_codes)
self.assertIn(valid_code_2, applied_codes)
Expand Down Expand Up @@ -337,13 +339,16 @@ def test_multiple_discounts_one_rejected(self):
discounted_checkout, expected_price, expected_discount=expected_discount
)

# Verify only one applied discount is present
# Verify the valid code is present in the applied list. The applied list
# also carries any automatic discounts, so assert membership rather than an
# exact count or a fixed position (automatic discounts have no code).
discounts_data = getattr(discounted_checkout, "discounts", {})
discounts_obj = (
discount.DiscountsObject(**discounts_data) if discounts_data else None
)
self.assertTrue(discounts_obj and len(discounts_obj.applied) == 1)
self.assertEqual(discounts_obj.applied[0].code, valid_code)
self.assertTrue(discounts_obj and discounts_obj.applied)
applied_codes = [d.code for d in discounts_obj.applied]
self.assertIn(valid_code, applied_codes)

def test_fixed_amount_discount(self):
"""Test that a fixed-amount discount code decreases the total correctly.
Expand Down
Loading