Add test for failing StreamBlock validation

This commit is contained in:
Tim Heap 2016-01-04 15:24:29 +11:00 committed by Matt Westcott
parent 968676c5bb
commit b7fd5de8ec

View file

@ -1239,6 +1239,38 @@ class TestStreamBlock(unittest.TestCase):
html
)
def test_validation_errors(self):
class ValidatedBlock(blocks.StreamBlock):
char = blocks.CharBlock()
url = blocks.URLBlock()
block = ValidatedBlock()
value = [
blocks.BoundBlock(
block=block.child_blocks['char'],
value='',
),
blocks.BoundBlock(
block=block.child_blocks['char'],
value='foo',
),
blocks.BoundBlock(
block=block.child_blocks['url'],
value='http://example.com/',
),
blocks.BoundBlock(
block=block.child_blocks['url'],
value='not a url',
),
]
with self.assertRaises(ValidationError) as catcher:
block.clean(value)
self.assertEqual(catcher.exception.params, {
0: ['This field is required.'],
3: ['Enter a valid URL.'],
})
def test_html_declarations(self):
class ArticleBlock(blocks.StreamBlock):
heading = blocks.CharBlock()