diff options
| author | Raphael Michel <mail@raphaelmichel.de> | 2015-11-07 14:18:06 +0100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-11-17 14:28:18 -0500 |
| commit | 16945f0e9c57aeabadb6f2e2f150a2687455be40 (patch) | |
| tree | 6d16352dea219959fa54fcc2e4279121bfb5cecc /tests | |
| parent | 20d2778597e89fc2de084bdaa128a438fbf12c7b (diff) | |
Fixed #25695 -- Added template_name parameter to csrf_failure() view.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/view_tests/tests/test_csrf.py | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/tests/view_tests/tests/test_csrf.py b/tests/view_tests/tests/test_csrf.py index f6531b882c..f595652978 100644 --- a/tests/view_tests/tests/test_csrf.py +++ b/tests/view_tests/tests/test_csrf.py @@ -1,5 +1,9 @@ -from django.test import Client, SimpleTestCase, override_settings +from django.template import TemplateDoesNotExist +from django.test import ( + Client, RequestFactory, SimpleTestCase, override_settings, +) from django.utils.translation import override +from django.views.csrf import CSRF_FAILURE_TEMPLATE_NAME, csrf_failure @override_settings(ROOT_URLCONF="view_tests.urls") @@ -70,3 +74,29 @@ class CsrfViewTests(SimpleTestCase): """ response = self.client.post('/') self.assertContains(response, "Forbidden", status_code=403) + + @override_settings(TEMPLATES=[{ + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'OPTIONS': { + 'loaders': [ + ('django.template.loaders.locmem.Loader', { + CSRF_FAILURE_TEMPLATE_NAME: 'Test template for CSRF failure' + }), + ], + }, + }]) + def test_custom_template(self): + """ + A custom CSRF_FAILURE_TEMPLATE_NAME is used. + """ + response = self.client.post('/') + self.assertContains(response, "Test template for CSRF failure", status_code=403) + + def test_custom_template_does_not_exist(self): + """ + An exception is raised if a nonexistent template is supplied. + """ + factory = RequestFactory() + request = factory.post('/') + with self.assertRaises(TemplateDoesNotExist): + csrf_failure(request, template_name="nonexistent.html") |
