Commit c098b73705d4e02f0ea2441cc2aef31777778ac7

Authored by Ailson da Cruz
1 parent ce4c49b9

Test edit and register user #7 #19

Showing 2 changed files with 63 additions and 5 deletions   Show diff stats
core/forms.py
... ... @@ -12,7 +12,7 @@ class RegisterUserForm(forms.ModelForm):
12 12 def clean_email(self):
13 13 email = self.cleaned_data['email']
14 14 if User.objects.filter(email = email).exists():
15   - raise forms.ValidationError(_('There is already a registered User with this e- mail'))
  15 + raise forms.ValidationError(_('There is already a registered User with this e-mail'))
16 16 return email
17 17  
18 18 def clean_password(self):
... ...
core/tests.py
... ... @@ -75,7 +75,7 @@ class RegisterUserTestCase(TestCase):
75 75 'gender': 'F',
76 76 }
77 77 response = self.client.post(self.url, data)
78   - self.assertFormError(response, 'form', 'password2', 'A confirmacão da senha está incorreta')
  78 + self.assertFormError(response, 'form', 'password2', 'The confirmation password is incorrect.')
79 79  
80 80 data = {
81 81 'username': 'testeamadeus',
... ... @@ -87,6 +87,7 @@ class RegisterUserTestCase(TestCase):
87 87 'state': 'PE',
88 88 'gender': 'F',
89 89 }
  90 +
90 91 response = self.client.post(self.url, data)
91 92 self.assertFormError(response, 'form', 'email', 'Insira um endereço de email válido.')
92 93  
... ... @@ -141,9 +142,25 @@ class UpdateUserTestCase(TestCase):
141 142 def setUp(self):
142 143 self.client = Client()
143 144  
144   - self.url = reverse('users:update_user')
  145 + self.user = User.objects.create_user(
  146 + username = 'test',
  147 + email = 'testing@amadeus.com',
  148 + is_staff = False,
  149 + is_active = True,
  150 + password = 'testing1'
  151 + )
  152 +
  153 + assign_role(self.user, 'student')
  154 +
  155 + self.url = reverse('users:update_profile')
  156 +
  157 + def test_update_ok(self):
  158 + #LOGGING USER TO TEST
  159 + data = {'username': 'test', 'password': 'testing1'}
  160 + response = self.client.post(reverse('core:home'), data)
  161 + self.assertRedirects(response, reverse('app:index'))
  162 +
145 163  
146   - def test_get_post(self):
147 164 data={
148 165 'username': 'testeamadeus',
149 166 'email': 'teste@amadeus.com',
... ... @@ -153,7 +170,48 @@ class UpdateUserTestCase(TestCase):
153 170 'gender': 'F',
154 171 }
155 172 # self.assertRedirects(response1, reverse('app:index'))
  173 + response = self.client.get(self.url)
  174 + self.assertEqual(response.status_code, 200)
156 175 response = self.client.post(self.url, data)
157 176 self.assertEqual(response.status_code, 302)
  177 +
  178 + def test_update_error(self):
  179 +
  180 + #LOGING USER TO TEST
  181 + data = {'username': 'test', 'password': 'testing1'}
  182 + response = self.client.post(reverse('core:home'), data)
  183 + self.assertRedirects(response, reverse('app:index'))
  184 +
158 185 response = self.client.get(self.url)
159   - self.assertEqual(response.status_code, 302)
  186 + self.assertEquals(response.status_code, 200)
  187 +
  188 + data = {
  189 + 'username': '',
  190 + 'email': 'teste@amadeus.com',
  191 + 'name': 'Teste Amadeus',
  192 + 'city': 'Praia',
  193 + 'state': 'PE',
  194 + 'gender': 'F',
  195 + }
  196 + response = self.client.post(self.url, data)
  197 + self.assertFormError(response, 'form', 'username', 'Este campo é obrigatório.')
  198 +
  199 +
  200 +class DeleteUserTestCase(TestCase):
  201 + def setUp(self):
  202 + self.client = Client()
  203 +
  204 + self.user = User.objects.create_user(
  205 + username = 'test',
  206 + email = 'testing@amadeus.com',
  207 + is_staff = True,
  208 + is_active = True,
  209 + password = 'testing'
  210 + )
  211 +
  212 + assign_role(self.user, 'studend')
  213 +
  214 + def tearDown(test):
  215 + pass
  216 +
  217 +
... ...