summaryrefslogtreecommitdiff
path: root/tests/template_tests/syntax_tests/test_exceptions.py
diff options
context:
space:
mode:
authorPreston Timmons <prestontimmons@gmail.com>2014-11-11 19:32:44 -0600
committerTim Graham <timograham@gmail.com>2014-12-02 19:18:35 -0500
commitb872134bfc14f6322bd1e4b0a08bf5bfd2c43a52 (patch)
treef82fc6be418adeb1e7ff36728f82008770066999 /tests/template_tests/syntax_tests/test_exceptions.py
parent4a4ad27712b44cebada1bdaebd082cf82df74610 (diff)
Fixed #23768 -- Rewrote template tests as unit tests.
Diffstat (limited to 'tests/template_tests/syntax_tests/test_exceptions.py')
-rw-r--r--tests/template_tests/syntax_tests/test_exceptions.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/tests/template_tests/syntax_tests/test_exceptions.py b/tests/template_tests/syntax_tests/test_exceptions.py
new file mode 100644
index 0000000000..923ca4a205
--- /dev/null
+++ b/tests/template_tests/syntax_tests/test_exceptions.py
@@ -0,0 +1,61 @@
+from django.conf import settings
+from django.template.base import TemplateDoesNotExist, TemplateSyntaxError
+from django.template.loader import get_template
+from django.test import TestCase
+
+from .test_extends import inheritance_templates
+from .utils import render, setup
+
+
+class ExceptionsTests(TestCase):
+
+ @setup({'exception01': "{% extends 'nonexistent' %}"})
+ def test_exception01(self):
+ """
+ Raise exception for invalid template name
+ """
+ with self.assertRaises(TemplateDoesNotExist):
+ render('exception01')
+
+ @setup({'exception02': '{% extends nonexistent %}'})
+ def test_exception02(self):
+ """
+ Raise exception for invalid variable template name
+ """
+ if settings.TEMPLATE_STRING_IF_INVALID:
+ with self.assertRaises(TemplateDoesNotExist):
+ render('exception02')
+ else:
+ with self.assertRaises(TemplateSyntaxError):
+ render('exception02')
+
+ @setup(
+ {'exception03': "{% extends 'inheritance01' %}"
+ "{% block first %}2{% endblock %}{% extends 'inheritance16' %}"},
+ inheritance_templates,
+ )
+ def test_exception03(self):
+ """
+ Raise exception for extra {% extends %} tags
+ """
+ with self.assertRaises(TemplateSyntaxError):
+ get_template('exception03')
+
+ @setup(
+ {'exception04': "{% extends 'inheritance17' %}{% block first %}{% echo 400 %}5678{% endblock %}"},
+ inheritance_templates,
+ )
+ def test_exception04(self):
+ """
+ Raise exception for custom tags used in child with {% load %} tag in parent, not in child
+ """
+ with self.assertRaises(TemplateSyntaxError):
+ get_template('exception04')
+
+ @setup({'exception05': '{% block first %}{{ block.super }}{% endblock %}'})
+ def test_exception05(self):
+ """
+ Raise exception for block.super used in base template
+ """
+ with self.assertRaises(TemplateSyntaxError):
+ render('exception05')