kopia lustrzana https://github.com/wagtail/wagtail
add unit test for get_prep_value with is_lazy=True
rodzic
dc0ae76eec
commit
045fda3595
|
@ -2626,7 +2626,16 @@ class TestStreamBlock(WagtailTestUtils, SimpleTestCase):
|
||||||
self.assertEqual(value[1].id, '0000')
|
self.assertEqual(value[1].id, '0000')
|
||||||
self.assertEqual(value[1].value, 'this is my heading')
|
self.assertEqual(value[1].value, 'this is my heading')
|
||||||
|
|
||||||
def test_get_prep_value(self):
|
def assertExpectedGetPrepValue(self, jsonish_value):
|
||||||
|
self.assertEqual(len(jsonish_value), 2)
|
||||||
|
self.assertEqual(jsonish_value[0], {'type': 'heading', 'value': 'this is my heading', 'id': '0000'})
|
||||||
|
self.assertEqual(jsonish_value[1]['type'], 'paragraph')
|
||||||
|
self.assertEqual(jsonish_value[1]['value'], '<p>this is a paragraph</p>')
|
||||||
|
# get_prep_value should assign a new (random and non-empty) ID to this block, as it didn't
|
||||||
|
# have one already
|
||||||
|
self.assertTrue(jsonish_value[1]['id'])
|
||||||
|
|
||||||
|
def get_prep_value(self):
|
||||||
class ArticleBlock(blocks.StreamBlock):
|
class ArticleBlock(blocks.StreamBlock):
|
||||||
heading = blocks.CharBlock()
|
heading = blocks.CharBlock()
|
||||||
paragraph = blocks.CharBlock()
|
paragraph = blocks.CharBlock()
|
||||||
|
@ -2637,15 +2646,22 @@ class TestStreamBlock(WagtailTestUtils, SimpleTestCase):
|
||||||
('heading', 'this is my heading', '0000'),
|
('heading', 'this is my heading', '0000'),
|
||||||
('paragraph', '<p>this is a paragraph</p>')
|
('paragraph', '<p>this is a paragraph</p>')
|
||||||
])
|
])
|
||||||
jsonish_value = block.get_prep_value(value)
|
|
||||||
|
|
||||||
self.assertEqual(len(jsonish_value), 2)
|
self.assertExpectedGetPrepValue(block.get_prep_value(value))
|
||||||
self.assertEqual(jsonish_value[0], {'type': 'heading', 'value': 'this is my heading', 'id': '0000'})
|
|
||||||
self.assertEqual(jsonish_value[1]['type'], 'paragraph')
|
def test_get_prep_value_lazy(self):
|
||||||
self.assertEqual(jsonish_value[1]['value'], '<p>this is a paragraph</p>')
|
class ArticleBlock(blocks.StreamBlock):
|
||||||
# get_prep_value should assign a new (random and non-empty) ID to this block, as it didn't
|
heading = blocks.CharBlock()
|
||||||
# have one already
|
paragraph = blocks.CharBlock()
|
||||||
self.assertTrue(jsonish_value[1]['id'])
|
|
||||||
|
block = ArticleBlock()
|
||||||
|
|
||||||
|
value = blocks.StreamValue(block, [
|
||||||
|
{'type': 'heading', 'value': 'this is my heading', 'id': '0000'},
|
||||||
|
{'type': 'paragraph', 'value': '<p>this is a paragraph</p>'},
|
||||||
|
], is_lazy=True)
|
||||||
|
|
||||||
|
self.assertExpectedGetPrepValue(block.get_prep_value(value))
|
||||||
|
|
||||||
|
|
||||||
class TestPageChooserBlock(TestCase):
|
class TestPageChooserBlock(TestCase):
|
||||||
|
|
Ładowanie…
Reference in New Issue