summaryrefslogtreecommitdiff
path: root/tests/handlers
diff options
context:
space:
mode:
Diffstat (limited to 'tests/handlers')
-rw-r--r--tests/handlers/templates/test_handler.html1
-rw-r--r--tests/handlers/tests_custom_error_handlers.py30
2 files changed, 31 insertions, 0 deletions
diff --git a/tests/handlers/templates/test_handler.html b/tests/handlers/templates/test_handler.html
new file mode 100644
index 0000000000..6f46e3e88f
--- /dev/null
+++ b/tests/handlers/templates/test_handler.html
@@ -0,0 +1 @@
+Error handler content
diff --git a/tests/handlers/tests_custom_error_handlers.py b/tests/handlers/tests_custom_error_handlers.py
new file mode 100644
index 0000000000..24c2c8b446
--- /dev/null
+++ b/tests/handlers/tests_custom_error_handlers.py
@@ -0,0 +1,30 @@
+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
+
+
+def template_response_error_handler(request, exception=None):
+ return TemplateResponse(request, 'test_handler.html', status=403)
+
+
+def permission_denied_view(request):
+ raise PermissionDenied
+
+
+urlpatterns = [
+ url(r'^$', permission_denied_view),
+]
+
+handler403 = template_response_error_handler
+
+
+@override_settings(ROOT_URLCONF='handlers.tests_custom_error_handlers')
+class CustomErrorHandlerTests(SimpleTestCase):
+
+ def test_handler_renders_template_response(self):
+ """
+ BaseHandler should render TemplateResponse if necessary.
+ """
+ response = self.client.get('/')
+ self.assertContains(response, 'Error handler content', status_code=403)