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
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
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)
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)
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
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
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
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()
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
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]
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
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
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()
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
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
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
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()
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()