diff options
| author | Curtis Maloney <curtis@tinbrain.net> | 2013-10-04 07:36:21 +1000 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2013-10-23 19:27:08 -0400 |
| commit | 8688f03eef9cf5fd763ba35481ddcff933a60c30 (patch) | |
| tree | 2f3e1644eb31beecc4e128e4770b29c6c82fc186 /tests | |
| parent | 4ce5c119b5a6109058500e207333cc6889d78abe (diff) | |
Fixed #20945 -- Allowed cache tag to use a specific cache.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/template_tests/tests.py | 37 |
1 files changed, 36 insertions, 1 deletions
diff --git a/tests/template_tests/tests.py b/tests/template_tests/tests.py index 8c52052811..a7990d0163 100644 --- a/tests/template_tests/tests.py +++ b/tests/template_tests/tests.py @@ -478,6 +478,42 @@ class TemplateRegressionTests(TestCase): 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.assertNotEqual(o1, o2) + + 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.""" @@ -1736,7 +1772,6 @@ class TemplateTests(TransRealMixin, TestCase): # Test whitespace in filter arguments 'cache18': ('{% load cache custom %}{% cache 2|noop:"x y" cache18 %}cache18{% endcache %}', {}, 'cache18'), - ### AUTOESCAPE TAG ############################################## 'autoescape-tag01': ("{% autoescape off %}hello{% endautoescape %}", {}, "hello"), 'autoescape-tag02': ("{% autoescape off %}{{ first }}{% endautoescape %}", {"first": "<b>hello</b>"}, "<b>hello</b>"), |
