diff options
| author | Preston Timmons <prestontimmons@gmail.com> | 2015-02-21 13:17:39 -0600 |
|---|---|---|
| committer | Aymeric Augustin <aymeric.augustin@oscaro.com> | 2015-02-24 14:00:02 +0100 |
| commit | f6d087b628a61a7b036cc468328497082031dc8e (patch) | |
| tree | d1ca0bbf46ef636832d563ebbbbd0385403b591a /tests/template_tests/syntax_tests | |
| parent | 250a3d199310a954a95fb1ffa4915f0e51ba1767 (diff) | |
Moved cache tests into syntax_tests/test_cache.py.
Diffstat (limited to 'tests/template_tests/syntax_tests')
| -rw-r--r-- | tests/template_tests/syntax_tests/test_cache.py | 48 |
1 files changed, 46 insertions, 2 deletions
diff --git a/tests/template_tests/syntax_tests/test_cache.py b/tests/template_tests/syntax_tests/test_cache.py index 52ce9b827c..1742b7111c 100644 --- a/tests/template_tests/syntax_tests/test_cache.py +++ b/tests/template_tests/syntax_tests/test_cache.py @@ -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) |
