Ticket #15110: modify_create_user_and_tests.patch
File modify_create_user_and_tests.patch, 3.9 KB (added by , 14 years ago) |
---|
-
django/contrib/auth/models.py
From 19bf7746cc0eec3e5c871d21ab4972b39a884667 Mon Sep 17 00:00:00 2001 From: Jorge Eduardo Cardona <jorgeecardona@gmail.com> Date: Tue, 18 Jan 2011 16:25:43 -0500 Subject: [PATCH 1/2] Modify create_user to receive a site object --- django/contrib/auth/models.py | 4 ++-- django/contrib/auth/tests/__init__.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django/contrib/auth/models.py b/django/contrib/auth/models.py index f51ba3b..2657e86 100644
a b class Group(models.Model): 112 112 return self.name 113 113 114 114 class UserManager(models.Manager): 115 def create_user(self, username, email, password=None ):115 def create_user(self, username, email, password=None, site=None): 116 116 """ 117 117 Creates and saves a User with the given username, e-mail and password. 118 118 """ … … class UserManager(models.Manager): 129 129 130 130 user = self.model(username=username, email=email, is_staff=False, 131 131 is_active=True, is_superuser=False, last_login=now, 132 date_joined=now )132 date_joined=now, site=site) 133 133 134 134 user.set_password(password) 135 135 user.save(using=self._db) -
django/contrib/auth/tests/__init__.py
diff --git a/django/contrib/auth/tests/__init__.py b/django/contrib/auth/tests/__init__.py index 3a8f55b..3f0f3db 100644
a b from django.contrib.auth.tests.tokens import TokenGeneratorTest 14 14 from django.contrib.auth.tests.views import (PasswordResetTest, 15 15 ChangePasswordTest, LoginTest, LogoutTest, LoginURLSettings) 16 16 from django.contrib.auth.tests.permissions import TestAuthPermissions 17 17 from django.contrib.auth.tests.multitenancy import MultitenancyTests 18 18 # The password for the fixture data users is 'password' -
new file django/contrib/auth/tests/multitenancy.py
-- 1.7.1 From 9f86e2b835c67a10b8ac73e7deb4258e9bd45fab Mon Sep 17 00:00:00 2001 From: Jorge Eduardo Cardona <jorgeecardona@gmail.com> Date: Tue, 18 Jan 2011 16:32:21 -0500 Subject: [PATCH 2/2] Add the tests for multitenancy --- django/contrib/auth/tests/multitenancy.py | 39 +++++++++++++++++++++++++++++ 1 files changed, 39 insertions(+), 0 deletions(-) create mode 100644 django/contrib/auth/tests/multitenancy.py diff --git a/django/contrib/auth/tests/multitenancy.py b/django/contrib/auth/tests/multitenancy.py new file mode 100644 index 0000000..e681d04
- + 1 from django.db import IntegrityError 2 from django.conf import settings 3 from django.test import TestCase 4 from django.contrib.sites.models import Site 5 from django.contrib.auth.models import User 6 7 8 class MultitenancyTests(TestCase): 9 10 def setUp(self): 11 site = Site(id=settings.SITE_ID, 12 domain="example.com", 13 name="example.com") 14 site.save() 15 16 def test_user_with_current_site(self): 17 "Check that an users can be created in a site" 18 u = User.objects.create_user('testuser', 'text@example.com', 'testpw') 19 self.assertEqual(u.site, None) 20 21 # Asign site. 22 u.site = Site.objects.get_current() 23 u.save() 24 self.assertEqual(u.site, Site.objects.get_current()) 25 26 # Add a new user to None site. 27 u = User.objects.create_user('testuser', 'text@example.com', 'testpw') 28 self.assertEqual(u.site, None) 29 30 def test_add_user_duplicated_in_site(self): 31 32 # Add a new user with same username to current site. 33 u = User.objects.create_user('testuser', 'text@example.com', 'testpw', 34 Site.objects.get_current()) 35 self.assertEqual(u.site, Site.objects.get_current()) 36 self.assertRaises(IntegrityError, User.objects.create_user, 37 'testuser', 'text@example.com', 'testpw', 38 Site.objects.get_current()) 39