fix: relax over-strict discount applied[] count/position assertions - #74
Open
XiaolongZhang-TT wants to merge 1 commit into
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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