mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-05-12 09:13:14 +00:00
Merge branch 'feature/streamfield' of github.com:torchbox/wagtail into feature/streamfield
This commit is contained in:
commit
c5ee808d15
2 changed files with 30 additions and 0 deletions
13
wagtail/wagtailembeds/blocks.py
Normal file
13
wagtail/wagtailembeds/blocks.py
Normal 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)
|
||||
|
|
@ -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)
|
||||
|
|
|
|||
Loading…
Reference in a new issue