data: fix ConfigJsonCell form validation (#42884)

This commit is contained in:
Lauréline Guérin 2020-05-15 09:40:34 +02:00
parent 1a6c51b999
commit 35c8d05564
No known key found for this signature in database
GPG Key ID: 1FAB9B9B4F93D473
2 changed files with 11 additions and 1 deletions

View File

@ -92,5 +92,7 @@ class ConfigJsonForm(forms.ModelForm):
def clean(self):
self.cleaned_data['parameters'] = {}
for field in self.formdef:
if field['varname'] not in self.cleaned_data:
continue
self.cleaned_data['parameters'][field['varname']] = self.cleaned_data[field['varname']]
return self.cleaned_data

View File

@ -1019,7 +1019,7 @@ def test_edit_config_json_cell(app, admin_user):
]}},
TEMPLATES=templates_settings):
resp = app.get('/manage/pages/%s/' % page.id)
assert not 'There are no options for this cell.' in resp.form.text
assert 'There are no options for this cell.' not in resp.form.text
resp.form['c%s-test' % cells[0].get_reference()].value = 'Hello world'
resp.form['c%s-test3' % cells[0].get_reference()].value = 'Hello again'
@ -1027,6 +1027,14 @@ def test_edit_config_json_cell(app, admin_user):
assert resp.status_int == 302
assert resp.location.endswith('/manage/pages/%s/#cell-%s' % (page.id, cells[0].get_reference()))
# test form error
resp = app.get('/manage/pages/%s/' % page.id)
resp.form['c%s-test' % cells[0].get_reference()].value = ''
resp.form['c%s-test3' % cells[0].get_reference()].value = 'Hello'
resp = resp.form.submit()
assert resp.status_int == 200
assert resp.context['form'].errors['test'] == ['This field is required.']
resp = app.get('/manage/pages/%s/' % page.id)
assert resp.form['c%s-test' % cells[0].get_reference()].value == 'Hello world'
assert resp.form['c%s-test2' % cells[0].get_reference()].checked is False