From 4f13255f35af98564d6a4e0cec4a422188d5619a Mon Sep 17 00:00:00 2001 From: Vismay Golwala Date: Tue, 12 Feb 2019 11:38:54 -0500 Subject: [PATCH] Allow empty default values for numerical survey answers. Signed-off-by: Vismay Golwala --- awx/api/views/__init__.py | 2 +- awx/main/tests/unit/api/test_views.py | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/awx/api/views/__init__.py b/awx/api/views/__init__.py index d2670c09f5..f754906951 100644 --- a/awx/api/views/__init__.py +++ b/awx/api/views/__init__.py @@ -2509,7 +2509,7 @@ class JobTemplateSurveySpec(GenericAPIView): ).format( 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]): type_label = 'string' if qtype in ['integer', 'float']: diff --git a/awx/main/tests/unit/api/test_views.py b/awx/main/tests/unit/api/test_views.py index e2f1f5150b..db602e3b85 100644 --- a/awx/main/tests/unit/api/test_views.py +++ b/awx/main/tests/unit/api/test_views.py @@ -413,3 +413,11 @@ class TestSurveySpecValidation: spec['spec'][0].pop('type') r = JobTemplateSurveySpec._validate_spec_data(spec, {}) 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