From cc8a94f88b7afe5f549f3cc856f38e0a9e982025 Mon Sep 17 00:00:00 2001 From: mlavin Date: Sun, 20 Apr 2014 09:01:44 -0400 Subject: [PATCH] [1.7.x] Fixed #22477 -- Update Django's tests to handle changed MIDDLEWARE_CLASSES defaults. --- .../auth/tests/test_context_processors.py | 18 ++++++++++++++---- tests/admin_scripts/tests.py | 3 ++- tests/runtests.py | 12 ++++++++++++ 3 files changed, 28 insertions(+), 5 deletions(-) diff --git a/django/contrib/auth/tests/test_context_processors.py b/django/contrib/auth/tests/test_context_processors.py index 48c5b77f2029c..7bdf9002a502b 100644 --- a/django/contrib/auth/tests/test_context_processors.py +++ b/django/contrib/auth/tests/test_context_processors.py @@ -77,8 +77,13 @@ class AuthContextProcessorTests(TestCase): fixtures = ['context-processors-users.xml'] @override_settings( - MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES, - TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS, + MIDDLEWARE_CLASSES=( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + ), + TEMPLATE_CONTEXT_PROCESSORS=( + 'django.contrib.auth.context_processors.auth', + ), ) def test_session_not_accessed(self): """ @@ -89,8 +94,13 @@ def test_session_not_accessed(self): self.assertContains(response, "Session not accessed") @override_settings( - MIDDLEWARE_CLASSES=global_settings.MIDDLEWARE_CLASSES, - TEMPLATE_CONTEXT_PROCESSORS=global_settings.TEMPLATE_CONTEXT_PROCESSORS, + MIDDLEWARE_CLASSES=( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + ), + TEMPLATE_CONTEXT_PROCESSORS=( + 'django.contrib.auth.context_processors.auth', + ), ) def test_session_is_accessed(self): """ diff --git a/tests/admin_scripts/tests.py b/tests/admin_scripts/tests.py index 90fd3520e2ab4..862bf6476da9a 100644 --- a/tests/admin_scripts/tests.py +++ b/tests/admin_scripts/tests.py @@ -58,11 +58,12 @@ def write_settings(self, filename, apps=None, is_dir=False, sdict=None, extra=No 'ROOT_URLCONF', 'SECRET_KEY', 'TEST_RUNNER', # We need to include TEST_RUNNER, otherwise we get a compatibility warning. + 'MIDDLEWARE_CLASSES', # We need to include MIDDLEWARE_CLASSES, otherwise we get a compatibility warning. ] for s in exports: if hasattr(settings, s): o = getattr(settings, s) - if not isinstance(o, dict): + if not isinstance(o, (dict, tuple, list)): o = "'%s'" % o settings_file.write("%s = %s\n" % (s, o)) diff --git a/tests/runtests.py b/tests/runtests.py index 0b065ea9515fe..90124a36900b2 100755 --- a/tests/runtests.py +++ b/tests/runtests.py @@ -56,6 +56,14 @@ 'servers.another_app', ] +ALWAYS_MIDDLEWARE_CLASSES = ( + 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', + 'django.contrib.auth.middleware.AuthenticationMiddleware', + 'django.contrib.messages.middleware.MessageMiddleware', +) + def get_test_modules(): from django.contrib.gis.tests.utils import HAS_SPATIAL_DB @@ -107,6 +115,7 @@ def no_available_apps(self): 'LANGUAGE_CODE': settings.LANGUAGE_CODE, 'STATIC_URL': settings.STATIC_URL, 'STATIC_ROOT': settings.STATIC_ROOT, + 'MIDDLEWARE_CLASSES': settings.MIDDLEWARE_CLASSES, } # Redirect some settings for the duration of these tests. @@ -117,6 +126,9 @@ def no_available_apps(self): settings.TEMPLATE_DIRS = (os.path.join(RUNTESTS_DIR, TEST_TEMPLATE_DIR),) settings.LANGUAGE_CODE = 'en' settings.SITE_ID = 1 + settings.MIDDLEWARE_CLASSES = ALWAYS_MIDDLEWARE_CLASSES + # Ensure the middleware classes are seen as overridden otherwise we get a compatibility warning. + settings._explicit_settings.add('MIDDLEWARE_CLASSES') if verbosity > 0: # Ensure any warnings captured to logging are piped through a verbose