예제 #1
0
    def test_respect_abstract_user_max_length_for_username(self):
        passwd = "verygoodpassword"
        data = {
            "username": "******" * 150,
            "email": "*****@*****.**",
            "password1": passwd,
            "password2": passwd,
        }

        form = UserCreationForm(data)
        assert form.is_valid()

        data["username"] = "******" * 151
        form = UserCreationForm(data)
        assert not form.is_valid()
        assert "username" in form.errors
예제 #2
0
    def test_respect_abstract_user_max_length_for_username(self):
        passwd = 'verygoodpassword'
        data = {
            'username': '******' * 150,
            'email': '*****@*****.**',
            'password1': passwd,
            'password2': passwd,
        }

        form = UserCreationForm(data)
        assert form.is_valid()

        data['username'] = '******' * 151
        form = UserCreationForm(data)
        assert not form.is_valid()
        assert 'username' in form.errors
예제 #3
0
    def test_required_fields(self):
        required_fields = ["username", "email", "password1", "password2", "captcha"]

        form = UserCreationForm({})
        assert form.is_valid() is False

        for required in required_fields:
            assert required in form.errors
        assert len(required_fields) == len(form.errors)
        assert issubclass(UserCreationForm, DjangoUserCreationForm)
예제 #4
0
    def test_required_fields(self):
        required_fields = ['username', 'email', 'password1', 'password2']

        form = UserCreationForm({})
        assert form.is_valid() is False

        for required in required_fields:
            assert required in form.errors
        assert len(required_fields) == len(form.errors)
        assert issubclass(UserCreationForm, DjangoUserCreationForm)
예제 #5
0
    def test_email_validation_does_not_break_if_different_letter_case(self):
        baker.make(settings.AUTH_USER_MODEL, email="*****@*****.**")
        passwd = "verygoodpassword"
        data = {
            "username": "******",
            "email": "*****@*****.**",
            "password1": passwd,
            "password2": passwd,
        }

        form = UserCreationForm(data)
        assert not form.is_valid()
        assert "email" in form.errors
예제 #6
0
    def test_invalid_username_if_already_exists(self):
        baker.make(settings.AUTH_USER_MODEL, username='******')
        passwd = 'verygoodpassword'
        data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': passwd,
            'password2': passwd,
        }

        form = UserCreationForm(data)
        assert form.is_valid() is False
        assert 'username' in form.errors
예제 #7
0
    def test_invalid_username_if_already_exists(self):
        baker.make(settings.AUTH_USER_MODEL, username="******")
        passwd = "verygoodpassword"
        data = {
            "username": "******",
            "email": "*****@*****.**",
            "password1": passwd,
            "password2": passwd,
        }

        form = UserCreationForm(data)
        assert form.is_valid() is False
        assert "username" in form.errors
예제 #8
0
    def test_subscribe_to_newsleter(self):
        data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': '123123asd',
            'password2': '123123asd',
            'subscribe_newsletter': True,
        }

        form = UserCreationForm(data)
        assert form.is_valid() is True
        user = form.save()

        assert NewsletterSubscriber.objects.filter(user=user).exists()
예제 #9
0
    def test_do_not_set_username_to_lowercase(self):
        passwd = "verygoodpassword"
        username = "******"
        data = {
            "username": username,
            "email": "*****@*****.**",
            "password1": passwd,
            "password2": passwd,
            "captcha": "captcha-validation",
        }

        form = UserCreationForm(data)
        assert form.is_valid()
        assert form.cleaned_data["username"] == username
예제 #10
0
    def test_invalid_username_digits(self):
        passwd = "verygoodpassword"
        data = {
            "username": "******",
            "email": "*****@*****.**",
            "password1": passwd,
            "password2": passwd,
            "captcha": "captcha-validation",
        }

        form = UserCreationForm(data)
        assert not form.is_valid()
        assert "username" in form.errors
        assert form.errors["username"] == [self.username_invalid_error]
예제 #11
0
    def test_do_not_validate_if_bad_captcha(self):
        passwd = "verygoodpassword"
        data = {
            "username": "******",
            "email": "*****@*****.**",
            "password1": passwd,
            "password2": passwd,
            "captcha": "invalid-captcha",
        }

        form = UserCreationForm(data)

        assert not form.is_valid()
        assert "captcha" in form.errors
예제 #12
0
    def test_invalid_email_if_user_already_exists(self):
        baker.make(settings.AUTH_USER_MODEL, email="*****@*****.**")
        passwd = "verygoodpassword"
        data = {
            "username": "******",
            "email": "*****@*****.**",
            "password1": passwd,
            "password2": passwd,
            "captcha": "captcha-validation",
        }

        form = UserCreationForm(data)
        assert not form.is_valid()
        assert "email" in form.errors
예제 #13
0
    def test_subscribe_to_newsleter(self):
        data = {
            "username": "******",
            "email": "*****@*****.**",
            "password1": "123123asd",
            "password2": "123123asd",
            "subscribe_newsletter": True,
        }

        form = UserCreationForm(data)
        assert form.is_valid() is True
        user = form.save()

        assert NewsletterSubscriber.objects.filter(user=user).exists()
예제 #14
0
    def test_strip_and_force_lowercase_email(self):
        passwd = "verygoodpassword"
        username = "******"
        data = {
            "username": username,
            "email": "[email protected] ",
            "password1": passwd,
            "password2": passwd,
            "captcha": "captcha-validation",
        }

        form = UserCreationForm(data)
        expected_email = "*****@*****.**"
        assert form.is_valid()
        assert form.cleaned_data["email"] == expected_email
예제 #15
0
    def test_force_lower_for_username(self):
        passwd = 'verygoodpassword'
        data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': passwd,
            'password2': passwd,
        }

        form = UserCreationForm(data)
        assert form.is_valid() is True
        user = form.save()
        user.refresh_from_db()

        assert 'foo' == user.username
예제 #16
0
    def test_force_lower_for_username(self):
        passwd = "verygoodpassword"
        data = {
            "username": "******",
            "email": "*****@*****.**",
            "password1": passwd,
            "password2": passwd,
        }

        form = UserCreationForm(data)
        assert form.is_valid() is True
        user = form.save()
        user.refresh_from_db()

        assert "foo" == user.username
예제 #17
0
    def test_create_user(self):
        passwd = 'qweasdzxc'
        data = {
            'username': '******',
            'email': '*****@*****.**',
            'password1': passwd,
            'password2': passwd,
        }

        form = UserCreationForm(data)
        assert form.is_valid() is True
        user = form.save()

        assert data['username'] == user.username
        assert data['email'] == user.email
        assert user.check_password(passwd) is True
        assert not NewsletterSubscriber.objects.filter(user=user).exists()
예제 #18
0
    def test_create_user(self):
        passwd = "verygoodpassword"
        data = {
            "username": "******",
            "email": "*****@*****.**",
            "password1": passwd,
            "password2": passwd,
        }

        form = UserCreationForm(data)
        assert form.is_valid() is True
        user = form.save()

        assert data["username"] == user.username
        assert data["email"] == user.email
        assert user.check_password(passwd) is True
        assert not NewsletterSubscriber.objects.filter(user=user).exists()