mirror of
https://github.com/Hopiu/wagtail.git
synced 2026-03-26 19:00:28 +00:00
Add test for failing StreamBlock validation
This commit is contained in:
parent
968676c5bb
commit
b7fd5de8ec
1 changed files with 32 additions and 0 deletions
|
|
@ -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()
|
||||
|
|
|
|||
Loading…
Reference in a new issue