def override_middleware():
from ...settings import OVERRIDE_MIDDLEWARE
if OVERRIDE_MIDDLEWARE:
- has_old = hasattr(settings, 'MIDDLEWARE_CLASSES')
- old = getattr(settings, 'MIDDLEWARE_CLASSES', None)
- settings.MIDDLEWARE_CLASSES = (
+ if hasattr(settings, 'MIDDLEWARE'):
+ mw_setting = 'MIDDLEWARE'
+ else:
+ mw_setting = 'MIDDLEWARE_CLASSES'
+ has_old = hasattr(settings, mw_setting)
+ old = getattr(settings, mw_setting, None)
+ setattr(settings, mw_setting, (
'django.contrib.sessions.middleware.SessionMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.middleware.locale.LocaleMiddleware',
'django.middleware.common.CommonMiddleware',
- )
+ ))
yield
if has_old:
- setattr(settings, 'MIDDLEWARE_CLASSES', old)
+ setattr(settings, mw_setting, old)
else: # NOQA
- delattr(settings, 'MIDDLEWARE_CLASSES')
+ delattr(settings, mw_setting)
else:
yield # pragma: no cover