Пример #1
0
 def test_clean_password2(self):
     form = UserCreationForm(data={'password1': '12345',
                                   'password2': '12345'})
     form.is_valid()
     self.assertEqual(form.clean_password2(), '12345')
     form1 = UserCreationForm(data={'password1': '12345',
                                    'password2': '123'})
     form1.is_valid()
     self.assertRaisesMessage(form1.clean_password2(),
                              "The two password fields didn't match.")
     self.assertRaises(ValidationError, form1.clean_password2())
Пример #2
0
 def test_form_invalid_captcha(self):
     os.environ['RECAPTCHA_TESTING'] = 'False'
     location = LocationFactory()
     data = {'email': '*****@*****.**',
             'password1': '11111',
             'password2': '11111',
             'phone1': '+380991234567',
             'location': location.pk,
             'g-recaptcha-response': 'PASSED'
             }
     form = UserCreationForm(data=data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors, {'captcha': ['Incorrect, please try again.']})
Пример #3
0
 def test_invalid_phone(self):
     os.environ['RECAPTCHA_TESTING'] = 'True'
     location = LocationFactory()
     data = {'email': '*****@*****.**',
             'password1': '11111',
             'password2': '11111',
             'phone1': '0991234567',
             'location': location.pk,
             'g-recaptcha-response': 'PASSED'
             }
     form = UserCreationForm(data=data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form.errors, {'phone1': [u'Enter a valid phone number.']})
Пример #4
0
 def test_form_valid(self):
     os.environ['RECAPTCHA_TESTING'] = 'True'
     location = LocationFactory()
     data = {'email': '*****@*****.**',
             'password1': '11111',
             'password2': '11111',
             'phone1': '+380991234567',
             'location': location.pk,
             'g-recaptcha-response': 'PASSED'
             }
     form = UserCreationForm(data=data)
     self.assertTrue(form.is_valid())
     form.save(commit=False)
     self.assertEqual(User.objects.count(), 0)
     form.save()
     self.assertEqual(User.objects.count(), 1)