aboutsummaryrefslogtreecommitdiffstats
path: root/test/test_cache.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2012-01-16 13:02:51 -0500
committerMike Bayer <mike_mp@zzzcomputing.com>2012-01-16 13:02:51 -0500
commit2879f8bcc02d75d256bf7db97251a8708ef2466e (patch)
treeb64ad6ab41312ce66147818802e218a8057e50e7 /test/test_cache.py
parent3266c0160d9103703400123b81a713db21ccd5be (diff)
downloadexternal_python_mako-2879f8bcc02d75d256bf7db97251a8708ef2466e.tar.gz
external_python_mako-2879f8bcc02d75d256bf7db97251a8708ef2466e.tar.bz2
external_python_mako-2879f8bcc02d75d256bf7db97251a8708ef2466e.zip
- [feature/bug] Can now refer to context variables
within extra arguments to <%block>, <%def>, i.e. <%block name="foo" cache_key="${somekey}">. Filters can also be used in this way, i.e. <%def name="foo()" filter="myfilter"> then template.render(myfilter=some_callable) [ticket:180]
Diffstat (limited to 'test/test_cache.py')
-rw-r--r--test/test_cache.py31
1 files changed, 31 insertions, 0 deletions
diff --git a/test/test_cache.py b/test/test_cache.py
index d898b02..1c7b42a 100644
--- a/test/test_cache.py
+++ b/test/test_cache.py
@@ -139,6 +139,37 @@ class CacheTest(TemplateTest):
]
assert m.kwargs == {}
+ def test_dynamic_key_with_context(self):
+ t = Template("""
+ <%block name="foo" cached="True" cache_key="${mykey}">
+ some block
+ </%block>
+ """)
+ m = self._install_mock_cache(t)
+ t.render(mykey="thekey")
+ t.render(mykey="thekey")
+ eq_(
+ result_lines(t.render(mykey="thekey")),
+ ["some block"]
+ )
+ eq_(m.key, "thekey")
+
+ t = Template("""
+ <%def name="foo()" cached="True" cache_key="${mykey}">
+ some def
+ </%def>
+ ${foo()}
+ """)
+ m = self._install_mock_cache(t)
+ t.render(mykey="thekey")
+ t.render(mykey="thekey")
+ eq_(
+ result_lines(t.render(mykey="thekey")),
+ ["some def"]
+ )
+ eq_(m.key, "thekey")
+
+
def test_dynamic_key_with_funcargs(self):
t = Template("""
<%def name="foo(num=5)" cached="True" cache_key="foo_${str(num)}">