Navigation Menu

Skip to content

Commit

Permalink
Simplify this code to only strip when there's something to strip
Browse files Browse the repository at this point in the history
  • Loading branch information
tswicegood committed Apr 18, 2012
1 parent 5e09cba commit e88e955
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 4 deletions.
3 changes: 1 addition & 2 deletions armstrong/apps/donations/forms.py
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions armstrong/apps/donations/tests/forms.py
Expand Up @@ -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())

Expand Down

0 comments on commit e88e955

Please sign in to comment.