Skip to content

Commit

Permalink
Padroniza nomes
Browse files Browse the repository at this point in the history
  • Loading branch information
matheuspdf committed May 21, 2024
1 parent 335f662 commit 28a68a3
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions eventex/subscriptions/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,8 @@ class SubscriptionForm(forms.Form):
cpf = forms.CharField(label='CPF', validators=[validate_cpf])
email = forms.EmailField(label='E-mail')
phone = forms.CharField(label='Telefone')

def clean_name(self):
name = self.cleaned_data['name']
words = [w.capitalize() for w in name.split()]
return ' '.join(words)
5 changes: 5 additions & 0 deletions eventex/subscriptions/tests/test_form_subscription.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ def test_cpf_has_11_digits(self):
form = self.make_validated_form(cpf='1234')
self.assertFormErrorCode(form, 'cpf', 'length')

def test_name_must_be_capitalized(self):
"""Name must be capitalized"""
form = self.make_validated_form(name='MATHEUS lopes')
self.assertEqual('Matheus Lopes', form.cleaned_data['name'])

def assertFormErrorCode(self, form, field, code):
errors = form.errors.as_data()
errors_list = errors[field]
Expand Down

0 comments on commit 28a68a3

Please sign in to comment.