本文整理汇总了Python中snippets.base.tests.SnippetTemplateFactory.render方法的典型用法代码示例。如果您正苦于以下问题:Python SnippetTemplateFactory.render方法的具体用法?Python SnippetTemplateFactory.render怎么用?Python SnippetTemplateFactory.render使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类snippets.base.tests.SnippetTemplateFactory
的用法示例。
在下文中一共展示了SnippetTemplateFactory.render方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_render_not_cached
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import render [as 别名]
def test_render_not_cached(self, mock_from_string, mock_sha1):
"""If the template isn't in the cache, add it."""
template = SnippetTemplateFactory(code='asdf')
mock_cache = {}
with patch('snippets.base.models.template_cache', mock_cache):
result = template.render({})
jinja_template = mock_from_string.return_value
cache_key = mock_sha1.return_value.hexdigest.return_value
eq_(mock_cache, {cache_key: jinja_template})
mock_sha1.assert_called_with('asdf')
mock_from_string.assert_called_with('asdf')
jinja_template.render.assert_called_with({'snippet_id': 0})
eq_(result, jinja_template.render.return_value)
示例2: test_render_cached
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import render [as 别名]
def test_render_cached(self, mock_from_string, mock_sha1):
"""
If the template is in the cache, use the cached version instead
of bothering to compile it.
"""
template = SnippetTemplateFactory(code='asdf')
cache_key = mock_sha1.return_value.hexdigest.return_value
jinja_template = Mock()
mock_cache = {cache_key: jinja_template}
with patch('snippets.base.models.template_cache', mock_cache):
result = template.render({})
mock_sha1.assert_called_with('asdf')
ok_(not mock_from_string.called)
jinja_template.render.assert_called_with({'snippet_id': 0})
eq_(result, jinja_template.render.return_value)
示例3: test_render_snippet_id
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import render [as 别名]
def test_render_snippet_id(self):
"""If the template context doesn't have a snippet_id entry, add one set to 0."""
template = SnippetTemplateFactory(code='<p>{{ snippet_id }}</p>')
eq_(template.render({'myvar': 'foo'}), '<p>0</p>')
示例4: test_render
# 需要导入模块: from snippets.base.tests import SnippetTemplateFactory [as 别名]
# 或者: from snippets.base.tests.SnippetTemplateFactory import render [as 别名]
def test_render(self):
template = SnippetTemplateFactory(code='<p>{{myvar}}</p>')
eq_(template.render({'myvar': 'foo'}), '<p>foo</p>')