2014-12-07 08:43:10 +00:00
|
|
|
from django.template import 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
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
|
2014-12-03 20:36:17 +00:00
|
|
|
class NamedEndblockTests(SimpleTestCase):
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
@setup({'namedendblocks01': '1{% block first %}_{% block second %}'
|
|
|
|
'2{% endblock second %}_{% endblock first %}3'})
|
|
|
|
def test_namedendblocks01(self):
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string('namedendblocks01')
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, '1_2_3')
|
|
|
|
|
|
|
|
# Unbalanced blocks
|
|
|
|
@setup({'namedendblocks02': '1{% block first %}_{% block second %}'
|
|
|
|
'2{% endblock first %}_{% endblock second %}3'})
|
|
|
|
def test_namedendblocks02(self):
|
|
|
|
with self.assertRaises(TemplateSyntaxError):
|
2014-12-07 08:43:10 +00:00
|
|
|
self.engine.get_template('namedendblocks02')
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
@setup({'namedendblocks03': '1{% block first %}_{% block second %}'
|
|
|
|
'2{% endblock %}_{% endblock second %}3'})
|
|
|
|
def test_namedendblocks03(self):
|
|
|
|
with self.assertRaises(TemplateSyntaxError):
|
2014-12-07 08:43:10 +00:00
|
|
|
self.engine.get_template('namedendblocks03')
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
@setup({'namedendblocks04': '1{% block first %}_{% block second %}'
|
|
|
|
'2{% endblock second %}_{% endblock third %}3'})
|
|
|
|
def test_namedendblocks04(self):
|
|
|
|
with self.assertRaises(TemplateSyntaxError):
|
2014-12-07 08:43:10 +00:00
|
|
|
self.engine.get_template('namedendblocks04')
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
@setup({'namedendblocks05': '1{% block first %}_{% block second %}2{% endblock first %}'})
|
|
|
|
def test_namedendblocks05(self):
|
|
|
|
with self.assertRaises(TemplateSyntaxError):
|
2014-12-07 08:43:10 +00:00
|
|
|
self.engine.get_template('namedendblocks05')
|
2014-11-12 01:32:44 +00:00
|
|
|
|
|
|
|
# Mixed named and unnamed endblocks
|
|
|
|
@setup({'namedendblocks06': '1{% block first %}_{% block second %}'
|
|
|
|
'2{% endblock %}_{% endblock first %}3'})
|
|
|
|
def test_namedendblocks06(self):
|
|
|
|
"""
|
|
|
|
Mixed named and unnamed endblocks
|
|
|
|
"""
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string('namedendblocks06')
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, '1_2_3')
|
|
|
|
|
|
|
|
@setup({'namedendblocks07': '1{% block first %}_{% block second %}'
|
|
|
|
'2{% endblock second %}_{% endblock %}3'})
|
|
|
|
def test_namedendblocks07(self):
|
2014-12-07 08:43:10 +00:00
|
|
|
output = self.engine.render_to_string('namedendblocks07')
|
2014-11-12 01:32:44 +00:00
|
|
|
self.assertEqual(output, '1_2_3')
|