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,5 +1,5 @@
from django.core.cache import cache
from django.template import Context, Template, TemplateSyntaxError
from django.template import Context, Engine, TemplateSyntaxError
from django.test import SimpleTestCase, override_settings
from ..utils import setup
@@ -119,8 +119,13 @@ class CacheTagTests(SimpleTestCase):
class CacheTests(SimpleTestCase):
@classmethod
def setUpClass(cls):
cls.engine = Engine()
super(CacheTests, cls).setUpClass()
def test_cache_regression_20130(self):
t = Template('{% load cache %}{% cache 1 regression_20130 %}foo{% endcache %}')
t = self.engine.from_string('{% load cache %}{% cache 1 regression_20130 %}foo{% endcache %}')
cachenode = t.nodelist[1]
self.assertEqual(cachenode.fragment_name, 'regression_20130')
@@ -139,8 +144,8 @@ class CacheTests(SimpleTestCase):
When a cache called "template_fragments" is present, the cache tag
will use it in preference to 'default'
"""
t1 = Template('{% load cache %}{% cache 1 fragment %}foo{% endcache %}')
t2 = Template('{% load cache %}{% cache 1 fragment using="default" %}bar{% endcache %}')
t1 = self.engine.from_string('{% load cache %}{% cache 1 fragment %}foo{% endcache %}')
t2 = self.engine.from_string('{% load cache %}{% cache 1 fragment using="default" %}bar{% endcache %}')
ctx = Context()
o1 = t1.render(ctx)
@@ -154,7 +159,7 @@ class CacheTests(SimpleTestCase):
When a cache that doesn't exist is specified, the cache tag will
raise a TemplateSyntaxError
'"""
t = Template('{% load cache %}{% cache 1 backend using="unknown" %}bar{% endcache %}')
t = self.engine.from_string('{% load cache %}{% cache 1 backend using="unknown" %}bar{% endcache %}')
ctx = Context()
with self.assertRaises(TemplateSyntaxError):