From a6c207a1f68ba73aacc4ce03e3ee9a087ba51ce6 Mon Sep 17 00:00:00 2001 From: Matt Westcott Date: Fri, 13 Feb 2015 20:33:03 +0000 Subject: [PATCH] Fix another place where we make a set() of block instances (and add the unit tests that would have caught it) --- wagtail/wagtailcore/blocks.py | 6 +-- wagtail/wagtailcore/tests/test_blocks.py | 61 ++++++++++++++++++++++++ 2 files changed, 64 insertions(+), 3 deletions(-) diff --git a/wagtail/wagtailcore/blocks.py b/wagtail/wagtailcore/blocks.py index ea81e30bf..296eb024f 100644 --- a/wagtail/wagtailcore/blocks.py +++ b/wagtail/wagtailcore/blocks.py @@ -81,12 +81,12 @@ class Block(six.with_metaclass(BaseBlock, object)): def all_blocks(self): """ - Return a set consisting of self and all block objects that are direct or indirect dependencies + Return a list consisting of self and all block objects that are direct or indirect dependencies of this block """ - result = set([self]) + result = [self] for dep in self.dependencies: - result |= dep.all_blocks() + result.extend(dep.all_blocks()) return result def all_media(self): diff --git a/wagtail/wagtailcore/tests/test_blocks.py b/wagtail/wagtailcore/tests/test_blocks.py index 9f2bf7179..453272d40 100644 --- a/wagtail/wagtailcore/tests/test_blocks.py +++ b/wagtail/wagtailcore/tests/test_blocks.py @@ -239,6 +239,29 @@ class TestStructBlock(unittest.TestCase): self.assertIn('', html) self.assertIn('', html) + def test_media_inheritance(self): + class ScriptedCharBlock(blocks.CharBlock): + media = forms.Media(js=['scripted_char_block.js']) + + class LinkBlock(blocks.StructBlock): + title = ScriptedCharBlock(default="Torchbox") + link = blocks.URLBlock(default="http://www.torchbox.com") + + block = LinkBlock() + self.assertIn('scripted_char_block.js', ''.join(block.all_media().render_js())) + + def test_html_declaration_inheritance(self): + class CharBlockWithDeclarations(blocks.CharBlock): + def html_declarations(self): + return '' + + class LinkBlock(blocks.StructBlock): + title = CharBlockWithDeclarations(default="Torchbox") + link = blocks.URLBlock(default="http://www.torchbox.com") + + block = LinkBlock() + self.assertIn('', block.all_html_declarations()) + class TestListBlock(unittest.TestCase): def test_initialise_with_class(self): @@ -360,6 +383,21 @@ class TestListBlock(unittest.TestCase): self.assertIn('', html) self.assertIn('', html) + def test_media_inheritance(self): + class ScriptedCharBlock(blocks.CharBlock): + media = forms.Media(js=['scripted_char_block.js']) + + block = blocks.ListBlock(ScriptedCharBlock()) + self.assertIn('scripted_char_block.js', ''.join(block.all_media().render_js())) + + def test_html_declaration_inheritance(self): + class CharBlockWithDeclarations(blocks.CharBlock): + def html_declarations(self): + return '' + + block = blocks.ListBlock(CharBlockWithDeclarations()) + self.assertIn('', block.all_html_declarations()) + class TestStreamBlock(unittest.TestCase): def test_initialisation(self): @@ -544,6 +582,29 @@ class TestStreamBlock(unittest.TestCase): self.assertIn('', html) self.assertIn('', html) + def test_media_inheritance(self): + class ScriptedCharBlock(blocks.CharBlock): + media = forms.Media(js=['scripted_char_block.js']) + + class ArticleBlock(blocks.StreamBlock): + heading = ScriptedCharBlock() + paragraph = blocks.CharBlock() + + block = ArticleBlock() + self.assertIn('scripted_char_block.js', ''.join(block.all_media().render_js())) + + def test_html_declaration_inheritance(self): + class CharBlockWithDeclarations(blocks.CharBlock): + def html_declarations(self): + return '' + + class ArticleBlock(blocks.StructBlock): + heading = CharBlockWithDeclarations(default="Torchbox") + paragraph = blocks.CharBlock() + + block = ArticleBlock() + self.assertIn('', block.all_html_declarations()) + def test_ordering_in_form_submission(self): class ArticleBlock(blocks.StreamBlock): heading = blocks.CharBlock()