make block names work properly when passed as binary strings

This commit is contained in:
Matt Westcott 2015-02-16 12:17:56 +00:00
parent 64d5ffe2b2
commit 342fd7a061
2 changed files with 10 additions and 1 deletions

View file

@ -115,7 +115,7 @@ class Block(six.with_metaclass(BaseBlock, object)):
def set_name(self, name):
self.name = name
if not self.meta.label:
self.label = capfirst(name.replace('_', ' '))
self.label = capfirst(force_text(name).replace('_', ' '))
@property
def media(self):

View file

@ -408,6 +408,15 @@ class TestStreamBlock(unittest.TestCase):
self.assertEqual(list(block.child_blocks.keys()), ['heading', 'paragraph'])
def test_initialisation_with_binary_string_names(self):
# migrations will sometimes write out names as binary strings, just to keep us on our toes
block = blocks.StreamBlock([
(b'heading', blocks.CharBlock()),
(b'paragraph', blocks.CharBlock()),
])
self.assertEqual(list(block.child_blocks.keys()), [b'heading', b'paragraph'])
def test_initialisation_from_subclass(self):
class ArticleBlock(blocks.StreamBlock):
heading = blocks.CharBlock()