Ticket #12776: 12776.patch
File 12776.patch, 3.8 KB (added by , 15 years ago) |
---|
-
django/contrib/auth/tests/__init__.py
6 6 import RemoteUserTest, RemoteUserNoCreateTest, RemoteUserCustomTest 7 7 from django.contrib.auth.tests.auth_backends import BackendTest, RowlevelBackendTest, AnonymousUserBackendTest, NoAnonymousUserBackendTest 8 8 from django.contrib.auth.tests.tokens import TOKEN_GENERATOR_TESTS 9 from django.contrib.auth.tests.models import ProfileTestCase 9 10 10 11 # The password for the fixture data users is 'password' 11 12 -
django/contrib/auth/tests/models.py
1 from django.conf import settings 2 from django.test import TestCase 3 from django.contrib.auth.models import User, SiteProfileNotAvailable 4 5 class ProfileTestCase(TestCase): 6 fixtures = ['authtestdata.json'] 7 def setUp(self): 8 """Backs up the AUTH_PROFILE_MODULE""" 9 self.old_AUTH_PROFILE_MODULE = getattr(settings, 10 'AUTH_PROFILE_MODULE', None) 11 12 def tearDown(self): 13 """Restores the AUTH_PROFILE_MODULE -- if it was not set it is deleted, 14 otherwise the old value is restored""" 15 if self.old_AUTH_PROFILE_MODULE is None and \ 16 hasattr(settings, 'AUTH_PROFILE_MODULE'): 17 del settings.AUTH_PROFILE_MODULE 18 19 if self.old_AUTH_PROFILE_MODULE is not None: 20 settings.AUTH_PROFILE_MODULE = self.old_AUTH_PROFILE_MODULE 21 22 def test_site_profile_not_available(self): 23 # calling get_profile without AUTH_PROFILE_MODULE set 24 if hasattr(settings, 'AUTH_PROFILE_MODULE'): 25 del settings.AUTH_PROFILE_MODULE 26 user = User.objects.get(username='testclient') 27 self.assertRaises(SiteProfileNotAvailable, user.get_profile) 28 29 # Bad syntax in AUTH_PROFILE_MODULE: 30 settings.AUTH_PROFILE_MODULE = 'foobar' 31 self.assertRaises(SiteProfileNotAvailable, user.get_profile) 32 33 # module that doesn't exist 34 settings.AUTH_PROFILE_MODULE = 'foo.bar' 35 self.assertRaises(SiteProfileNotAvailable, user.get_profile) -
django/contrib/auth/models.py
336 336 if not hasattr(self, '_profile_cache'): 337 337 from django.conf import settings 338 338 if not getattr(settings, 'AUTH_PROFILE_MODULE', False): 339 raise SiteProfileNotAvailable 339 raise SiteProfileNotAvailable('You need to set AUTH_PROFILE_MO' 340 'DULE in your project settings') 340 341 try: 341 342 app_label, model_name = settings.AUTH_PROFILE_MODULE.split('.') 343 except ValueError: 344 raise SiteProfileNotAvailable('app_label and model_name should' 345 ' be separated by a dot in the AUTH_PROFILE_MODULE set' 346 'ting') 347 348 try: 342 349 model = models.get_model(app_label, model_name) 350 if model is None: 351 raise SiteProfileNotAvailable('Unable to load the profile ' 352 'model, check AUTH_PROFILE_MODULE in your project sett' 353 'ings') 343 354 self._profile_cache = model._default_manager.using(self._state.db).get(user__id__exact=self.id) 344 355 self._profile_cache.user = self 345 356 except (ImportError, ImproperlyConfigured):