summaryrefslogtreecommitdiff
path: root/tests/auth_tests
diff options
context:
space:
mode:
authorGary Jarrel <gary@jarrel.com.au>2023-03-27 23:26:06 +1100
committerMariusz Felisiak <felisiak.mariusz@gmail.com>2023-03-28 11:33:20 +0200
commitfcc7dc5781667932bf0bf8bec76df458836e5e95 (patch)
treeb863d20774080545ddf4b2b708c004738db21299 /tests/auth_tests
parent45ecd9acca9b36093e274f47b6877a5f79108d9e (diff)
downloaddjango-fcc7dc5781667932bf0bf8bec76df458836e5e95.tar.gz
Fixed #34438 -- Reallowed extending UserCreationForm.
Regression in 298d02a77a69321af8c0023df3250663e9d1362d.
Diffstat (limited to 'tests/auth_tests')
-rw-r--r--tests/auth_tests/test_forms.py29
1 files changed, 29 insertions, 0 deletions
diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py
index c3ce1f570f..7a80adbf31 100644
--- a/tests/auth_tests/test_forms.py
+++ b/tests/auth_tests/test_forms.py
@@ -372,6 +372,35 @@ class UserCreationFormTest(TestDataMixin, TestCase):
["A user with that username already exists."],
)
+ @override_settings(AUTH_USER_MODEL="auth_tests.ExtensionUser")
+ def test_case_insensitive_username_custom_user_and_error_message(self):
+ class CustomUserCreationForm(UserCreationForm):
+ class Meta(UserCreationForm.Meta):
+ model = ExtensionUser
+ fields = UserCreationForm.Meta.fields + ("date_of_birth",)
+ error_messages = {
+ "username": {"unique": "This username has already been taken."}
+ }
+
+ ExtensionUser.objects.create_user(
+ username="testclient",
+ password="password",
+ email="testclient@example.com",
+ date_of_birth=datetime.date(1984, 3, 5),
+ )
+ data = {
+ "username": "TeStClIeNt",
+ "password1": "test123",
+ "password2": "test123",
+ "date_of_birth": "1980-01-01",
+ }
+ form = CustomUserCreationForm(data)
+ self.assertIs(form.is_valid(), False)
+ self.assertEqual(
+ form["username"].errors,
+ ["This username has already been taken."],
+ )
+
# To verify that the login form rejects inactive users, use an authentication
# backend that allows them.