Ticket #17504: django-17504.2.diff
File django-17504.2.diff, 4.9 KB (added by , 13 years ago) |
---|
-
django/contrib/auth/models.py
diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index 8064a4e..51ebd41 100644
a b class Group(models.Model): 116 116 117 117 118 118 class UserManager(models.Manager): 119 def create_user(self, username, email=None, password=None): 119 120 @staticmethod 121 def normalize_email(email): 120 122 """ 121 Creates and saves a User with the given username, email and password. 123 Normalize the address by lowercasing the domain part of the email 124 address. 122 125 """ 123 now = timezone.now()124 125 # Normalize the address by lowercasing the domain part of the email126 # address.127 126 email = email or '' 128 127 try: 129 email_name, domain_part = email.strip(). split('@', 1)128 email_name, domain_part = email.strip().rsplit('@', 1) 130 129 except ValueError: 131 130 pass 132 131 else: 133 132 email = '@'.join([email_name, domain_part.lower()]) 133 return email 134 135 def create_user(self, username, email=None, password=None): 136 """ 137 Creates and saves a User with the given username, email and password. 138 """ 139 now = timezone.now() 140 141 email = UserManager.normalize_email(email) 134 142 135 143 user = self.model(username=username, email=email, is_staff=False, 136 144 is_active=True, is_superuser=False, last_login=now, -
django/contrib/auth/tests/__init__.py
diff --git a/django/contrib/auth/tests/__init__.py b/django/contrib/auth/tests/__init__.py index 883e4c9..6bb6e68 100644
a b from django.contrib.auth.tests.forms import (UserCreationFormTest, 10 10 from django.contrib.auth.tests.remote_user import (RemoteUserTest, 11 11 RemoteUserNoCreateTest, RemoteUserCustomTest) 12 12 from django.contrib.auth.tests.management import GetDefaultUsernameTestCase 13 from django.contrib.auth.tests.models import ProfileTestCase 13 from django.contrib.auth.tests.models import ProfileTestCase, UserManagerTestCase 14 14 from django.contrib.auth.tests.hashers import TestUtilsHashPass 15 15 from django.contrib.auth.tests.signals import SignalTestCase 16 16 from django.contrib.auth.tests.tokens import TokenGeneratorTest 17 from django.contrib.auth.tests.views import (AuthViewNamedURLTests, 18 PasswordResetTest, ChangePasswordTest, LoginTest, LogoutTest, 17 from django.contrib.auth.tests.views import (AuthViewNamedURLTests, 18 PasswordResetTest, ChangePasswordTest, LoginTest, LogoutTest, 19 19 LoginURLSettings) 20 20 21 21 # The password for the fixture data users is 'password' -
django/contrib/auth/tests/models.py
diff --git a/django/contrib/auth/tests/models.py b/django/contrib/auth/tests/models.py index 754c6db..52e44c6 100644
a b 1 1 from django.conf import settings 2 2 from django.test import TestCase 3 from django.contrib.auth.models import User, SiteProfileNotAvailable 3 from django.contrib.auth.models import User, SiteProfileNotAvailable, UserManager 4 4 5 5 6 class ProfileTestCase(TestCase): 6 7 fixtures = ['authtestdata.json'] 8 7 9 def setUp(self): 8 10 """Backs up the AUTH_PROFILE_MODULE""" 9 11 self.old_AUTH_PROFILE_MODULE = getattr(settings, … … class ProfileTestCase(TestCase): 26 28 user = User.objects.get(username='testclient') 27 29 self.assertRaises(SiteProfileNotAvailable, user.get_profile) 28 30 29 # Bad syntax in AUTH_PROFILE_MODULE: 31 # Bad syntax in AUTH_PROFILE_MODULE: 30 32 settings.AUTH_PROFILE_MODULE = 'foobar' 31 33 self.assertRaises(SiteProfileNotAvailable, user.get_profile) 32 34 33 35 # module that doesn't exist 34 36 settings.AUTH_PROFILE_MODULE = 'foo.bar' 35 37 self.assertRaises(SiteProfileNotAvailable, user.get_profile) 38 39 40 class UserManagerTestCase(TestCase): 41 42 def setUp(self): 43 self.manager = UserManager() 44 self.manager.contribute_to_class(User, 'name') 45 46 def test_create_user(self): 47 email_lowercase = 'normal@normal.com' 48 user = self.manager.create_user('user', email_lowercase) 49 self.assertEquals(user.email, email_lowercase) 50 self.assertEquals(user.username, 'user') 51 self.assertEquals(user.password, '!') 52 53 def test_create_user_email_domain_normalize_rfc3696(self): 54 # According to http://tools.ietf.org/html/rfc3696#section-3 55 # the "@" symbol can be part of the local part of an email address 56 returned = UserManager.normalize_email(r'Abc\@DEF@EXAMPLE.com') 57 self.assertEquals(returned, r'Abc\@DEF@example.com') 58 59 def test_create_user_email_domain_normalize(self): 60 returned = UserManager.normalize_email('normal@DOMAIN.COM') 61 self.assertEquals(returned, 'normal@domain.com') 62 63 def test_create_user_email_domain_normalize_with_whitespace(self): 64 returned = UserManager.normalize_email('email\ with_whitespace@D.COM') 65 self.assertEquals(returned, 'email\ with_whitespace@d.com')