Ticket #25617: ticket_25617.patch

File ticket_25617.patch, 2.1 KB (added by Neven Munđar, 9 years ago)
  • django/contrib/auth/forms.py

    diff --git a/django/contrib/auth/forms.py b/django/contrib/auth/forms.py
    index b1cedc9..fb2a7c0 100644
    a b class UserCreationForm(forms.ModelForm):  
    7878        model = User
    7979        fields = ("username",)
    8080
     81    def clean_username(self):
     82        username = self.cleaned_data.get('username')
     83        if User.objects.filter(username__iexact=username).exists():
     84            raise forms.ValidationError(
     85                User._meta.get_field('username').error_messages['unique'],
     86                code='unique',
     87            )
     88        return username
     89
    8190    def clean_password2(self):
    8291        password1 = self.cleaned_data.get("password1")
    8392        password2 = self.cleaned_data.get("password2")
  • tests/auth_tests/test_forms.py

    diff --git a/tests/auth_tests/test_forms.py b/tests/auth_tests/test_forms.py
    index aa0a6af..5cddbe7 100644
    a b class UserCreationFormTest(TestDataMixin, TestCase):  
    7878        self.assertEqual(form["username"].errors,
    7979                         [force_text(User._meta.get_field('username').error_messages['unique'])])
    8080
     81    def test_case_insensitive_user_already_exists(self):
     82        data = {
     83            'username': 'Testclient',
     84            'password1': 'test123',
     85            'password2': 'test123',
     86        }
     87        form = UserCreationForm(data)
     88        self.assertFalse(form.is_valid())
     89        self.assertEqual(form["username"].errors,
     90                         [force_text(User._meta.get_field('username').error_messages['unique'])])
     91
    8192    def test_invalid_data(self):
    8293        data = {
    8394            'username': 'jsmith!',
    class UserCreationFormTest(TestDataMixin, TestCase):  
    140151    ])
    141152    def test_validates_password(self):
    142153        data = {
    143             'username': 'testclient',
    144             'password1': 'testclient',
    145             'password2': 'testclient',
     154            'username': 'anothertestclient',
     155            'password1': 'anothertestclient',
     156            'password2': 'anothertestclient',
    146157        }
    147158        form = UserCreationForm(data)
    148159        self.assertFalse(form.is_valid())
Back to Top