Exemple #1
0
 def test_RegisterForm_email_too_long(self):
     register_data = {
         'username': '******',
         'email': self.email_255,
         'password1': 'abc123',
         'password2': 'abc123',
         'captcha_0': self.hashkey,
         'captcha_1': self.response
     }
     register_form = tp_forms.RegisterForm(data=register_data)
     self.assertFalse(register_form.is_valid())
Exemple #2
0
 def test_RegisterForm_username_too_long(self):
     register_data = {
         'username': self.username_151,
         'email': '*****@*****.**',
         'password1': 'abc123',
         'password2': 'abc123',
         'captcha_0': self.hashkey,
         'captcha_1': self.response
     }
     register_form = tp_forms.RegisterForm(data=register_data)
     self.assertFalse(register_form.is_valid())
Exemple #3
0
 def test_RegisterForm_invalid_username_chars(self):
     register_data = {
         'username': '******',
         'email': '*****@*****.**',
         'password1': 'abc123',
         'password2': 'abc123',
         'captcha_0': self.hashkey,
         'captcha_1': self.response
     }
     register_form = tp_forms.RegisterForm(data=register_data)
     err_msg = "This value may contain only letters, numbers and @/./+/-/_ characters."
     self.assertEqual(register_form.errors['username'], [err_msg])
     self.assertFalse(register_form.is_valid())
Exemple #4
0
    def test_RegisterForm_clean_email(self):
        register_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'abc123',
            'password2': 'abc123',
            'captcha_0': self.hashkey,
            'captcha_1': self.response
        }

        register_form = tp_forms.RegisterForm(data=register_data)

        self.assertTrue(register_form.is_valid())

        ret = register_form.clean_email()

        self.assertEqual('*****@*****.**', ret)
Exemple #5
0
    def test_RegisterForm_clean_password2_diff(self):
        register_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'abcd123',
            'password2': 'abc123',
            'captcha_0': self.hashkey,
            'captcha_1': self.response
        }

        register_form = tp_forms.RegisterForm(data=register_data)

        # use is_valid to get cleaned_data attributes
        self.assertFalse(register_form.is_valid())

        # is_valid removed cleaned_data password2, need to update
        register_form.cleaned_data['password2'] = 'abc123'

        self.assertRaises(forms.ValidationError, register_form.clean_password2)
Exemple #6
0
    def test_RegisterForm_clean_username_dup(self):
        register_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'abc123',
            'password2': 'abc123',
            'captcha_0': self.hashkey,
            'captcha_1': self.response
        }

        register_form = tp_forms.RegisterForm(data=register_data)

        # validate form, false because duplicated user
        self.assertFalse(register_form.is_valid())

        # user is duplicated so is_valid removed from cleaned_data, we add it back to test
        register_form.cleaned_data['username'] = '******'

        self.assertRaises(forms.ValidationError, register_form.clean_username)
Exemple #7
0
    def test_RegisterForm_clean_password2(self, mock_vp):
        register_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'abc123',
            'password2': 'abc123',
            'captcha_0': self.hashkey,
            'captcha_1': self.response
        }

        register_form = tp_forms.RegisterForm(data=register_data)

        # Check if form is valid and to generate cleaned_data
        self.assertTrue(register_form.is_valid())

        ret = register_form.clean_password2()

        mock_vp.assert_called_with('abc123')

        self.assertEqual('abc123', ret)
Exemple #8
0
    def test_RegisterForm_clean_email_dup(self):
        register_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'abc123',
            'password2': 'abc123',
            'captcha_0': self.hashkey,
            'captcha_1': self.response
        }

        register_form = tp_forms.RegisterForm(data=register_data)

        register_form.is_valid()

        # is_valid is removing duplicated email
        self.assertNotIn('email', register_form.cleaned_data)

        # To test raise error, we need to put it back in to test
        register_form.cleaned_data['email'] = '*****@*****.**'

        self.assertRaises(forms.ValidationError, register_form.clean_email)
Exemple #9
0
    def test_RegisterForm_save(self):
        register_data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': 'abc123',
            'password2': 'abc123',
            'captcha_0': self.hashkey,
            'captcha_1': self.response
        }

        register_form = tp_forms.RegisterForm(data=register_data)

        ret = register_form.save()

        # Also try to get from database after it's saved
        ret_database = User.objects.get(username='******')

        # Check result
        self.assertIsInstance(ret, User)
        self.assertIsInstance(ret_database, User)
        self.assertEqual('user1', ret.username)
        self.assertEqual('user1', ret_database.username)