diff --git a/django/contrib/auth/tests/__init__.py b/django/contrib/auth/tests/__init__.py index b3007ea484b..038c8980d9d 100644 --- a/django/contrib/auth/tests/__init__.py +++ b/django/contrib/auth/tests/__init__.py @@ -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) diff --git a/django/contrib/auth/tests/basic.py b/django/contrib/auth/tests/basic.py index bc7344f753e..2c807cca517 100644 --- a/django/contrib/auth/tests/basic.py +++ b/django/contrib/auth/tests/basic.py @@ -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):