From 26b2efe361f562321b642c32fb72844f2a968d40 Mon Sep 17 00:00:00 2001 From: Gertjan Oude Lohuis Date: Tue, 18 Apr 2017 14:24:21 +0200 Subject: [PATCH] Fix compatibility for older versions of Django --- oidc_provider/middleware.py | 6 +++++- oidc_provider/tests/test_middleware.py | 9 ++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/oidc_provider/middleware.py b/oidc_provider/middleware.py index 06f4d82..3516bc4 100644 --- a/oidc_provider/middleware.py +++ b/oidc_provider/middleware.py @@ -1,4 +1,8 @@ -from django.utils.deprecation import MiddlewareMixin +try: + # https://docs.djangoproject.com/en/1.10/topics/http/middleware/#upgrading-pre-django-1-10-style-middleware + from django.utils.deprecation import MiddlewareMixin +except ImportError: + MiddlewareMixin = object from oidc_provider import settings from oidc_provider.lib.utils.common import get_browser_state_or_default diff --git a/oidc_provider/tests/test_middleware.py b/oidc_provider/tests/test_middleware.py index 9464ec2..c2a02df 100644 --- a/oidc_provider/tests/test_middleware.py +++ b/oidc_provider/tests/test_middleware.py @@ -1,6 +1,6 @@ from django.conf.urls import url from django.test import TestCase, override_settings -from django.views import View +from django.views.generic import View from mock import mock @@ -10,10 +10,13 @@ class StubbedViews: urlpatterns = [url('^test/', SampleView.as_view())] +MW_CLASSES = ('django.contrib.sessions.middleware.SessionMiddleware', + 'oidc_provider.middleware.SessionManagementMiddleware') + @override_settings(ROOT_URLCONF=StubbedViews, - MIDDLEWARE=('django.contrib.sessions.middleware.SessionMiddleware', - 'oidc_provider.middleware.SessionManagementMiddleware'), + MIDDLEWARE=MW_CLASSES, + MIDDLEWARE_CLASSES=MW_CLASSES, OIDC_SESSION_MANAGEMENT_ENABLE=True) class MiddlewareTestCase(TestCase):