Commits

Mikhail Korobov committed 130a9a7

some basic tests for template response middleware

  • Participants
  • Parent commits fb80c7a

Comments (0)

Files changed (3)

File tests/regressiontests/middleware_exceptions/tests.py

 from django.test import TestCase
 from django.core.signals import got_request_exception
 from django.http import HttpResponse
-
+from django.template.response import TemplateResponse
+from django.template import Template
 
 class TestException(Exception):
     pass
         self.process_request_called = False
         self.process_view_called = False
         self.process_response_called = False
+        self.process_template_response_called = False
         self.process_exception_called = False
 
     def process_request(self, request):
     def process_view(self, request, view_func, view_args, view_kwargs):
         self.process_view_called = True
 
+    def process_template_response(self, request, response):
+        self.process_template_response_called = True
+        return response
+
     def process_response(self, request, response):
         self.process_response_called = True
         return response
         super(ResponseMiddleware, self).process_response(request, response)
         return HttpResponse('Response Middleware')
 
+class TemplateResponseMiddleware(TestMiddleware):
+    def process_template_response(self, request, response):
+        super(TemplateResponseMiddleware, self).process_template_response(request, response)
+        return TemplateResponse(request, Template('Template Response Middleware'))
+
 class ExceptionMiddleware(TestMiddleware):
     def process_exception(self, request, exception):
         super(ExceptionMiddleware, self).process_exception(request, exception)
         super(BadViewMiddleware, self).process_view(request, view_func, view_args, view_kwargs)
         raise TestException('Test View Exception')
 
+class BadTemplateResponseMiddleware(TestMiddleware):
+    def process_template_response(self, request, response):
+        super(BadTemplateResponseMiddleware, self).process_template_response(request, response)
+        raise TestException('Test Template Response Exception')
+
 class BadResponseMiddleware(TestMiddleware):
     def process_response(self, request, response):
         super(BadResponseMiddleware, self).process_response(request, response)
     def _add_middleware(self, middleware):
         self.client.handler._request_middleware.insert(0, middleware.process_request)
         self.client.handler._view_middleware.insert(0, middleware.process_view)
+        self.client.handler._template_response_middleware.append(middleware.process_template_response)
         self.client.handler._response_middleware.append(middleware.process_response)
         self.client.handler._exception_middleware.append(middleware.process_exception)
 
             exception, value, tb = self.exceptions[i]
             self.assertEquals(value.args, (error, ))
 
-    def assert_middleware_usage(self, middleware, request, view, response, exception):
+    def assert_middleware_usage(self, middleware, request, view, template_response, response, exception):
         self.assertEqual(middleware.process_request_called, request)
         self.assertEqual(middleware.process_view_called, view)
