本文整理汇总了Python中wagtail.wagtailembeds.blocks.EmbedBlock.to_python方法的典型用法代码示例。如果您正苦于以下问题:Python EmbedBlock.to_python方法的具体用法?Python EmbedBlock.to_python怎么用?Python EmbedBlock.to_python使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类wagtail.wagtailembeds.blocks.EmbedBlock
的用法示例。
在下文中一共展示了EmbedBlock.to_python方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_deserialize
# 需要导入模块: from wagtail.wagtailembeds.blocks import EmbedBlock [as 别名]
# 或者: from wagtail.wagtailembeds.blocks.EmbedBlock import to_python [as 别名]
def test_deserialize(self):
"""
Deserialising the JSONish value of an EmbedBlock (a URL) should give us an EmbedValue
for that URL
"""
block = EmbedBlock(required=False)
block_val = block.to_python('http://www.example.com/foo')
self.assertIsInstance(block_val, EmbedValue)
self.assertEqual(block_val.url, 'http://www.example.com/foo')
# empty values should yield None
empty_block_val = block.to_python('')
self.assertEqual(empty_block_val, None)
示例2: test_render
# 需要导入模块: from wagtail.wagtailembeds.blocks import EmbedBlock [as 别名]
# 或者: from wagtail.wagtailembeds.blocks.EmbedBlock import to_python [as 别名]
def test_render(self, get_embed):
get_embed.return_value = Embed(html='<h1>Hello world!</h1>')
block = EmbedBlock()
block_val = block.to_python('http://www.example.com/foo')
temp = template.Template('embed: {{ embed }}')
context = template.Context({'embed': block_val})
result = temp.render(context)
# Check that the embed was in the returned HTML
self.assertIn('<h1>Hello world!</h1>', result)
# Check that get_embed was called correctly
get_embed.assert_any_call('http://www.example.com/foo')