Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

[1.5.x] 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.
Backport of a962bc7 from master.
  • Loading branch information...
commit fc570b14152997f19523be3317da5e1438dbc34b 1 parent 0d3ec8d
@claudep claudep authored
View
13 django/contrib/auth/tests/__init__.py
@@ -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
+
+
+@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)
View
2  django/contrib/auth/tests/basic.py
@@ -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()
@override_settings(AUTH_USER_MODEL='badsetting')
def test_swappable_user_bad_setting(self):
Please sign in to comment.
Something went wrong with that request. Please try again.