diff --git a/wagtail/wagtailadmin/tests/test_blocks.py b/wagtail/wagtailadmin/tests/test_blocks.py index 2f6acb5da..2de2aeb5d 100644 --- a/wagtail/wagtailadmin/tests/test_blocks.py +++ b/wagtail/wagtailadmin/tests/test_blocks.py @@ -113,8 +113,8 @@ class TestStructBlock(unittest.TestCase): def test_render(self): class LinkBlock(blocks.StructBlock): - title = blocks.FieldBlock(forms.CharField(), label="Title") - link = blocks.FieldBlock(forms.URLField(), label="Link") + title = blocks.FieldBlock(forms.CharField()) + link = blocks.FieldBlock(forms.URLField()) block = LinkBlock() html = block.render({ @@ -127,6 +127,27 @@ class TestStructBlock(unittest.TestCase): self.assertIn('
link
', html) self.assertIn('
http://www.wagtail.io
', html) + @unittest.expectedFailure + def test_render_unknown_field(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField()) + link = blocks.FieldBlock(forms.URLField()) + + block = LinkBlock() + html = block.render({ + 'title': "Wagtail site", + 'link': 'http://www.wagtail.io', + 'image': 10, + }) + + self.assertIn('
title
', html) + self.assertIn('
Wagtail site
', html) + self.assertIn('
link
', html) + self.assertIn('
http://www.wagtail.io
', html) + + # Don't render the extra item + self.assertNotIn('
image
', html) + def test_render_form(self): class LinkBlock(blocks.StructBlock): title = blocks.FieldBlock(forms.CharField()) @@ -144,6 +165,42 @@ class TestStructBlock(unittest.TestCase): self.assertIn('
', html) self.assertIn('', html) + def test_render_form_unknown_field(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField()) + link = blocks.FieldBlock(forms.URLField()) + + block = LinkBlock() + html = block.render_form({ + 'title': "Wagtail site", + 'link': 'http://www.wagtail.io', + 'image': 10, + }, prefix='mylink') + + self.assertIn('
', html) + self.assertIn('
', html) + self.assertIn('', html) + self.assertIn('
', html) + self.assertIn('', html) + + # Don't render the extra field + self.assertNotIn('mylink-image', html) + + @unittest.expectedFailure + def test_render_form_uses_initial_values(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField(initial="Torchbox")) + link = blocks.FieldBlock(forms.URLField(initial="http://www.torchbox.com")) + + block = LinkBlock() + html = block.render_form({}, prefix='mylink') + + self.assertIn('
', html) + self.assertIn('
', html) + self.assertIn('', html) + self.assertIn('
', html) + self.assertIn('', html) + class TestListBlock(unittest.TestCase): def test_initialise_with_class(self):