summaryrefslogtreecommitdiff
path: root/tests/handlers
diff options
context:
space:
mode:
authorClaude Paroz <claude@2xlibre.net>2016-06-23 16:30:07 +0200
committerClaude Paroz <claude@2xlibre.net>2016-06-24 10:22:30 +0200
commit742ea51413b3aab07c6afbfd1d52c1908ffcb510 (patch)
tree5d773661aab4bbff0bb8e0fd66e6a5a53e515144 /tests/handlers
parent9f66302797d0346ae4615369e3c2440855e0b624 (diff)
downloaddjango-742ea51413b3aab07c6afbfd1d52c1908ffcb510.tar.gz
Refs #24829 -- Made TemplateResponse.content available sooner in exception context
Thanks Tim Graham for the initial patch.
Diffstat (limited to 'tests/handlers')
-rw-r--r--tests/handlers/tests_custom_error_handlers.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/tests/handlers/tests_custom_error_handlers.py b/tests/handlers/tests_custom_error_handlers.py
index 24c2c8b446..04f58fbe2a 100644
--- a/tests/handlers/tests_custom_error_handlers.py
+++ b/tests/handlers/tests_custom_error_handlers.py
@@ -1,7 +1,19 @@
from django.conf.urls import url
from django.core.exceptions import PermissionDenied
from django.template.response import TemplateResponse
-from django.test import SimpleTestCase, override_settings
+from django.test import SimpleTestCase, modify_settings, override_settings
+
+
+class MiddlewareAccessingContent(object):
+ def __init__(self, get_response):
+ self.get_response = get_response
+
+ def __call__(self, request):
+ response = self.get_response(request)
+ # Response.content should be available in the middleware even with a
+ # TemplateResponse-based exception response.
+ assert response.content
+ return response
def template_response_error_handler(request, exception=None):
@@ -20,6 +32,7 @@ handler403 = template_response_error_handler
@override_settings(ROOT_URLCONF='handlers.tests_custom_error_handlers')
+@modify_settings(MIDDLEWARE={'append': 'handlers.tests_custom_error_handlers.MiddlewareAccessingContent'})
class CustomErrorHandlerTests(SimpleTestCase):
def test_handler_renders_template_response(self):