1
0
mirror of https://github.com/django/django.git synced 2025-10-24 06:06:09 +00:00

Updated template tests to create their own engine.

This continues work to treat Django templates as a library.
This commit is contained in:
Preston Timmons
2015-04-11 19:41:45 -04:00
parent d84f01ff08
commit fb267a1d85
11 changed files with 153 additions and 171 deletions

View File

@@ -1,4 +1,4 @@
from django.template import Context, Template
from django.template import Context, Engine
from django.test import SimpleTestCase
from ..utils import setup
@@ -157,11 +157,19 @@ class IfChangedTagTests(SimpleTestCase):
class IfChangedTests(SimpleTestCase):
@classmethod
def setUpClass(cls):
cls.engine = Engine()
super(IfChangedTests, cls).setUpClass()
def test_ifchanged_concurrency(self):
"""
#15849 -- ifchanged should be thread-safe.
"""
template = Template('[0{% for x in foo %},{% with var=get_value %}{% ifchanged %}{{ var }}{% endifchanged %}{% endwith %}{% endfor %}]')
template = self.engine.from_string(
'[0{% for x in foo %},{% with var=get_value %}{% ifchanged %}'
'{{ var }}{% endifchanged %}{% endwith %}{% endfor %}]'
)
# Using generator to mimic concurrency.
# The generator is not passed to the 'for' loop, because it does a list(values)
@@ -184,6 +192,6 @@ class IfChangedTests(SimpleTestCase):
"""
#19890. The content of ifchanged template tag was rendered twice.
"""
template = Template('{% ifchanged %}{% cycle "1st time" "2nd time" %}{% endifchanged %}')
template = self.engine.from_string('{% ifchanged %}{% cycle "1st time" "2nd time" %}{% endifchanged %}')
output = template.render(Context({}))
self.assertEqual(output, '1st time')