From ced0bdd923f22ee6750ec90c9582d452dbc56203 Mon Sep 17 00:00:00 2001 From: Tim Graham Date: Tue, 20 Nov 2018 10:38:42 -0500 Subject: [PATCH] Tested a middleware's process_template_response() returning None. --- tests/middleware_exceptions/middleware.py | 5 +++++ tests/middleware_exceptions/tests.py | 9 +++++++++ 2 files changed, 14 insertions(+) diff --git a/tests/middleware_exceptions/middleware.py b/tests/middleware_exceptions/middleware.py index 49e5d43189..63502c6902 100644 --- a/tests/middleware_exceptions/middleware.py +++ b/tests/middleware_exceptions/middleware.py @@ -58,6 +58,11 @@ class LogMiddleware(BaseMiddleware): return response +class NoTemplateResponseMiddleware(BaseMiddleware): + def process_template_response(self, request, response): + return None + + class NotFoundMiddleware(BaseMiddleware): def __call__(self, request): raise Http404('not found') diff --git a/tests/middleware_exceptions/tests.py b/tests/middleware_exceptions/tests.py index 783257c057..053a768dff 100644 --- a/tests/middleware_exceptions/tests.py +++ b/tests/middleware_exceptions/tests.py @@ -56,6 +56,15 @@ class MiddlewareTests(SimpleTestCase): response = self.client.get('/middleware_exceptions/template_response/') self.assertEqual(response.content, b'template_response OK\nTemplateResponseMiddleware') + @override_settings(MIDDLEWARE=['middleware_exceptions.middleware.NoTemplateResponseMiddleware']) + def test_process_template_response_returns_none(self): + msg = ( + "NoTemplateResponseMiddleware.process_template_response didn't " + "return an HttpResponse object. It returned None instead." + ) + with self.assertRaisesMessage(ValueError, msg): + self.client.get('/middleware_exceptions/template_response/') + @override_settings(MIDDLEWARE=['middleware_exceptions.middleware.LogMiddleware']) def test_view_exception_converted_before_middleware(self): response = self.client.get('/middleware_exceptions/permission_denied/')