Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Simplify this code to only strip when there's something to strip

  • Loading branch information...
commit e88e955ca81dffb09a678cf7a34bc760541aaa9b 1 parent 5e09cba
Travis Swicegood authored
3  armstrong/apps/donations/forms.py
@@ -133,12 +133,11 @@ class CreditCardDonationForm(BaseDonationForm):
133 133 expiration_month = forms.ChoiceField(choices=MONTH_CHOICES)
134 134 expiration_year = forms.ChoiceField(choices=YEAR_CHOICES)
135 135
136   - strip_sensitive_info = True
137 136 fields_to_strip = ["card_number", "ccv_code", ]
138 137
139 138 def is_valid(self, *args, **kwargs):
140 139 r = super(CreditCardDonationForm, self).is_valid(*args, **kwargs)
141   - if not r and self.strip_sensitive_info:
  140 + if not r and self.fields_to_strip:
142 141 empty_values = [""] * len(self.fields_to_strip)
143 142 new_data = dict(zip(self.fields_to_strip, empty_values))
144 143 self.data.update(new_data)
4 armstrong/apps/donations/tests/forms.py
@@ -274,13 +274,13 @@ def get_invalid_form(self):
274 274
275 275 def assert_value_is_empty(self, field):
276 276 form = self.get_invalid_form()
277   - form.strip_sensitive_info = True
  277 + form.fields_to_strip = ["card_number", "ccv_code"]
278 278 self.assertFalse(form.is_valid())
279 279 self.assertEqual("", form[field].value())
280 280
281 281 def assert_value_is_not_empty(self, field):
282 282 form = self.get_invalid_form()
283   - form.strip_sensitive_info = False
  283 + form.fields_to_strip = []
284 284 self.assertFalse(form.is_valid())
285 285 self.assertNotEqual("", form[field].value())
286 286

0 comments on commit e88e955

Please sign in to comment.
Something went wrong with that request. Please try again.