Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

test_stripe: Fix incorrect pattern replacement in fixtures.

Aman Agrawal567cf3c1272f
diff --git a/corporate/tests/test_stripe.py b/corporate/tests/test_stripe.py
index b1337ffc09b..34f60814188 100644
--- a/corporate/tests/test_stripe.py
+++ b/corporate/tests/test_stripe.py
@@ -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",