WIP: ne pas vérifier les post-conditions si le formulaire contient des erreurs (#86992) #1145

Closed
bdauvergne wants to merge 2 commits from wip/86992-Condition-de-sortie-de-page-ne-p into main
3 changed files with 8 additions and 2 deletions

View File

@ -462,6 +462,7 @@ def test_tests_edit_data_mark_as_failing(pub):
),
fields.StringField(id='1', label='Text', varname='text', validation={'type': 'digits'}),
fields.CommentField(id='2', label='comment field'),
fields.StringField(id='3', label='Text', varname='text2', validation={'type': 'digits'}),
]
formdef.store()
@ -482,6 +483,7 @@ def test_tests_edit_data_mark_as_failing(pub):
assert 'Mark as failing' not in resp.text
resp.form['f1'] = '123456'
resp.form['f3'] = '123456'
resp = resp.form.submit('submit').follow()
assert '123456' in resp.text
@ -490,11 +492,13 @@ def test_tests_edit_data_mark_as_failing(pub):
# two errors on page
resp.form['f1'] = '123a'
resp.form['f3'] = '123a'
resp = resp.form.submit('submit')
assert 'Mark as failing' not in resp.text
# one error
resp.form['f1'] = '1234'
resp.form['f3'] = '1234'
resp = resp.form.submit('submit')
assert 'If test should fail on error "Not enough chars.", click button below.' in resp.text
assert 'Mark as failing' in resp.text

View File

@ -5911,7 +5911,6 @@ def test_form_errors_summary(pub):
formdef.data_class().wipe()
resp = get_app(pub).get('/test/')
resp = resp.forms[0].submit('submit')
assert 'You shall not pass.' in resp.pyquery('.errornotice').text()
assert 'The following field has an error: string1' in resp.pyquery('.errornotice').text()
resp.forms[0]['f1'] = 'foo'

View File

@ -1332,7 +1332,6 @@ class FormPage(Directory, TempfileDirectoryMixin, FormTemplateMixin):
page_error_messages = []
if form.get_submit() == 'submit' and page:
post_conditions = page.post_conditions or []
# create a new dictionary to hold live data, this makes sure
# a new ConditionsVars will get added to the substitution
# variables.
@ -1351,6 +1350,10 @@ class FormPage(Directory, TempfileDirectoryMixin, FormTemplateMixin):
)
form_data.update(data)
form_data.update(computed_data)
if form.get_submit() == 'submit' and page and not form.has_errors():
# check post conditions
post_conditions = page.post_conditions or []
for i, post_condition in enumerate(post_conditions):
condition = post_condition.get('condition')
error_message = post_condition.get('error_message')