+        self.assertEqual(middleware.process_template_response_called, template_response)
         self.assertEqual(middleware.process_response_called, response)
         self.assertEqual(middleware.process_exception_called, exception)
 
         self.assert_exceptions_handled('/middleware_exceptions/view/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(middleware,      True,  False, True,  False)
-        self.assert_middleware_usage(post_middleware, False, False, True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(middleware,      True,  False, False, True,  False)
+        self.assert_middleware_usage(post_middleware, False, False, False, True,  False)
 
     def test_process_view_middleware(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/view/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(middleware,      True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  False, True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(middleware,      True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  False, False, True, False)
 
     def test_process_response_middleware(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/view/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True,  False)
-        self.assert_middleware_usage(middleware,      True,  True,  True,  False)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False, True,  False)
+        self.assert_middleware_usage(middleware,      True,  True, False, True,  False)
+        self.assert_middleware_usage(post_middleware, True,  True, False, True,  False)
+
+    def test_process_template_response_middleware(self):
+        pre_middleware = TestMiddleware()
+        middleware = TemplateResponseMiddleware()
+        post_middleware = TestMiddleware()
+        self._add_middleware(post_middleware)
+        self._add_middleware(middleware)
+        self._add_middleware(pre_middleware)
+        self.assert_exceptions_handled('/middleware_exceptions/template_response/', [])
+
+        # Check that the right middleware methods have been invoked
+        self.assert_middleware_usage(pre_middleware,  True,  True, True, True,  False)
+        self.assert_middleware_usage(middleware,      True,  True, True, True,  False)
+        self.assert_middleware_usage(post_middleware, True,  True, True, True,  False)
 
     def test_process_exception_middleware(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/view/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(middleware,      True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  True,  True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False, True, False)
+        self.assert_middleware_usage(middleware,      True,  True, False, True, False)
+        self.assert_middleware_usage(post_middleware, True,  True, False, True, False)
 
     def test_process_request_middleware_not_found(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/not_found/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(middleware,      True,  False, True,  False)
-        self.assert_middleware_usage(post_middleware, False, False, True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(middleware,      True,  False, False, True,  False)
+        self.assert_middleware_usage(post_middleware, False, False, False, True,  False)
 
     def test_process_view_middleware_not_found(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/not_found/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(middleware,      True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  False, True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(middleware,      True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  False, False, True, False)
+
+    def test_process_template_response_middleware_not_found(self):
+        pre_middleware = TestMiddleware()
+        middleware = TemplateResponseMiddleware()
+        post_middleware = TestMiddleware()
+        self._add_middleware(post_middleware)
+        self._add_middleware(middleware)
+        self._add_middleware(pre_middleware)
+        self.assert_exceptions_handled('/middleware_exceptions/not_found/', [])
+
+        # Check that the right middleware methods have been invoked
+        self.assert_middleware_usage(pre_middleware,  True,  True, False, True,  True)
+        self.assert_middleware_usage(middleware,      True,  True, False, True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False, True,  True)
 
     def test_process_response_middleware_not_found(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/not_found/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True,  True)
-        self.assert_middleware_usage(middleware,      True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False, True,  True)
+        self.assert_middleware_usage(middleware,      True,  True, False, True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False, True,  True)
 
     def test_process_exception_middleware_not_found(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/not_found/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(middleware,      True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True, True, False, True, False)
+        self.assert_middleware_usage(middleware,      True, True, False, True, True)
+        self.assert_middleware_usage(post_middleware, True, True, False, True, True)
 
     def test_process_request_middleware_exception(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/error/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(post_middleware, False, False, True,  False)
+        self.assert_middleware_usage(pre_middleware, True, False, False, True,  False)
+        self.assert_middleware_usage(middleware,     True, False, False, True,  False)
+        self.assert_middleware_usage(post_middleware, False, False, False, True,  False)
 
     def test_process_view_middleware_exception(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/error/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(middleware,      True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  False, True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False, True, False)
+        self.assert_middleware_usage(middleware,      True,  True, False, True, False)
+        self.assert_middleware_usage(post_middleware, True,  False, False, True, False)
 
     def test_process_response_middleware_exception(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/error/', ['Error in view'], Exception())
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True,  True)
-        self.assert_middleware_usage(middleware,      True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False, True,  True)
+        self.assert_middleware_usage(middleware,      True,  True, False, True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False, True,  True)
 
     def test_process_exception_middleware_exception(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/error/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(middleware,      True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False, True, False)
+        self.assert_middleware_usage(middleware,      True,  True, False, True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False, True,  True)
 
     def test_process_request_middleware_null_view(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/null_view/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(middleware,      True,  False, True,  False)
-        self.assert_middleware_usage(post_middleware, False, False, True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(middleware,      True,  False, False, True,  False)
+        self.assert_middleware_usage(post_middleware, False, False, False, True,  False)
 
     def test_process_view_middleware_null_view(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/null_view/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(middleware,      True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  False, True, False)
+        self.assert_middleware_usage(pre_middleware,  True, True, False, True, False)
+        self.assert_middleware_usage(middleware,      True, True, False, True, False)
+        self.assert_middleware_usage(post_middleware, True, False, False, True, False)
 
     def test_process_response_middleware_null_view(self):
         pre_middleware = TestMiddleware()
             ValueError())
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True,  False)
-        self.assert_middleware_usage(middleware,      True,  True,  True,  False)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False, True, False)
+        self.assert_middleware_usage(middleware,      True,  True, False, True, False)
+        self.assert_middleware_usage(post_middleware, True,  True, False, True, False)
 
     def test_process_exception_middleware_null_view(self):
         pre_middleware = TestMiddleware()
             ValueError())
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(middleware,      True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  True,  True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(middleware,      True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True, False)
 
     def test_process_request_middleware_permission_denied(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/permission_denied/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(middleware,      True,  False, True,  False)
-        self.assert_middleware_usage(post_middleware, False, False, True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(middleware,      True,  False, False, True,  False)
+        self.assert_middleware_usage(post_middleware, False, False, False, True,  False)
 
     def test_process_view_middleware_permission_denied(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/permission_denied/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(middleware,      True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  False, True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(middleware,      True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  False, False, True, False)
 
     def test_process_response_middleware_permission_denied(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/permission_denied/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True,  True)
-        self.assert_middleware_usage(middleware,      True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True,  True)
+        self.assert_middleware_usage(middleware,      True,  True, False,  True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True,  True)
 
     def test_process_exception_middleware_permission_denied(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/permission_denied/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(middleware,  True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(middleware,  True,  True, False,  True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True,  True)
 
 class BadMiddlewareTests(BaseMiddlewareExceptionTest):
 
         self.assert_exceptions_handled('/middleware_exceptions/view/', ['Test Request Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(bad_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(post_middleware, False, False, True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(bad_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(post_middleware, False, False, False, True,  False)
 
     def test_process_view_bad_middleware(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/view/', ['Test View Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  False, True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  False, False, True, False)
+
+    def test_process_template_response_bad_middleware(self):
+        pre_middleware = TestMiddleware()
+        bad_middleware = BadTemplateResponseMiddleware()
+        post_middleware = TestMiddleware()
+        self._add_middleware(post_middleware)
+        self._add_middleware(bad_middleware)
+        self._add_middleware(pre_middleware)
+        self.assert_exceptions_handled('/middleware_exceptions/template_response/', ['Test Template Response Exception'])
+
+        # Check that the right middleware methods have been invoked
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  False, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, True,  False,  False)
+        self.assert_middleware_usage(post_middleware, True,  True, True,  False,  False)
 
     def test_process_response_bad_middleware(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/view/', ['Test Response Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  False, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True,  False)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  False, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True,  False)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True,  False)
 
     def test_process_exception_bad_middleware(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/view/', [])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  True,  True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True, False)
 
     def test_process_request_bad_middleware_not_found(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/not_found/', ['Test Request Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(bad_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(post_middleware, False, False, True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(bad_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(post_middleware, False, False, False, True,  False)
 
     def test_process_view_bad_middleware_not_found(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/not_found/', ['Test View Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  False, True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  False, False, True, False)
 
     def test_process_response_bad_middleware_not_found(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/not_found/', ['Test Response Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  False, True)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  False, True)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True,  True)
 
     def test_process_exception_bad_middleware_not_found(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/not_found/', ['Test Exception Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True,  True)
 
     def test_process_request_bad_middleware_exception(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/error/', ['Test Request Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(bad_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(post_middleware, False, False, True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(bad_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(post_middleware, False, False, False, True,  False)
 
     def test_process_view_bad_middleware_exception(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/error/', ['Test View Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  False, True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  False, False, True, False)
 
     def test_process_response_bad_middleware_exception(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/error/', ['Error in view', 'Test Response Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  False, True)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  False, True)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True,  True)
 
     def test_process_exception_bad_middleware_exception(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/error/', ['Test Exception Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True,  True)
 
     def test_process_request_bad_middleware_null_view(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/null_view/', ['Test Request Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(bad_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(post_middleware, False, False, True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(bad_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(post_middleware, False, False, False, True,  False)
 
     def test_process_view_bad_middleware_null_view(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/null_view/', ['Test View Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  False, True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  False, False, True, False)
 
     def test_process_response_bad_middleware_null_view(self):
         pre_middleware = TestMiddleware()
             ])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  False, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True,  False)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  False, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True,  False)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True,  False)
 
     def test_process_exception_bad_middleware_null_view(self):
         pre_middleware = TestMiddleware()
             ValueError())
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  True,  True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True, False)
 
     def test_process_request_bad_middleware_permission_denied(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/permission_denied/', ['Test Request Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(bad_middleware,  True,  False, True,  False)
-        self.assert_middleware_usage(post_middleware, False, False, True,  False)
+        self.assert_middleware_usage(pre_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(bad_middleware,  True,  False, False, True,  False)
+        self.assert_middleware_usage(post_middleware, False, False, False, True,  False)
 
     def test_process_view_bad_middleware_permission_denied(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/permission_denied/', ['Test View Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(post_middleware, True,  False, True, False)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(post_middleware, True,  False, False, True, False)
 
     def test_process_response_bad_middleware_permission_denied(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/permission_denied/', ['Test Response Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  False, True)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  False, True)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True,  True)
 
     def test_process_exception_bad_middleware_permission_denied(self):
         pre_middleware = TestMiddleware()
         self.assert_exceptions_handled('/middleware_exceptions/permission_denied/', ['Test Exception Exception'])
 
         # Check that the right middleware methods have been invoked
-        self.assert_middleware_usage(pre_middleware,  True,  True,  True, False)
-        self.assert_middleware_usage(bad_middleware,  True,  True,  True,  True)
-        self.assert_middleware_usage(post_middleware, True,  True,  True,  True)
+        self.assert_middleware_usage(pre_middleware,  True,  True, False,  True, False)
+        self.assert_middleware_usage(bad_middleware,  True,  True, False,  True,  True)
+        self.assert_middleware_usage(post_middleware, True,  True, False,  True,  True)

File tests/regressiontests/middleware_exceptions/urls.py

     (r'^error/$', views.server_error),
     (r'^null_view/$', views.null_view),
     (r'^permission_denied/$', views.permission_denied),
+
+    (r'^template_response/$', views.template_response),
+    (r'^template_response_error/$', views.template_response_error),
 )

File tests/regressiontests/middleware_exceptions/views.py

 from django import http
 from django.core.exceptions import PermissionDenied
+from django.shortcuts import render
+from django.template import Template
 
 def normal_view(request):
     return http.HttpResponse('OK')
 
+def template_response(request):
+    return render(request, Template('OK'))
+
+def template_response_error(request):
+    return render(request, Template('{%'))
+
 def not_found(request):
     raise http.Http404()