mirror of https://github.com/django/django.git
Updated User manager when testing custom AUTH_USER_MODEL
This is giving more real test conditions when AUTH_USER_MODEL is set with override_settings.
This commit is contained in:
parent
08b4a22293
commit
a962bc7c45
|
@ -14,3 +14,16 @@ from django.contrib.auth.tests.tokens import *
|
|||
from django.contrib.auth.tests.views import *
|
||||
|
||||
# The password for the fixture data users is 'password'
|
||||
|
||||
from django.dispatch import receiver
|
||||
from django.test.signals import setting_changed
|
||||
|
||||
|
||||
@receiver(setting_changed)
|
||||
def user_model_swapped(**kwargs):
|
||||
if kwargs['setting'] == 'AUTH_USER_MODEL':
|
||||
from django.db.models.manager import ensure_default_manager
|
||||
from django.contrib.auth.models import User
|
||||
# Reset User manager
|
||||
setattr(User, 'objects', User._default_manager)
|
||||
ensure_default_manager(User)
|
||||
|
|
|
@ -162,6 +162,8 @@ class BasicTestCase(TestCase):
|
|||
def test_swappable_user(self):
|
||||
"The current user model can be swapped out for another"
|
||||
self.assertEqual(get_user_model(), CustomUser)
|
||||
with self.assertRaises(AttributeError):
|
||||
User.objects.all()
|
||||
|
||||
@override_settings(AUTH_USER_MODEL='badsetting')
|
||||
def test_swappable_user_bad_setting(self):
|
||||
|
|
Loading…
Reference in New Issue