From 2f615b10e6330d27dccbd770a4628200044acf70 Mon Sep 17 00:00:00 2001 From: ana-balica Date: Mon, 15 Jun 2015 15:55:55 +0300 Subject: Fixed #24829 -- Allowed use of TemplateResponse in view error handlers. --- tests/handlers/templates/test_handler.html | 1 + tests/handlers/tests_custom_error_handlers.py | 30 +++++++++++++++++++++++++++ 2 files changed, 31 insertions(+) create mode 100644 tests/handlers/templates/test_handler.html create mode 100644 tests/handlers/tests_custom_error_handlers.py (limited to 'tests') 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) -- cgit v1.3