Пример #1
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,
                      [u'A user with that username already exists.'])
Пример #2
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,
                      [u'This value may contain only letters, numbers and @/./+/-/_ characters.'])
Пример #3
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,
                      [u"The two password fields didn't match."])
Пример #4
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]>')
Пример #5
0
    def test_both_passwords(self):
        # One (or both) passwords weren't given
        data = {'username': '******'}
        form = UserCreationForm(data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form['password1'].errors,
                         [u'This field is required.'])
        self.assertEqual(form['password2'].errors,
                         [u'This field is required.'])


        data['password2'] = 'test123'
        form = UserCreationForm(data)
        self.assertFalse(form.is_valid())
        self.assertEqual(form['password1'].errors,
                         [u'This field is required.'])