Fixed #17966 -- Isolated ProfileTestCase from custom AUTH_PROFILE_MODULE
Thanks Rob Golding for helping on the patch.
This commit is contained in:
parent
d69f1d71c4
commit
5318783027
|
@ -5,39 +5,29 @@ from django.contrib.auth.models import (Group, User,
|
||||||
SiteProfileNotAvailable, UserManager)
|
SiteProfileNotAvailable, UserManager)
|
||||||
|
|
||||||
|
|
||||||
@override_settings(USE_TZ=False)
|
@override_settings(USE_TZ=False, AUTH_PROFILE_MODULE='')
|
||||||
class ProfileTestCase(TestCase):
|
class ProfileTestCase(TestCase):
|
||||||
fixtures = ['authtestdata.json']
|
|
||||||
|
|
||||||
def setUp(self):
|
|
||||||
"""Backs up the AUTH_PROFILE_MODULE"""
|
|
||||||
self.old_AUTH_PROFILE_MODULE = getattr(settings,
|
|
||||||
'AUTH_PROFILE_MODULE', None)
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
"""Restores the AUTH_PROFILE_MODULE -- if it was not set it is deleted,
|
|
||||||
otherwise the old value is restored"""
|
|
||||||
if self.old_AUTH_PROFILE_MODULE is None and \
|
|
||||||
hasattr(settings, 'AUTH_PROFILE_MODULE'):
|
|
||||||
del settings.AUTH_PROFILE_MODULE
|
|
||||||
|
|
||||||
if self.old_AUTH_PROFILE_MODULE is not None:
|
|
||||||
settings.AUTH_PROFILE_MODULE = self.old_AUTH_PROFILE_MODULE
|
|
||||||
|
|
||||||
def test_site_profile_not_available(self):
|
def test_site_profile_not_available(self):
|
||||||
|
user = User.objects.create(username='testclient')
|
||||||
|
|
||||||
# calling get_profile without AUTH_PROFILE_MODULE set
|
# calling get_profile without AUTH_PROFILE_MODULE set
|
||||||
if hasattr(settings, 'AUTH_PROFILE_MODULE'):
|
del settings.AUTH_PROFILE_MODULE
|
||||||
del settings.AUTH_PROFILE_MODULE
|
with self.assertRaisesRegexp(SiteProfileNotAvailable,
|
||||||
user = User.objects.get(username='testclient')
|
"You need to set AUTH_PROFILE_MODULE in your project"):
|
||||||
self.assertRaises(SiteProfileNotAvailable, user.get_profile)
|
user.get_profile()
|
||||||
|
|
||||||
# Bad syntax in AUTH_PROFILE_MODULE:
|
# Bad syntax in AUTH_PROFILE_MODULE:
|
||||||
settings.AUTH_PROFILE_MODULE = 'foobar'
|
settings.AUTH_PROFILE_MODULE = 'foobar'
|
||||||
self.assertRaises(SiteProfileNotAvailable, user.get_profile)
|
with self.assertRaisesRegexp(SiteProfileNotAvailable,
|
||||||
|
"app_label and model_name should be separated by a dot"):
|
||||||
|
user.get_profile()
|
||||||
|
|
||||||
# module that doesn't exist
|
# module that doesn't exist
|
||||||
settings.AUTH_PROFILE_MODULE = 'foo.bar'
|
settings.AUTH_PROFILE_MODULE = 'foo.bar'
|
||||||
self.assertRaises(SiteProfileNotAvailable, user.get_profile)
|
with self.assertRaisesRegexp(SiteProfileNotAvailable,
|
||||||
|
"Unable to load the profile model"):
|
||||||
|
user.get_profile()
|
||||||
|
|
||||||
|
|
||||||
@override_settings(USE_TZ=False)
|
@override_settings(USE_TZ=False)
|
||||||
|
|
Loading…
Reference in New Issue