Removed direct manipulation of settings in auth tests; refs #21230.
This commit is contained in:
parent
23c4cbc0fa
commit
4444ff39a4
|
@ -1,7 +1,6 @@
|
|||
from __future__ import unicode_literals
|
||||
from datetime import date
|
||||
|
||||
from django.conf import settings
|
||||
from django.contrib.auth.backends import ModelBackend
|
||||
from django.contrib.auth.models import User, Group, Permission, AnonymousUser
|
||||
from django.contrib.auth.tests.utils import skipIfCustomUser
|
||||
|
@ -34,12 +33,14 @@ class BaseModelBackendTest(object):
|
|||
backend = 'django.contrib.auth.backends.ModelBackend'
|
||||
|
||||
def setUp(self):
|
||||
self.curr_auth = list(settings.AUTHENTICATION_BACKENDS)
|
||||
settings.AUTHENTICATION_BACKENDS = [self.backend]
|
||||
self.patched_settings = modify_settings(
|
||||
AUTHENTICATION_BACKENDS={'append': self.backend},
|
||||
)
|
||||
self.patched_settings.enable()
|
||||
self.create_users()
|
||||
|
||||
def tearDown(self):
|
||||
settings.AUTHENTICATION_BACKENDS = self.curr_auth
|
||||
self.patched_settings.disable()
|
||||
# The custom_perms test messes with ContentTypes, which will
|
||||
# be cached; flush the cache to ensure there are no side effects
|
||||
# Refs #14975, #14925
|
||||
|
|
|
@ -6,7 +6,7 @@ from django.contrib.auth.backends import RemoteUserBackend
|
|||
from django.contrib.auth.middleware import RemoteUserMiddleware
|
||||
from django.contrib.auth.models import User
|
||||
from django.contrib.auth.tests.utils import skipIfCustomUser
|
||||
from django.test import TestCase, override_settings
|
||||
from django.test import TestCase, modify_settings, override_settings
|
||||
from django.utils import timezone
|
||||
|
||||
|
||||
|
@ -23,15 +23,14 @@ class RemoteUserTest(TestCase):
|
|||
known_user2 = 'knownuser2'
|
||||
|
||||
def setUp(self):
|
||||
self.curr_middleware = list(settings.MIDDLEWARE_CLASSES)
|
||||
self.curr_auth = list(settings.AUTHENTICATION_BACKENDS)
|
||||
settings.MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES + [self.middleware]
|
||||
settings.AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS + [self.backend]
|
||||
self.patched_settings = modify_settings(
|
||||
AUTHENTICATION_BACKENDS={'append': self.backend},
|
||||
MIDDLEWARE_CLASSES={'append': self.middleware},
|
||||
)
|
||||
self.patched_settings.enable()
|
||||
|
||||
def tearDown(self):
|
||||
"""Restores settings to avoid breaking other tests."""
|
||||
settings.MIDDLEWARE_CLASSES = self.curr_middleware
|
||||
settings.AUTHENTICATION_BACKENDS = self.curr_auth
|
||||
self.patched_settings.disable()
|
||||
|
||||
def test_no_remote_user(self):
|
||||
"""
|
||||
|
|
Loading…
Reference in New Issue