From 7694e196cee9304883122dc206327566af635f5e Mon Sep 17 00:00:00 2001 From: Simon Charette Date: Wed, 18 May 2016 09:33:53 -0400 Subject: [PATCH] Moved the AUTH_USER_MODEL setting changed receiver. Test suites besides Django's may need the same behavior. --- django/test/signals.py | 7 +++++++ tests/auth_tests/test_basic.py | 9 --------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/django/test/signals.py b/django/test/signals.py index e9ba517073..62b386268c 100644 --- a/django/test/signals.py +++ b/django/test/signals.py @@ -3,6 +3,7 @@ import threading import time import warnings +from django.apps import apps from django.core.signals import setting_changed from django.db import connections, router from django.db.utils import ConnectionRouter @@ -168,3 +169,9 @@ def auth_password_validators_changed(**kwargs): if kwargs['setting'] == 'AUTH_PASSWORD_VALIDATORS': from django.contrib.auth.password_validation import get_default_password_validators get_default_password_validators.cache_clear() + + +@receiver(setting_changed) +def user_model_swapped(**kwargs): + if kwargs['setting'] == 'AUTH_USER_MODEL': + apps.clear_cache() diff --git a/tests/auth_tests/test_basic.py b/tests/auth_tests/test_basic.py index 7421f66e49..caefa9c7a0 100644 --- a/tests/auth_tests/test_basic.py +++ b/tests/auth_tests/test_basic.py @@ -3,25 +3,16 @@ from __future__ import unicode_literals import warnings -from django.apps import apps from django.contrib.auth import get_user_model from django.contrib.auth.models import AnonymousUser, User from django.core.exceptions import ImproperlyConfigured from django.db import IntegrityError -from django.dispatch import receiver from django.test import TestCase, override_settings -from django.test.signals import setting_changed from django.utils import translation from .models import CustomUser -@receiver(setting_changed) -def user_model_swapped(**kwargs): - if kwargs['setting'] == 'AUTH_USER_MODEL': - apps.clear_cache() - - class BasicTestCase(TestCase): def test_user(self): "Check that users can be created and can set their password"