Ejemplo n.º 1
0
 def test_invalid_data(self):
     data = {
         'username': '******',
         'password1': 'test123',
         'password2': 'test123',
         }
     form = UserCreationForm(data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form["username"].errors,
                      [force_unicode(form.fields['username'].error_messages['invalid'])])
Ejemplo n.º 2
0
 def test_user_already_exists(self):
     data = {
         'username': '******',
         'password1': 'test123',
         'password2': 'test123',
         }
     form = UserCreationForm(data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form["username"].errors,
                      [force_unicode(form.error_messages['duplicate_username'])])
Ejemplo n.º 3
0
 def test_success(self):
     # The success case.
     data = {
         'username': '******',
         'password1': 'test123',
         'password2': 'test123',
         }
     form = UserCreationForm(data)
     self.assertTrue(form.is_valid())
     u = form.save()
     self.assertEqual(repr(u), '<User: [email protected]>')
Ejemplo n.º 4
0
 def test_password_verification(self):
     # The verification password is incorrect.
     data = {
         'username': '******',
         'password1': 'test123',
         'password2': 'test',
         }
     form = UserCreationForm(data)
     self.assertFalse(form.is_valid())
     self.assertEqual(form["password2"].errors,
                      [force_unicode(form.error_messages['password_mismatch'])])
Ejemplo n.º 5
0
    def test_both_passwords(self):
        # One (or both) passwords weren't given
        data = {'username': '******'}
        form = UserCreationForm(data)
        required_error = [force_unicode(Field.default_error_messages['required'])]
        self.assertFalse(form.is_valid())
        self.assertEqual(form['password1'].errors, required_error)
        self.assertEqual(form['password2'].errors, required_error)

        data['password2'] = 'test123'
        form = UserCreationForm(data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form['password1'].errors, required_error)