correctly forbid empty Python expression (#24670)
This commit is contained in:
parent
320dee2376
commit
486225c4b2
|
@ -502,7 +502,22 @@ def test_computed_expression_widget():
|
|||
assert not widget.has_error()
|
||||
|
||||
widget = ComputedExpressionWidget('test')
|
||||
mock_form_submission(req, widget, {'test$value_python': '=hello world', 'test$type': ['python']})
|
||||
mock_form_submission(req, widget, {'test$value_python': 'hello world', 'test$type': ['python']})
|
||||
assert widget.has_error()
|
||||
assert widget.get_error().startswith('syntax error')
|
||||
|
||||
widget = ComputedExpressionWidget('test')
|
||||
mock_form_submission(req, widget, {'test$value_python': '=3', 'test$type': ['python']})
|
||||
assert widget.has_error()
|
||||
assert widget.get_error().startswith('syntax error')
|
||||
|
||||
widget = ComputedExpressionWidget('test')
|
||||
mock_form_submission(req, widget, {'test$value_python': '', 'test$type': ['python']})
|
||||
assert widget.has_error()
|
||||
assert widget.get_error().startswith('syntax error')
|
||||
|
||||
widget = ComputedExpressionWidget('test')
|
||||
mock_form_submission(req, widget, {'test$type': ['python']})
|
||||
assert widget.has_error()
|
||||
assert widget.get_error().startswith('syntax error')
|
||||
|
||||
|
|
|
@ -2325,7 +2325,7 @@ class ComputedExpressionWidget(CompositeWidget):
|
|||
if not self.get('type'):
|
||||
return
|
||||
value_type = self.get('type')
|
||||
value_content = self.get('value_%s' % value_type)
|
||||
value_content = self.get('value_%s' % value_type) or ''
|
||||
if value_type == 'python':
|
||||
self.value = '=' + value_content
|
||||
else:
|
||||
|
|
Loading…
Reference in New Issue