Moved cache tests into syntax_tests/test_cache.py.
This commit is contained in:
parent
250a3d1993
commit
f6d087b628
|
@ -1,6 +1,6 @@
|
|||
from django.core.cache import cache
|
||||
from django.template import TemplateSyntaxError
|
||||
from django.test import SimpleTestCase
|
||||
from django.template import Context, Template, TemplateSyntaxError
|
||||
from django.test import SimpleTestCase, override_settings
|
||||
|
||||
from ..utils import setup
|
||||
|
||||
|
@ -115,3 +115,47 @@ class CacheTagTests(SimpleTestCase):
|
|||
"""
|
||||
output = self.engine.render_to_string('cache18')
|
||||
self.assertEqual(output, 'cache18')
|
||||
|
||||
|
||||
class CacheTests(SimpleTestCase):
|
||||
|
||||
def test_cache_regression_20130(self):
|
||||
t = Template('{% load cache %}{% cache 1 regression_20130 %}foo{% endcache %}')
|
||||
cachenode = t.nodelist[1]
|
||||
self.assertEqual(cachenode.fragment_name, 'regression_20130')
|
||||
|
||||
@override_settings(CACHES={
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': 'default',
|
||||
},
|
||||
'template_fragments': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': 'fragments',
|
||||
},
|
||||
})
|
||||
def test_cache_fragment_cache(self):
|
||||
"""
|
||||
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 %}')
|
||||
|
||||
ctx = Context()
|
||||
o1 = t1.render(ctx)
|
||||
o2 = t2.render(ctx)
|
||||
|
||||
self.assertEqual(o1, 'foo')
|
||||
self.assertEqual(o2, 'bar')
|
||||
|
||||
def test_cache_missing_backend(self):
|
||||
"""
|
||||
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 %}')
|
||||
|
||||
ctx = Context()
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
t.render(ctx)
|
||||
|
|
|
@ -103,47 +103,6 @@ class TemplateRegressionTests(SimpleTestCase):
|
|||
output1 = template.render(Context({'foo': range(3), 'get_value': lambda: next(gen1)}))
|
||||
self.assertEqual(output1, '[0,1,2,3]', 'Expected [0,1,2,3] in first template, got {}'.format(output1))
|
||||
|
||||
def test_cache_regression_20130(self):
|
||||
t = Template('{% load cache %}{% cache 1 regression_20130 %}foo{% endcache %}')
|
||||
cachenode = t.nodelist[1]
|
||||
self.assertEqual(cachenode.fragment_name, 'regression_20130')
|
||||
|
||||
@override_settings(CACHES={
|
||||
'default': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': 'default',
|
||||
},
|
||||
'template_fragments': {
|
||||
'BACKEND': 'django.core.cache.backends.locmem.LocMemCache',
|
||||
'LOCATION': 'fragments',
|
||||
},
|
||||
})
|
||||
def test_cache_fragment_cache(self):
|
||||
"""
|
||||
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 %}')
|
||||
|
||||
ctx = Context()
|
||||
o1 = t1.render(ctx)
|
||||
o2 = t2.render(ctx)
|
||||
|
||||
self.assertEqual(o1, 'foo')
|
||||
self.assertEqual(o2, 'bar')
|
||||
|
||||
def test_cache_missing_backend(self):
|
||||
"""
|
||||
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 %}')
|
||||
|
||||
ctx = Context()
|
||||
with self.assertRaises(TemplateSyntaxError):
|
||||
t.render(ctx)
|
||||
|
||||
def test_ifchanged_render_once(self):
|
||||
""" Test for ticket #19890. The content of ifchanged template tag was
|
||||
rendered twice."""
|
||||
|
|
Loading…
Reference in New Issue