From bd780875828c6cd5a54654b3a6f5a9df0f3ca58e Mon Sep 17 00:00:00 2001 From: Jens Langhammer Date: Mon, 28 Sep 2020 11:47:50 +0200 Subject: [PATCH] root: fix RemovedInDjango40Warning being triggered --- passbook/flows/tests/test_planner.py | 8 +++++++- .../providers/saml/tests/test_auth_n_request.py | 13 +++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/passbook/flows/tests/test_planner.py b/passbook/flows/tests/test_planner.py index 13db0db56..4ad47ecf9 100644 --- a/passbook/flows/tests/test_planner.py +++ b/passbook/flows/tests/test_planner.py @@ -3,6 +3,7 @@ from unittest.mock import MagicMock, Mock, PropertyMock, patch from django.contrib.sessions.middleware import SessionMiddleware from django.core.cache import cache +from django.http import HttpRequest from django.shortcuts import reverse from django.test import RequestFactory, TestCase from guardian.shortcuts import get_anonymous_user @@ -23,6 +24,11 @@ CACHE_MOCK = Mock(wraps=cache) 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): """Test planner logic""" @@ -164,7 +170,7 @@ class TestFlowPlanner(TestCase): ) request.user = get_anonymous_user() - middleware = SessionMiddleware() + middleware = SessionMiddleware(dummy_get_response) middleware.process_request(request) request.session.save() diff --git a/passbook/providers/saml/tests/test_auth_n_request.py b/passbook/providers/saml/tests/test_auth_n_request.py index 66c511b9c..8fc511e98 100644 --- a/passbook/providers/saml/tests/test_auth_n_request.py +++ b/passbook/providers/saml/tests/test_auth_n_request.py @@ -1,6 +1,6 @@ """Test AuthN Request generator and parser""" 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 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 +def dummy_get_response(request: HttpRequest): # pragma: no cover + """Dummy get_response for SessionMiddleware""" + return None + + class TestAuthNRequest(TestCase): """Test AuthN Request generator and parser""" @@ -41,7 +46,7 @@ class TestAuthNRequest(TestCase): """Test generated AuthNRequest with valid signature""" http_request = self.factory.get("/") - middleware = SessionMiddleware() + middleware = SessionMiddleware(dummy_get_response) middleware.process_request(http_request) http_request.session.save() @@ -59,7 +64,7 @@ class TestAuthNRequest(TestCase): """Test generated AuthNRequest with valid signature (detached)""" http_request = self.factory.get("/") - middleware = SessionMiddleware() + middleware = SessionMiddleware(dummy_get_response) middleware.process_request(http_request) http_request.session.save() @@ -78,7 +83,7 @@ class TestAuthNRequest(TestCase): http_request = self.factory.get("/") http_request.user = get_anonymous_user() - middleware = SessionMiddleware() + middleware = SessionMiddleware(dummy_get_response) middleware.process_request(http_request) http_request.session.save()