Added EmbedBlock

This commit is contained in:
Karl Hobley 2015-02-06 16:48:29 +00:00
parent 7fd561554a
commit 444328601f
2 changed files with 30 additions and 0 deletions

View file

@ -0,0 +1,13 @@
from django import forms
from wagtail.wagtailadmin import blocks
from wagtail.wagtailembeds.format import embed_to_frontend_html
class EmbedBlock(blocks.FieldBlock):
def __init__(self, **kwargs):
super(EmbedBlock, self).__init__(forms.URLField(), **kwargs)
def render_basic(self, value):
return embed_to_frontend_html(value)

View file

@ -25,6 +25,8 @@ from wagtail.wagtailembeds.embeds import (
oembed as wagtail_oembed,
)
from wagtail.wagtailembeds.templatetags.wagtailembeds_tags import embed as embed_filter
from wagtail.wagtailembeds.blocks import EmbedBlock
from wagtail.wagtailembeds.models import Embed
class TestEmbeds(TestCase):
@ -303,3 +305,18 @@ class TestEmbedFilter(TestCase):
context = template.Context()
result = temp.render(context)
self.assertEqual(result, '')
class TestEmbedBlock(TestCase):
@patch('wagtail.wagtailembeds.format.get_embed')
def test_render(self, get_embed):
get_embed.return_value = Embed(html='<h1>Hello world!</h1>')
block = EmbedBlock()
html = block.render('http://www.example.com')
# Check that get_embed was called correctly
get_embed.assert_any_call('http://www.example.com')
# Check that the embed was in the returned HTML
self.assertIn('<h1>Hello world!</h1', html)