Skip to content

Commit

Permalink
Moved the AUTH_USER_MODEL setting changed receiver.
Browse files Browse the repository at this point in the history
Test suites besides Django's may need the same behavior.
  • Loading branch information
charettes committed May 18, 2016
1 parent b9ae662 commit 7694e19
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 9 deletions.
7 changes: 7 additions & 0 deletions django/test/signals.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
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
Expand Down Expand Up @@ -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()
9 changes: 0 additions & 9 deletions tests/auth_tests/test_basic.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,16 @@

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"
Expand Down

0 comments on commit 7694e19

Please sign in to comment.