2014-12-07 08:43:10 +00:00
|
|
|
from django.template import TemplateDoesNotExist, TemplateSyntaxError
|
2014-12-03 20:36:17 +00:00
|
|
|
from django.test import SimpleTestCase
|
2014-11-12 01:32:44 +00:00
|
|
|
|
2014-12-07 08:43:10 +00:00
|
|
|
from ..utils import setup
|
2015-01-28 12:35:27 +00:00
|
|
|
from .test_extends import inheritance_templates
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
|
2014-12-03 20:36:17 +00:00
|
|
|
class ExceptionsTests(SimpleTestCase):
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
@setup({'exception01': "{% extends 'nonexistent' %}"})
|
|
|
|
def test_exception01(self):
|
|
|
|
"""
|
|
|
|
Raise exception for invalid template name
|
|
|
|
"""
|
|
|
|
with self.assertRaises(TemplateDoesNotExist):
|
2014-12-07 08:43:10 +00:00
|
|
|
self.engine.render_to_string('exception01')
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
@setup({'exception02': '{% extends nonexistent %}'})
|
|
|
|
def test_exception02(self):
|
|
|
|
"""
|
|
|
|
Raise exception for invalid variable template name
|
|
|
|
"""
|
2014-12-07 08:43:10 +00:00
|
|
|
if self.engine.string_if_invalid:
|
2014-11-12 01:32:44 +00:00
|
|
|
with self.assertRaises(TemplateDoesNotExist):
|
2014-12-07 08:43:10 +00:00
|
|
|
self.engine.render_to_string('exception02')
|
2014-11-12 01:32:44 +00:00
|
|
|
else:
|
|
|
|
with self.assertRaises(TemplateSyntaxError):
|
2014-12-07 08:43:10 +00:00
|
|
|
self.engine.render_to_string('exception02')
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
@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):
|
2014-12-07 08:43:10 +00:00
|
|
|
self.engine.get_template('exception03')
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
@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):
|
2014-12-07 08:43:10 +00:00
|
|
|
self.engine.get_template('exception04')
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
@setup({'exception05': '{% block first %}{{ block.super }}{% endblock %}'})
|
|
|
|
def test_exception05(self):
|
|
|
|
"""
|
|
|
|
Raise exception for block.super used in base template
|
|
|
|
"""
|
|
|
|
with self.assertRaises(TemplateSyntaxError):
|
2014-12-07 08:43:10 +00:00
|
|
|
self.engine.render_to_string('exception05')
|