fix: relax over-strict discount applied[] count/position assertions - #74
Conversation
Two discount tests asserted exact lengths and a fixed position on discounts.applied[], but discount.md states applied carries code-based discounts *plus any automatic discounts*, whose count is not fixed and whose code is null. A conformant business that also applies an automatic discount would fail these assertions even though every submitted code is present. - test_multiple_discounts_accepted: drop `len(applied) == 2`; the two assertIn(code) checks already prove both codes applied. - test_multiple_discounts_one_rejected: drop `len(applied) == 1` and the `applied[0].code == valid_code` position assumption; assert membership instead, tolerant of automatic discounts ordered first. assertIn is safe against a list that may contain None entries from automatic discounts, since the submitted code is always a string.
Relax discount assertions in test_discount_flow and test_fixed_amount_discount to support servers with automatic discounts, matching the changes in PR 74. Also, explicitly assert that the invalid code is not applied in test_multiple_discounts_one_rejected. TAG=agy CONV=f7ceb008-807f-4776-b148-c69bd5b036e8
|
Thanks for the PR! Relaxing these assertions is definitely the right move to support servers that apply automatic discounts. I noticed a few places where we can improve the tests further to be robust against automatic discounts while maintaining coverage:
I have pushed a branch containing these fixes to the upstream repository at Thanks! |
|
Thanks @damaz91! I've pulled your commit in — the expanded coverage (assertNotIn for the invalid code, plus relaxing the index assumptions in test_discount_flow and test_fixed_amount_discount) looks great. Appreciate the help getting this over the line. |
damaz91
left a comment
There was a problem hiding this comment.
The changes look good. Relaxing the assertions on the applied discounts list to check for membership () rather than exact count or fixed positions is a correct and robust change. This allows server implementations to return automatic discounts alongside code-based ones as permitted by the UCP spec, without failing conformance tests.
Description
Two discount tests in
business_logic_test.pyasserted exact lengths (and one a fixed position) ondiscounts.applied[], but perdiscount.mdtheappliedlist carries code-based discounts plus any automatic discounts, whose count is not fixed and whosecodeisnull. A conformant business that also applies an automatic discount would fail these assertions even though every submitted code is correctly present.test_multiple_discounts_acceptedThe two
assertIn(code)checks already prove both submitted codes were applied, so thelen == 2adds nothing except a failure mode when an automatic discount coexists. Relaxed toassertTrue(discounts_obj.applied).test_multiple_discounts_one_rejectedTwo issues: the exact count, and
applied[0]assuming the code-based discount is first — an automatic discount ordered ahead of it hascode = nulland fails the equality. Replaced with a position-independent membership check.assertInis safe against a list that may containNoneentries (automatic discounts), since the submitted code is always a string.Type of change
Is this a Breaking Change or Removal?
N/A — test-only fix, no schema/field removal.
Checklist