test_stripe: Fix incorrect pattern replacement in fixtures.

When normalizing fixture data, all numbers were being
replaced if they matched `exp_month`. This can lead to various
errors and flaky fixture generation. We use a pattern match
which includes the parameter being matched to fix this.
This commit is contained in:
Aman Agrawal
2025-05-10 02:06:49 +05:30
committed by Tim Abbott
parent 104a7dd7a0
commit 567cf3c127

View File

@@ -236,15 +236,17 @@ def normalize_fixture_data(
]
# We'll replace "invoice_prefix": "A35BC4Q" with something like "invoice_prefix": "NORMA01"
# For patterns whose matches can be too generic like `[0-9]+`, include matching field in the translation
# to avoid it replacing other occurrences of the pattern. See `exp_month` for example.
pattern_translations = {
r'"exp_month": ([0-9]+)': "1",
r'"exp_year": ([0-9]+)': "9999",
r'"postal_code": "([0-9]+)"': "12345",
r'"invoice_prefix": "([A-Za-z0-9]{7,8})"': "NORMALIZED",
r'"fingerprint": "([A-Za-z0-9]{16})"': "NORMALIZED",
r'"number": "([A-Za-z0-9]{7,8}-[A-Za-z0-9]{4})"': "NORMALIZED",
r'"address": "([A-Za-z0-9]{9}-test_[A-Za-z0-9]{12})"': "000000000-test_NORMALIZED",
r'"client_secret": "([\w]+)"': "NORMALIZED",
r'"exp_month": [0-9]+': '"exp_month": 1',
r'"exp_year": [0-9]+': '"exp_year": 9999',
r'"postal_code": "[0-9]+"': '"postal_code": "12345"',
r'"invoice_prefix": "[A-Za-z0-9]{7,8}"': '"invoice_prefix": "NORMALIZED"',
r'"fingerprint": "[A-Za-z0-9]{16}"': '"fingerprint": "NORMALIZED"',
r'"number": "[A-Za-z0-9]{7,8}-[A-Za-z0-9]{4}"': '"number": "NORMALIZED"',
r'"address": "[A-Za-z0-9]{9}-test_[A-Za-z0-9]{12}"': '"address": "000000000-test_NORMALIZED"',
r'"client_secret": "[\w]+"': '"client_secret": "NORMALIZED"',
r'"url": "https://billing.stripe.com/p/session/test_([\w]+)"': "NORMALIZED",
r'"url": "https://checkout.stripe.com/c/pay/cs_test_([\w#%]+)"': "NORMALIZED",
r'"receipt_url": "https://pay.stripe.com/receipts/invoices/([\w-]+)\?s=[\w]+"': "NORMALIZED",