mirror of https://github.com/django/django.git
Tested a middleware's process_template_response() returning None.
This commit is contained in:
parent
bff5ccff75
commit
ced0bdd923
|
@ -58,6 +58,11 @@ class LogMiddleware(BaseMiddleware):
|
||||||
return response
|
return response
|
||||||
|
|
||||||
|
|
||||||
|
class NoTemplateResponseMiddleware(BaseMiddleware):
|
||||||
|
def process_template_response(self, request, response):
|
||||||
|
return None
|
||||||
|
|
||||||
|
|
||||||
class NotFoundMiddleware(BaseMiddleware):
|
class NotFoundMiddleware(BaseMiddleware):
|
||||||
def __call__(self, request):
|
def __call__(self, request):
|
||||||
raise Http404('not found')
|
raise Http404('not found')
|
||||||
|
|
|
@ -56,6 +56,15 @@ class MiddlewareTests(SimpleTestCase):
|
||||||
response = self.client.get('/middleware_exceptions/template_response/')
|
response = self.client.get('/middleware_exceptions/template_response/')
|
||||||
self.assertEqual(response.content, b'template_response OK\nTemplateResponseMiddleware')
|
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'])
|
@override_settings(MIDDLEWARE=['middleware_exceptions.middleware.LogMiddleware'])
|
||||||
def test_view_exception_converted_before_middleware(self):
|
def test_view_exception_converted_before_middleware(self):
|
||||||
response = self.client.get('/middleware_exceptions/permission_denied/')
|
response = self.client.get('/middleware_exceptions/permission_denied/')
|
||||||
|
|
Loading…
Reference in New Issue