mirror of
https://github.com/ansible/awx.git
synced 2026-05-06 08:57:35 -02:30
Merge pull request #3215 from vismay-golwala/survey_allow_empty_defaults
Allow empty default values for numerical survey answers. Reviewed-by: https://github.com/softwarefactory-project-zuul[bot]
This commit is contained in:
@@ -2530,7 +2530,7 @@ class JobTemplateSurveySpec(GenericAPIView):
|
|||||||
).format(
|
).format(
|
||||||
allowed_types=', '.join(JobTemplateSurveySpec.ALLOWED_TYPES.keys()), **context
|
allowed_types=', '.join(JobTemplateSurveySpec.ALLOWED_TYPES.keys()), **context
|
||||||
)))
|
)))
|
||||||
if 'default' in survey_item:
|
if 'default' in survey_item and survey_item['default'] != '':
|
||||||
if not isinstance(survey_item['default'], JobTemplateSurveySpec.ALLOWED_TYPES[qtype]):
|
if not isinstance(survey_item['default'], JobTemplateSurveySpec.ALLOWED_TYPES[qtype]):
|
||||||
type_label = 'string'
|
type_label = 'string'
|
||||||
if qtype in ['integer', 'float']:
|
if qtype in ['integer', 'float']:
|
||||||
|
|||||||
@@ -413,3 +413,11 @@ class TestSurveySpecValidation:
|
|||||||
spec['spec'][0].pop('type')
|
spec['spec'][0].pop('type')
|
||||||
r = JobTemplateSurveySpec._validate_spec_data(spec, {})
|
r = JobTemplateSurveySpec._validate_spec_data(spec, {})
|
||||||
assert "'type' missing from survey question 0" in r.data['error']
|
assert "'type' missing from survey question 0" in r.data['error']
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.parametrize('_type', ['integer', 'float'])
|
||||||
|
def test_survey_spec_element_number_empty_default(self, _type):
|
||||||
|
""" Assert that empty default is allowed for answer. """
|
||||||
|
spec = self.spec_from_element({'type': _type, 'default': ''})
|
||||||
|
r = JobTemplateSurveySpec._validate_spec_data(spec, {})
|
||||||
|
assert r is None
|
||||||
|
|||||||
Reference in New Issue
Block a user