summaryrefslogtreecommitdiff
path: root/tests/view_tests
diff options
context:
space:
mode:
Diffstat (limited to 'tests/view_tests')
-rw-r--r--tests/view_tests/tests/test_debug.py31
-rw-r--r--tests/view_tests/tests/test_defaults.py25
2 files changed, 34 insertions, 22 deletions
diff --git a/tests/view_tests/tests/test_debug.py b/tests/view_tests/tests/test_debug.py
index b9987c72b0..ab04c6622d 100644
--- a/tests/view_tests/tests/test_debug.py
+++ b/tests/view_tests/tests/test_debug.py
@@ -63,21 +63,28 @@ class DebugViewTests(TestCase):
response = self.client.get('/raises400/')
self.assertContains(response, '<div class="context" id="', status_code=400)
+ # Ensure no 403.html template exists to test the default case.
+ @override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ }])
def test_403(self):
- # Ensure no 403.html template exists to test the default case.
- with override_settings(TEMPLATE_LOADERS=[]):
- response = self.client.get('/raises403/')
- self.assertContains(response, '<h1>403 Forbidden</h1>', status_code=403)
+ response = self.client.get('/raises403/')
+ self.assertContains(response, '<h1>403 Forbidden</h1>', status_code=403)
+ # Set up a test 403.html template.
+ @override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'OPTIONS': {
+ 'loaders': [
+ ('django.template.loaders.locmem.Loader', {
+ '403.html': 'This is a test template for a 403 error.',
+ }),
+ ],
+ },
+ }])
def test_403_template(self):
- # Set up a test 403.html template.
- with override_settings(TEMPLATE_LOADERS=[
- ('django.template.loaders.locmem.Loader', {
- '403.html': 'This is a test template for a 403 Forbidden error.',
- })
- ]):
- response = self.client.get('/raises403/')
- self.assertContains(response, 'test template', status_code=403)
+ response = self.client.get('/raises403/')
+ self.assertContains(response, 'test template', status_code=403)
def test_404(self):
response = self.client.get('/raises404/')
diff --git a/tests/view_tests/tests/test_defaults.py b/tests/view_tests/tests/test_defaults.py
index 6a3a495c23..7b95211a5a 100644
--- a/tests/view_tests/tests/test_defaults.py
+++ b/tests/view_tests/tests/test_defaults.py
@@ -35,21 +35,26 @@ class DefaultsTests(TestCase):
response = self.client.get('/server_error/')
self.assertEqual(response.status_code, 500)
+ @override_settings(TEMPLATES=[{
+ 'BACKEND': 'django.template.backends.django.DjangoTemplates',
+ 'OPTIONS': {
+ 'loaders': [
+ ('django.template.loaders.locmem.Loader', {
+ '404.html': 'This is a test template for a 404 error.',
+ '500.html': 'This is a test template for a 500 error.',
+ }),
+ ],
+ },
+ }])
def test_custom_templates(self):
"""
Test that 404.html and 500.html templates are picked by their respective
handler.
"""
- with override_settings(TEMPLATE_LOADERS=[
- ('django.template.loaders.locmem.Loader', {
- '404.html': 'This is a test template for a 404 error.',
- '500.html': 'This is a test template for a 500 error.',
- }),
- ]):
- for code, url in ((404, '/non_existing_url/'), (500, '/server_error/')):
- response = self.client.get(url)
- self.assertContains(response, "test template for a %d error" % code,
- status_code=code)
+ for code, url in ((404, '/non_existing_url/'), (500, '/server_error/')):
+ response = self.client.get(url)
+ self.assertContains(response, "test template for a %d error" % code,
+ status_code=code)
def test_get_absolute_url_attributes(self):
"A model can set attributes on the get_absolute_url method"