Removed direct manipulation of settings in auth tests; refs #21230.

This commit is contained in:
Tim Graham 2015-02-04 09:56:55 -05:00
parent 23c4cbc0fa
commit 4444ff39a4
2 changed files with 12 additions and 12 deletions

View File

@ -1,7 +1,6 @@
from __future__ import unicode_literals from __future__ import unicode_literals
from datetime import date from datetime import date
from django.conf import settings
from django.contrib.auth.backends import ModelBackend from django.contrib.auth.backends import ModelBackend
from django.contrib.auth.models import User, Group, Permission, AnonymousUser from django.contrib.auth.models import User, Group, Permission, AnonymousUser
from django.contrib.auth.tests.utils import skipIfCustomUser from django.contrib.auth.tests.utils import skipIfCustomUser
@ -34,12 +33,14 @@ class BaseModelBackendTest(object):
backend = 'django.contrib.auth.backends.ModelBackend' backend = 'django.contrib.auth.backends.ModelBackend'
def setUp(self): def setUp(self):
self.curr_auth = list(settings.AUTHENTICATION_BACKENDS) self.patched_settings = modify_settings(
settings.AUTHENTICATION_BACKENDS = [self.backend] AUTHENTICATION_BACKENDS={'append': self.backend},
)
self.patched_settings.enable()
self.create_users() self.create_users()
def tearDown(self): def tearDown(self):
settings.AUTHENTICATION_BACKENDS = self.curr_auth self.patched_settings.disable()
# The custom_perms test messes with ContentTypes, which will # The custom_perms test messes with ContentTypes, which will
# be cached; flush the cache to ensure there are no side effects # be cached; flush the cache to ensure there are no side effects
# Refs #14975, #14925 # Refs #14975, #14925

View File

@ -6,7 +6,7 @@ from django.contrib.auth.backends import RemoteUserBackend
from django.contrib.auth.middleware import RemoteUserMiddleware from django.contrib.auth.middleware import RemoteUserMiddleware
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.contrib.auth.tests.utils import skipIfCustomUser 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 from django.utils import timezone
@ -23,15 +23,14 @@ class RemoteUserTest(TestCase):
known_user2 = 'knownuser2' known_user2 = 'knownuser2'
def setUp(self): def setUp(self):
self.curr_middleware = list(settings.MIDDLEWARE_CLASSES) self.patched_settings = modify_settings(
self.curr_auth = list(settings.AUTHENTICATION_BACKENDS) AUTHENTICATION_BACKENDS={'append': self.backend},
settings.MIDDLEWARE_CLASSES = settings.MIDDLEWARE_CLASSES + [self.middleware] MIDDLEWARE_CLASSES={'append': self.middleware},
settings.AUTHENTICATION_BACKENDS = settings.AUTHENTICATION_BACKENDS + [self.backend] )
self.patched_settings.enable()
def tearDown(self): def tearDown(self):
"""Restores settings to avoid breaking other tests.""" self.patched_settings.disable()
settings.MIDDLEWARE_CLASSES = self.curr_middleware
settings.AUTHENTICATION_BACKENDS = self.curr_auth
def test_no_remote_user(self): def test_no_remote_user(self):
""" """