summaryrefslogtreecommitdiff
path: root/tests/template_tests/syntax_tests/test_include.py
diff options
context:
space:
mode:
authorJon Dufresne <jon.dufresne@gmail.com>2016-09-08 18:24:22 -0700
committerGitHub <noreply@github.com>2016-09-08 18:24:22 -0700
commit331ca5391eb64cbac3a001209257beb93522d587 (patch)
treee6dcdf38907001da099892c79cc17a23d9f223f3 /tests/template_tests/syntax_tests/test_include.py
parent7ca3b391b611eb710c4c1d613e2f672591097a00 (diff)
Fixed #27175 -- Deprecated silencing exceptions from the {% include %} template tag.
Thanks Tim Graham for the review.
Diffstat (limited to 'tests/template_tests/syntax_tests/test_include.py')
-rw-r--r--tests/template_tests/syntax_tests/test_include.py30
1 files changed, 24 insertions, 6 deletions
diff --git a/tests/template_tests/syntax_tests/test_include.py b/tests/template_tests/syntax_tests/test_include.py
index fc1554a17e..ebf3e8e7ab 100644
--- a/tests/template_tests/syntax_tests/test_include.py
+++ b/tests/template_tests/syntax_tests/test_include.py
@@ -1,7 +1,10 @@
+import warnings
+
from django.template import (
Context, Engine, TemplateDoesNotExist, TemplateSyntaxError,
)
-from django.test import SimpleTestCase
+from django.test import SimpleTestCase, ignore_warnings
+from django.utils.deprecation import RemovedInDjango21Warning
from ..utils import setup
from .test_basic import basic_templates
@@ -41,9 +44,20 @@ class IncludeTagTests(SimpleTestCase):
with self.assertRaises(TemplateDoesNotExist):
template.render(Context({}))
else:
- output = template.render(Context({}))
+ with warnings.catch_warnings(record=True) as warns:
+ warnings.simplefilter('always')
+ output = template.render(Context({}))
+
self.assertEqual(output, "ab")
+ self.assertEqual(len(warns), 1)
+ self.assertEqual(
+ str(warns[0].message),
+ "Rendering {% include 'include04' %} raised "
+ "TemplateDoesNotExist. In Django 2.1, this exception will be "
+ "raised rather than silenced and rendered as an empty string.",
+ )
+
@setup({
'include 05': 'template with a space',
'include06': '{% include "include 05"%}',
@@ -169,7 +183,8 @@ class IncludeTagTests(SimpleTestCase):
with self.assertRaises(RuntimeError):
template.render(Context())
else:
- self.assertEqual(template.render(Context()), '')
+ with ignore_warnings(category=RemovedInDjango21Warning):
+ self.assertEqual(template.render(Context()), '')
@setup({'include-error08': '{% include "include-fail2" %}'}, include_fail_templates)
def test_include_error08(self):
@@ -179,7 +194,8 @@ class IncludeTagTests(SimpleTestCase):
with self.assertRaises(TemplateSyntaxError):
template.render(Context())
else:
- self.assertEqual(template.render(Context()), '')
+ with ignore_warnings(category=RemovedInDjango21Warning):
+ self.assertEqual(template.render(Context()), '')
@setup({'include-error09': '{% include failed_include %}'}, include_fail_templates)
def test_include_error09(self):
@@ -190,7 +206,8 @@ class IncludeTagTests(SimpleTestCase):
with self.assertRaises(RuntimeError):
template.render(context)
else:
- self.assertEqual(template.render(context), '')
+ with ignore_warnings(category=RemovedInDjango21Warning):
+ self.assertEqual(template.render(context), '')
@setup({'include-error10': '{% include failed_include %}'}, include_fail_templates)
def test_include_error10(self):
@@ -201,7 +218,8 @@ class IncludeTagTests(SimpleTestCase):
with self.assertRaises(TemplateSyntaxError):
template.render(context)
else:
- self.assertEqual(template.render(context), '')
+ with ignore_warnings(category=RemovedInDjango21Warning):
+ self.assertEqual(template.render(context), '')
class IncludeTests(SimpleTestCase):