Permalink
Browse files

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

  • Loading branch information...
1 parent 5e09cba commit e88e955ca81dffb09a678cf7a34bc760541aaa9b @tswicegood committed Apr 18, 2012
Showing with 3 additions and 4 deletions.
  1. +1 −2 armstrong/apps/donations/forms.py
  2. +2 −2 armstrong/apps/donations/tests/forms.py
View
3 armstrong/apps/donations/forms.py
@@ -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)
View
4 armstrong/apps/donations/tests/forms.py
@@ -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())

0 comments on commit e88e955

Please sign in to comment.