Ticket #17966: 17966-1.diff

File 17966-1.diff, 2.2 KB (added by Claude Paroz, 13 years ago)

Possible fix

  • django/contrib/auth/tests/models.py

    diff --git a/django/contrib/auth/tests/models.py b/django/contrib/auth/tests/models.py
    index 5d0e4f1..b08de72 100644
    a b from django.contrib.auth.models import (Group, User,  
    66
    77
    88class ProfileTestCase(TestCase):
    9     fixtures = ['authtestdata.json']
    109
    1110    def setUp(self):
    1211        """Backs up the AUTH_PROFILE_MODULE"""
    13         self.old_AUTH_PROFILE_MODULE = getattr(settings,
    14                                                'AUTH_PROFILE_MODULE', None)
    15 
    16     def tearDown(self):
    17         """Restores the AUTH_PROFILE_MODULE -- if it was not set it is deleted,
    18         otherwise the old value is restored"""
    19         if self.old_AUTH_PROFILE_MODULE is None and \
    20                 hasattr(settings, 'AUTH_PROFILE_MODULE'):
    21             del settings.AUTH_PROFILE_MODULE
    22 
    23         if self.old_AUTH_PROFILE_MODULE is not None:
    24             settings.AUTH_PROFILE_MODULE = self.old_AUTH_PROFILE_MODULE
     12        self.user = User.objects.create(username='testclient')
    2513
     14    @override_settings(AUTH_PROFILE_MODULE='')
    2615    def test_site_profile_not_available(self):
    2716        # calling get_profile without AUTH_PROFILE_MODULE set
    28         if hasattr(settings, 'AUTH_PROFILE_MODULE'):
    29             del settings.AUTH_PROFILE_MODULE
    30         user = User.objects.get(username='testclient')
    31         self.assertRaises(SiteProfileNotAvailable, user.get_profile)
     17        self.assertRaises(SiteProfileNotAvailable, self.user.get_profile)
    3218
     19    @override_settings(AUTH_PROFILE_MODULE='foobar')
     20    def test_site_profile_bad_syntax(self):
    3321        # Bad syntax in AUTH_PROFILE_MODULE:
    34         settings.AUTH_PROFILE_MODULE = 'foobar'
    35         self.assertRaises(SiteProfileNotAvailable, user.get_profile)
     22        self.assertRaises(SiteProfileNotAvailable, self.user.get_profile)
    3623
     24    @override_settings(AUTH_PROFILE_MODULE='foo.bar')
     25    def test_site_profile_missing_module(self):
    3726        # module that doesn't exist
    38         settings.AUTH_PROFILE_MODULE = 'foo.bar'
    39         self.assertRaises(SiteProfileNotAvailable, user.get_profile)
     27        self.assertRaises(SiteProfileNotAvailable, self.user.get_profile)
    4028
    4129ProfileTestCase = override_settings(USE_TZ=False)(ProfileTestCase)
    4230
Back to Top