From 3c18f8a3d2f61669493f9ff2015ddc027eada3d6 Mon Sep 17 00:00:00 2001 From: Berker Peksag Date: Wed, 24 Aug 2016 20:20:12 +0300 Subject: Fixed #27111 -- Fixed KeyError if USERNAME_FIELD isn't in UserCreationForm.fields. --- tests/auth_tests/test_forms.py | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) (limited to 'tests') diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py index 707d5b87ad..dde639dc01 100644 --- a/tests/auth_tests/test_forms.py +++ b/tests/auth_tests/test_forms.py @@ -22,7 +22,9 @@ from django.utils.encoding import force_text from django.utils.text import capfirst from django.utils.translation import ugettext as _ -from .models.custom_user import CustomUser, ExtensionUser +from .models.custom_user import ( + CustomUser, CustomUserWithoutIsActiveField, ExtensionUser, +) from .models.with_integer_username import IntegerUsernameUser from .settings import AUTH_TEMPLATES @@ -209,6 +211,20 @@ class UserCreationFormTest(TestDataMixin, TestCase): form = CustomUserCreationForm(data) self.assertTrue(form.is_valid()) + def test_custom_form_hidden_username_field(self): + class CustomUserCreationForm(UserCreationForm): + class Meta(UserCreationForm.Meta): + model = CustomUserWithoutIsActiveField + fields = ('email',) # without USERNAME_FIELD + + data = { + 'email': 'testclient@example.com', + 'password1': 'testclient', + 'password2': 'testclient', + } + form = CustomUserCreationForm(data) + self.assertTrue(form.is_valid()) + def test_password_whitespace_not_stripped(self): data = { 'username': 'testuser', -- cgit v1.3