Beispiel #1
0
 def test_register_user_with_valid_data_is_valid(self):
     form_data = {
         'username': '******',
         'email': '*****@*****.**',
         'first_name': 'bob',
         'last_name': 'whatever',
         'password1': 'qwertyuiop',
         'password2': 'qwertyuiop'
     }
     form = UserRegistrationForm(form_data)
     self.assertTrue(form.is_valid())
Beispiel #2
0
 def test_register_user_with_password_mismatch_fails(self):
     form_data = {
         'username': '******',
         'email': '*****@*****.**',
         'first_name': 'bob',
         'last_name': 'whatever',
         'password1': 'qwertyuiop',
         'password2': 'qwertyuiop2'
     }
     form = UserRegistrationForm(form_data)
     self.assertFalse(form.is_valid())
Beispiel #3
0
 def test_register_user_with_missing_data_fails(self):
     form_data = {
         'username': '******',
         'email': '*****@*****.**',
         'first_name': 'bob',
         'last_name': 'whatever',
         'password1': 'qwertyuiop',
         'password2': 'qwertyuiop'
     }
     # Remove each key-value from dictionary, assert form not valid
     for field in form_data.keys():
         data = dict(form_data)
         del (data[field])
         form = UserRegistrationForm(data)
         self.assertFalse(form.is_valid())
Beispiel #4
0
    def test_register_user_with_username_already_in_db_fails(self):

        # Create a user with username bob
        bob = User(username='******', email='*****@*****.**')
        bob.save()

        # attempt to create another user with same username
        form_data = {
            'username': '******',
            'email': '*****@*****.**',
            'first_name': 'bob',
            'last_name': 'whatever',
            'password1': 'qwertyuiop',
            'password2': 'qwertyuiop'
        }
        form = UserRegistrationForm(form_data)
        self.assertFalse(form.is_valid())
Beispiel #5
0
    def test_register_user_with_email_already_in_db_case_insensitive_fails(
            self):

        # Create a user with username bob
        bob = User(username='******', email='*****@*****.**')
        bob.save()

        invalid_email = [
            '*****@*****.**', '*****@*****.**', '*****@*****.**', '*****@*****.**',
            '*****@*****.**', '*****@*****.**'
        ]

        for invalid in invalid_email:
            # attempt to create another user with same username
            form_data = {
                'username': '******',
                'email': invalid,
                'first_name': 'bob',
                'last_name': 'whatever',
                'password1': 'qwertyuiop',
                'password2': 'qwertyuiop'
            }
            form = UserRegistrationForm(form_data)
            self.assertFalse(form.is_valid())