Commit ffdd0fc448ae33be290811d17059bd6a56f50d01
1 parent
64e8f587
Exists in
master
and in
5 other branches
Adding test_regiater_user_error #5
Showing
2 changed files
with
50 additions
and
1 deletions
Show diff stats
core/forms.py
@@ -9,6 +9,12 @@ class RegisterUserForm(forms.ModelForm): | @@ -9,6 +9,12 @@ class RegisterUserForm(forms.ModelForm): | ||
9 | # birth_date = forms.DateField(widget=forms.SelectDateWidget()) | 9 | # birth_date = forms.DateField(widget=forms.SelectDateWidget()) |
10 | MIN_LENGTH = 8 | 10 | MIN_LENGTH = 8 |
11 | 11 | ||
12 | + def clean_email(self): | ||
13 | + email = self.cleaned_data['email'] | ||
14 | + if User.objects.filter(email = email).exists(): | ||
15 | + raise forms.ValidationError('Já existe um usuário cadastrado com este E-mail') | ||
16 | + return email | ||
17 | + | ||
12 | def clean_password(self): | 18 | def clean_password(self): |
13 | password = self.cleaned_data.get('password') | 19 | password = self.cleaned_data.get('password') |
14 | 20 | ||
@@ -29,7 +35,7 @@ class RegisterUserForm(forms.ModelForm): | @@ -29,7 +35,7 @@ class RegisterUserForm(forms.ModelForm): | ||
29 | password2 = self.cleaned_data.get("password2") | 35 | password2 = self.cleaned_data.get("password2") |
30 | 36 | ||
31 | if password and password2 and password != password2: | 37 | if password and password2 and password != password2: |
32 | - raise forms.ValidationError('A confirmmacao de senha esta incorreta') | 38 | + raise forms.ValidationError('A confirmacão da senha está incorreta') |
33 | return password2 | 39 | return password2 |
34 | 40 | ||
35 | def save(self, commit=True): | 41 | def save(self, commit=True): |
core/tests.py
@@ -60,6 +60,49 @@ class RegisterUserTestCase(TestCase): | @@ -60,6 +60,49 @@ class RegisterUserTestCase(TestCase): | ||
60 | self.assertEqual(response.status_code, 302) | 60 | self.assertEqual(response.status_code, 302) |
61 | self.assertEqual(User.objects.count(), 1) | 61 | self.assertEqual(User.objects.count(), 1) |
62 | 62 | ||
63 | + def test_register_error(self): | ||
64 | + response = self.client.get(self.url) | ||
65 | + self.assertEquals(response.status_code, 200) | ||
66 | + | ||
67 | + data = { | ||
68 | + 'username': 'testeamadeus', | ||
69 | + 'email': 'teste@amadeus.com', | ||
70 | + 'password': 'aminhasenha1', | ||
71 | + 'password2': 'aminhasenha', | ||
72 | + 'name': 'Teste Amadeus', | ||
73 | + 'city': 'Praia', | ||
74 | + 'state': 'PE', | ||
75 | + 'gender': 'F', | ||
76 | + } | ||
77 | + response = self.client.post(self.url, data) | ||
78 | + self.assertFormError(response, 'form', 'password2', 'A confirmacão da senha está incorreta') | ||
79 | + | ||
80 | + data = { | ||
81 | + 'username': 'testeamadeus', | ||
82 | + 'email': 'teste.amadeus.com', | ||
83 | + 'password': 'aminhasenha1', | ||
84 | + 'password2': 'aminhasenha', | ||
85 | + 'name': 'Teste Amadeus', | ||
86 | + 'city': 'Praia', | ||
87 | + 'state': 'PE', | ||
88 | + 'gender': 'F', | ||
89 | + } | ||
90 | + response = self.client.post(self.url, data) | ||
91 | + self.assertFormError(response, 'form', 'email', 'Insira um endereço de email válido.') | ||
92 | + | ||
93 | + data = { | ||
94 | + 'username': '', | ||
95 | + 'email': 'teste@amadeus.com', | ||
96 | + 'password': 'aminhasenha1', | ||
97 | + 'password2': 'aminhasenha', | ||
98 | + 'name': 'Teste Amadeus', | ||
99 | + 'city': 'Praia', | ||
100 | + 'state': 'PE', | ||
101 | + 'gender': 'F', | ||
102 | + } | ||
103 | + response = self.client.post(self.url, data) | ||
104 | + self.assertFormError(response, 'form', 'username', 'Este campo é obrigatório.') | ||
105 | + | ||
63 | class RememberPasswordTestCase(TestCase): | 106 | class RememberPasswordTestCase(TestCase): |
64 | 107 | ||
65 | def setUp(self): | 108 | def setUp(self): |