From 18a4722b51f02a5e91e269e19abd82669995bd10 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 6 Feb 2015 12:59:01 +0000 Subject: [PATCH 1/2] Tests for html_declarations --- wagtail/wagtailadmin/tests/test_blocks.py | 89 ++++++++++++++++++++++- 1 file changed, 88 insertions(+), 1 deletion(-) diff --git a/wagtail/wagtailadmin/tests/test_blocks.py b/wagtail/wagtailadmin/tests/test_blocks.py index 2de2aeb5d..759c47dc6 100644 --- a/wagtail/wagtailadmin/tests/test_blocks.py +++ b/wagtail/wagtailadmin/tests/test_blocks.py @@ -201,6 +201,20 @@ class TestStructBlock(unittest.TestCase): self.assertIn('
', html) self.assertIn('', html) + def test_render_form_uses_default_value(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField(), default="Torchbox") + link = blocks.FieldBlock(forms.URLField(), default="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): @@ -261,7 +275,7 @@ class TestListBlock(unittest.TestCase): html = self.render_form() self.assertIn('', html) - self.assertIn('', html) + self.assertIn('', html) def test_render_form_values(self): html = self.render_form() @@ -271,6 +285,28 @@ class TestListBlock(unittest.TestCase): self.assertIn('', html) self.assertIn('', html) + def test_html_declarations(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField()) + link = blocks.FieldBlock(forms.URLField()) + + block = blocks.ListBlock(LinkBlock) + html = block.html_declarations() + + self.assertIn('', html) + self.assertIn('', html) + + def test_html_declarations_uses_default(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField(), default="Github") + link = blocks.FieldBlock(forms.URLField(), default="http://www.github.com") + + block = blocks.ListBlock(LinkBlock) + html = block.html_declarations() + + self.assertIn('', html) + self.assertIn('', html) + class TestStreamBlock(unittest.TestCase): def test_initialisation(self): @@ -426,3 +462,54 @@ class TestStreamBlock(unittest.TestCase): self.assertIn('', html) self.assertIn('', html) self.assertIn('', html) + + def test_render_form_uses_default_value(self): + class ArticleBlock(blocks.StreamBlock): + heading = blocks.FieldBlock(forms.CharField(), ) + paragraph = blocks.FieldBlock(forms.CharField()) + + default = [ + { + 'type': 'heading', + 'value': "My title", + } + ] + + block = ArticleBlock() + value = block.to_python([ + { + 'type': 'heading', + 'value': "My title", + }, + { + 'type': 'paragraph', + 'value': 'My first paragraph', + }, + { + 'type': 'paragraph', + 'value': 'My second paragraph', + }, + ]) + return block.render_form(value, prefix='myarticle') + + def test_html_declarations(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField()) + link = blocks.FieldBlock(forms.URLField()) + + block = blocks.ListBlock(LinkBlock) + html = block.html_declarations() + + self.assertIn('', html) + self.assertIn('', html) + + def test_html_declarations_uses_default(self): + class LinkBlock(blocks.StructBlock): + title = blocks.FieldBlock(forms.CharField(), default="Github") + link = blocks.FieldBlock(forms.URLField(), default="http://www.github.com") + + block = blocks.ListBlock(LinkBlock) + html = block.html_declarations() + + self.assertIn('', html) + self.assertIn('', html) From 446a9868dc95fd8cec8478e4dcd0e470be352637 Mon Sep 17 00:00:00 2001 From: Karl Hobley Date: Fri, 6 Feb 2015 13:04:19 +0000 Subject: [PATCH 2/2] Removed some stray code --- wagtail/wagtailadmin/tests/test_blocks.py | 29 ----------------------- 1 file changed, 29 deletions(-) diff --git a/wagtail/wagtailadmin/tests/test_blocks.py b/wagtail/wagtailadmin/tests/test_blocks.py index 759c47dc6..c4a430321 100644 --- a/wagtail/wagtailadmin/tests/test_blocks.py +++ b/wagtail/wagtailadmin/tests/test_blocks.py @@ -463,35 +463,6 @@ class TestStreamBlock(unittest.TestCase): self.assertIn('', html) self.assertIn('', html) - def test_render_form_uses_default_value(self): - class ArticleBlock(blocks.StreamBlock): - heading = blocks.FieldBlock(forms.CharField(), ) - paragraph = blocks.FieldBlock(forms.CharField()) - - default = [ - { - 'type': 'heading', - 'value': "My title", - } - ] - - block = ArticleBlock() - value = block.to_python([ - { - 'type': 'heading', - 'value': "My title", - }, - { - 'type': 'paragraph', - 'value': 'My first paragraph', - }, - { - 'type': 'paragraph', - 'value': 'My second paragraph', - }, - ]) - return block.render_form(value, prefix='myarticle') - def test_html_declarations(self): class LinkBlock(blocks.StructBlock): title = blocks.FieldBlock(forms.CharField())