[extensions-web/wip/ne0sight: 2/3] auth: check for username uniqueness ignoring case



commit 2d56606a5951409d60b22ef7ce90b81bee1f776e
Author: Yuri Konotopov <ykonotopov gnome org>
Date:   Mon Nov 25 23:53:15 2019 +0400

    auth: check for username uniqueness ignoring case

 sweettooth/auth/forms.py |  4 ++--
 sweettooth/auth/tests.py | 16 +++++++++++++---
 2 files changed, 15 insertions(+), 5 deletions(-)
---
diff --git a/sweettooth/auth/forms.py b/sweettooth/auth/forms.py
index f96de74..af71887 100644
--- a/sweettooth/auth/forms.py
+++ b/sweettooth/auth/forms.py
@@ -2,7 +2,7 @@
 from django import forms
 from django.contrib.auth import forms as auth_forms
 from django.utils.translation import ugettext_lazy as _
-from django_registration.forms import RegistrationFormUniqueEmail
+from django_registration.forms import RegistrationFormCaseInsensitive, RegistrationFormUniqueEmail
 
 class PlainOutputForm(object):
     def as_plain(self):
@@ -41,7 +41,7 @@ class AuthenticationForm(LoginOrEmailAuthenticationForm, AutoFocusForm,
                         auth_forms.AuthenticationForm):
     pass
 
-class RegistrationForm(RegistrationFormUniqueEmail):
+class RegistrationForm(RegistrationFormCaseInsensitive, RegistrationFormUniqueEmail):
     # Copies the standard setting from the django.contrib.auth.forms
     username = forms.RegexField(label=_("Username"), max_length=30, regex=r'^[\w.@+-]+$',
         help_text = _("Required. 30 characters or fewer. Letters, digits and @/./+/-/_ only."),
diff --git a/sweettooth/auth/tests.py b/sweettooth/auth/tests.py
index d5e627e..c1944f7 100644
--- a/sweettooth/auth/tests.py
+++ b/sweettooth/auth/tests.py
@@ -13,12 +13,11 @@ from django_registration import validators
 from django.contrib.auth import get_user_model
 from django.test.testcases import TestCase
 from django.utils.six import text_type
-from .forms import AutoFocusRegistrationForm
+from .forms import AutoFocusRegistrationForm, RegistrationForm
 
 User = get_user_model()
 
-# registration/tests/test_forms.py
-class AuthTests(TestCase):
+class RegistrationDataTest(TestCase):
     registration_data = {
         User.USERNAME_FIELD: 'bob',
         'email': 'bob example com',
@@ -39,6 +38,8 @@ class AuthTests(TestCase):
             password=cls.registration_data['password']
         )
 
+# registration/tests/test_forms.py
+class AuthTests(RegistrationDataTest):
     def test_email_uniqueness(self):
         data = self.valid_data.copy()
         data.update(email = self.registration_data['email'])
@@ -72,3 +73,12 @@ class AuthTests(TestCase):
         self.assertFalse(self.client.login(
             username=self.registration_data['email'],
             password=self.valid_data['password1']))
+
+class RegistrationTests(RegistrationDataTest):
+    def test_username_case(self):
+        data = self.valid_data.copy()
+        data[User.USERNAME_FIELD] = self.registration_data[User.USERNAME_FIELD].swapcase()
+        self.assertTrue(data[User.USERNAME_FIELD] != self.registration_data[User.USERNAME_FIELD])
+
+        form = RegistrationForm(data=data)
+        self.assertFalse(form.is_valid())


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]