Skip to content

Commit

Permalink
[1.7.x] Fixed #22477 -- Update Django's tests to handle changed MIDDL…
Browse files Browse the repository at this point in the history
…EWARE_CLASSES defaults.
  • Loading branch information
mlavin committed Apr 20, 2014
1 parent a33f6c0 commit cc8a94f
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 5 deletions.
18 changes: 14 additions & 4 deletions django/contrib/auth/tests/test_context_processors.py
Expand Up @@ -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):
"""
Expand All @@ -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):
"""
Expand Down
3 changes: 2 additions & 1 deletion tests/admin_scripts/tests.py
Expand Up @@ -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))

Expand Down
12 changes: 12 additions & 0 deletions tests/runtests.py
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand All @@ -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
Expand Down

0 comments on commit cc8a94f

Please sign in to comment.