Exemplo n.º 1
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)
Exemplo n.º 2
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
Exemplo n.º 3
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
Exemplo n.º 4
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
Exemplo n.º 5
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()
Exemplo n.º 6
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
Exemplo n.º 7
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]
Exemplo n.º 8
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
Exemplo n.º 9
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
Exemplo n.º 10
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()
Exemplo n.º 11
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
Exemplo n.º 12
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
Exemplo n.º 13
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
Exemplo n.º 14
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()
Exemplo n.º 15
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()