当前位置: 首页>>代码示例>>Python>>正文


Python SnippetTemplateFactory.render方法代码示例

本文整理汇总了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)
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:18,代码来源:test_models.py

示例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)
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:19,代码来源:test_models.py

示例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>')
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:6,代码来源:test_models.py

示例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>')
开发者ID:hoosteeno,项目名称:snippets-service,代码行数:5,代码来源:test_models.py


注:本文中的snippets.base.tests.SnippetTemplateFactory.render方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。