Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
View
@@ -133,12 +133,11 @@ class CreditCardDonationForm(BaseDonationForm):
expiration_month = forms.ChoiceField(choices=MONTH_CHOICES)
expiration_year = forms.ChoiceField(choices=YEAR_CHOICES)
- strip_sensitive_info = True
fields_to_strip = ["card_number", "ccv_code", ]
def is_valid(self, *args, **kwargs):
r = super(CreditCardDonationForm, self).is_valid(*args, **kwargs)
- if not r and self.strip_sensitive_info:
+ if not r and self.fields_to_strip:
empty_values = [""] * len(self.fields_to_strip)
new_data = dict(zip(self.fields_to_strip, empty_values))
self.data.update(new_data)
4 armstrong/apps/donations/tests/forms.py
View
@@ -274,13 +274,13 @@ def get_invalid_form(self):
def assert_value_is_empty(self, field):
form = self.get_invalid_form()
- form.strip_sensitive_info = True
+ form.fields_to_strip = ["card_number", "ccv_code"]
self.assertFalse(form.is_valid())
self.assertEqual("", form[field].value())
def assert_value_is_not_empty(self, field):
form = self.get_invalid_form()
- form.strip_sensitive_info = False
+ form.fields_to_strip = []
self.assertFalse(form.is_valid())
self.assertNotEqual("", form[field].value())
Please sign in to comment.
Something went wrong with that request. Please try again.