root: fix RemovedInDjango40Warning being triggered

This commit is contained in:
Jens Langhammer 2020-09-28 11:47:50 +02:00
parent 8f4e954160
commit bd78087582
2 changed files with 16 additions and 5 deletions

View File

@ -3,6 +3,7 @@ from unittest.mock import MagicMock, Mock, PropertyMock, patch
from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sessions.middleware import SessionMiddleware
from django.core.cache import cache from django.core.cache import cache
from django.http import HttpRequest
from django.shortcuts import reverse from django.shortcuts import reverse
from django.test import RequestFactory, TestCase from django.test import RequestFactory, TestCase
from guardian.shortcuts import get_anonymous_user from guardian.shortcuts import get_anonymous_user
@ -23,6 +24,11 @@ CACHE_MOCK = Mock(wraps=cache)
POLICY_RETURN_TRUE = MagicMock(return_value=PolicyResult(True)) POLICY_RETURN_TRUE = MagicMock(return_value=PolicyResult(True))
def dummy_get_response(request: HttpRequest): # pragma: no cover
"""Dummy get_response for SessionMiddleware"""
return None
class TestFlowPlanner(TestCase): class TestFlowPlanner(TestCase):
"""Test planner logic""" """Test planner logic"""
@ -164,7 +170,7 @@ class TestFlowPlanner(TestCase):
) )
request.user = get_anonymous_user() request.user = get_anonymous_user()
middleware = SessionMiddleware() middleware = SessionMiddleware(dummy_get_response)
middleware.process_request(request) middleware.process_request(request)
request.session.save() request.session.save()

View File

@ -1,6 +1,6 @@
"""Test AuthN Request generator and parser""" """Test AuthN Request generator and parser"""
from django.contrib.sessions.middleware import SessionMiddleware from django.contrib.sessions.middleware import SessionMiddleware
from django.http.request import QueryDict from django.http.request import HttpRequest, QueryDict
from django.test import RequestFactory, TestCase from django.test import RequestFactory, TestCase
from guardian.utils import get_anonymous_user from guardian.utils import get_anonymous_user
@ -19,6 +19,11 @@ from passbook.sources.saml.processors.request import (
from passbook.sources.saml.processors.response import ResponseProcessor from passbook.sources.saml.processors.response import ResponseProcessor
def dummy_get_response(request: HttpRequest): # pragma: no cover
"""Dummy get_response for SessionMiddleware"""
return None
class TestAuthNRequest(TestCase): class TestAuthNRequest(TestCase):
"""Test AuthN Request generator and parser""" """Test AuthN Request generator and parser"""
@ -41,7 +46,7 @@ class TestAuthNRequest(TestCase):
"""Test generated AuthNRequest with valid signature""" """Test generated AuthNRequest with valid signature"""
http_request = self.factory.get("/") http_request = self.factory.get("/")
middleware = SessionMiddleware() middleware = SessionMiddleware(dummy_get_response)
middleware.process_request(http_request) middleware.process_request(http_request)
http_request.session.save() http_request.session.save()
@ -59,7 +64,7 @@ class TestAuthNRequest(TestCase):
"""Test generated AuthNRequest with valid signature (detached)""" """Test generated AuthNRequest with valid signature (detached)"""
http_request = self.factory.get("/") http_request = self.factory.get("/")
middleware = SessionMiddleware() middleware = SessionMiddleware(dummy_get_response)
middleware.process_request(http_request) middleware.process_request(http_request)
http_request.session.save() http_request.session.save()
@ -78,7 +83,7 @@ class TestAuthNRequest(TestCase):
http_request = self.factory.get("/") http_request = self.factory.get("/")
http_request.user = get_anonymous_user() http_request.user = get_anonymous_user()
middleware = SessionMiddleware() middleware = SessionMiddleware(dummy_get_response)
middleware.process_request(http_request) middleware.process_request(http_request)
http_request.session.save() http_request.session.save()