billing: Take advantage of re match notation in normalize_fixture_data.

No change in behavior; just visual code cleanup.
This commit is contained in:
Rishi Gupta 2018-12-03 13:06:08 -08:00
parent f52e9d143b
commit 84f7a779c4
1 changed files with 6 additions and 6 deletions

View File

@ -125,10 +125,10 @@ def normalize_fixture_data(decorated_function: CallableT, keep: List[str]=[]) ->
} }
# We'll replace "invoice_prefix": "A35BC4Q" with something like "invoice_prefix": "NORMA01" # We'll replace "invoice_prefix": "A35BC4Q" with something like "invoice_prefix": "NORMA01"
pattern_translations.update({ pattern_translations.update({
'"invoice_prefix": "[A-Za-z0-9]{7}"': '"invoice_prefix": "NORMA%02d"', '"invoice_prefix": "([A-Za-z0-9]{7})"': 'NORMA%02d',
'"fingerprint": "[A-Za-z0-9]{16}"': '"fingerprint": "NORMALIZED%06d"', '"fingerprint": "([A-Za-z0-9]{16})"': 'NORMALIZED%06d',
'"number": "[A-Za-z0-9]{7}-[A-Za-z0-9]{4}"': '"number": "NORMALI-%04d"', '"number": "([A-Za-z0-9]{7}-[A-Za-z0-9]{4})"': 'NORMALI-%04d',
'"address": "[A-Za-z0-9]{9}-test_[A-Za-z0-9]{12}"': '"address": "000000000-test_NORMALIZED%02d"', '"address": "([A-Za-z0-9]{9}-test_[A-Za-z0-9]{12})"': '000000000-test_NORMALIZED%02d',
# Does not preserve relative ordering of the timestamps, nor any # Does not preserve relative ordering of the timestamps, nor any
# coordination with the timestamps in setUp mocks (e.g. Plan.created). # coordination with the timestamps in setUp mocks (e.g. Plan.created).
': (1[5-9][0-9]{8})(?![0-9-])': '1%09d', ': (1[5-9][0-9]{8})(?![0-9-])': '1%09d',
@ -144,8 +144,8 @@ def normalize_fixture_data(decorated_function: CallableT, keep: List[str]=[]) ->
if match not in normalized_values[pattern]: if match not in normalized_values[pattern]:
normalized_values[pattern][match] = translation % (len(normalized_values[pattern]) + 1,) normalized_values[pattern][match] = translation % (len(normalized_values[pattern]) + 1,)
file_content = file_content.replace(match, normalized_values[pattern][match]) file_content = file_content.replace(match, normalized_values[pattern][match])
file_content = re.sub(r'"risk_score": \d+', '"risk_score": 00', file_content) file_content = re.sub(r'(?<="risk_score": )(\d+)', '00', file_content)
file_content = re.sub(r'"times_redeemed": \d+', '"times_redeemed": 00', file_content) file_content = re.sub(r'(?<="times_redeemed": )(\d+)', '00', file_content)
# Dates # Dates
file_content = re.sub(r'[0-3]\d [A-Z][a-z]{2} 20[1-2]\d', 'NORMALIZED DATE', file_content) file_content = re.sub(r'[0-3]\d [A-Z][a-z]{2} 20[1-2]\d', 'NORMALIZED DATE', file_content)
# IP addresses # IP addresses