tests: check post-condition using |getlist on block (#47715)

This commit is contained in:
Nicolas Roche 2020-11-04 18:12:39 +01:00 committed by Frédéric Péters
parent 83d03acdfb
commit d0fd141fb1
1 changed files with 36 additions and 0 deletions

View File

@ -834,3 +834,39 @@ def test_block_digest_item(pub, blocks_feature):
{'123': 'foo2', '234': '2', '234_display': 'deux'},
]
assert formdef.data_class().select()[0].data['1_display'] == 'XunY, XdeuxY'
def test_block_post_condition_on_2nd_page(pub, blocks_feature):
FormDef.wipe()
BlockDef.wipe()
block = BlockDef()
block.name = 'foobar'
block.fields = [
fields.StringField(id='123', required=True, label='Test', type='string', varname='foo'),
]
block.store()
formdef = FormDef()
formdef.name = 'form title'
formdef.fields = [
fields.PageField(id='0', label='1st page', type='page'),
fields.PageField(id='1', label='2nd page', type='page', post_conditions=[{
'condition': {
'type': 'django', 'value': 'form_var_blockfoo|getlist:"foo"|sum == 5'
}, 'error_message': 'You shall not pass.'}]),
fields.BlockField(id='2', label='test', type='block:foobar', max_items=3,
varname='blockfoo'),
]
formdef.store()
app = get_app(pub)
resp = app.get(formdef.get_url())
resp = resp.form.submit('submit') # -> second page
resp.form['f2$element0$f123'] = 2
resp = resp.form.submit('f2$add_element')
resp.form['f2$element1$f123'] = 3
resp = resp.form.submit('submit') # -> validation page
assert 'You shall not pass.' not in resp.text
resp = resp.form.submit('submit') # -> submit
resp = resp.follow()