Skip to content


Subversion checkout URL

You can clone with
Download ZIP
Browse files

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.
  • Loading branch information...
commit a962bc7c45d868523a18e5139b96b275b3df2589 1 parent 08b4a22
@claudep claudep authored
13 django/contrib/auth/tests/
@@ -14,3 +14,16 @@
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
+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)
2  django/contrib/auth/tests/
@@ -162,6 +162,8 @@ def test_get_user_model(self):
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()
def test_swappable_user_bad_setting(self):

0 comments on commit a962bc7

Please sign in to comment.
Something went wrong with that request. Please try again.