diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index dff8b2a5f1..d31f571607 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -240,19 +240,19 @@ class JobTemplate(UnifiedJobTemplate, JobOptions): errors.append("'%s' value missing" % survey_element['variable']) elif survey_element['type'] in ["textarea", "text"]: if survey_element['variable'] in data: - if 'min' in survey_element and survey_element['min'] != "" and len(data[survey_element['variable']]) < survey_element['min']: + if 'min' in survey_element and survey_element['min'] not in ["", None] and len(data[survey_element['variable']]) < survey_element['min']: errors.append("'%s' value %s is too small (must be at least %s)" % (survey_element['variable'], data[survey_element['variable']], survey_element['min'])) - if 'max' in survey_element and survey_element['max'] != "" and len(data[survey_element['variable']]) > survey_element['max']: + if 'max' in survey_element and survey_element['max'] not in ["", None] and len(data[survey_element['variable']]) > survey_element['max']: errors.append("'%s' value %s is too large (must be no more than%s)" % (survey_element['variable'], data[survey_element['variable']], survey_element['max'])) elif survey_element['type'] == 'integer': if survey_element['variable'] in data: - if 'min' in survey_element and survey_element['min'] != "" and survey_element['variable'] in data and \ + if 'min' in survey_element and survey_element['min'] not in ["", None] and survey_element['variable'] in data and \ data[survey_element['variable']] < survey_element['min']: errors.append("'%s' value %s is too small (must be at least %s)" % (survey_element['variable'], data[survey_element['variable']], survey_element['min'])) - if 'max' in survey_element and survey_element['max'] != "" and survey_element['variable'] in data and \ + if 'max' in survey_element and survey_element['max'] not in ["", None] and survey_element['variable'] in data and \ data[survey_element['variable']] > survey_element['max']: errors.append("'%s' value %s is too large (must be no more than%s)" % (survey_element['variable'], data[survey_element['variable']], survey_element['max'])) @@ -261,10 +261,10 @@ class JobTemplate(UnifiedJobTemplate, JobOptions): survey_element['variable'])) elif survey_element['type'] == 'float': if survey_element['variable'] in data: - if 'min' in survey_element and survey_element['min'] != "" and data[survey_element['variable']] < survey_element['min']: + if 'min' in survey_element and survey_element['min'] not in ["", None] and data[survey_element['variable']] < survey_element['min']: errors.append("'%s' value %s is too small (must be at least %s)" % (survey_element['variable'], data[survey_element['variable']], survey_element['min'])) - if 'max' in survey_element and survey_element['max'] != "" and data[survey_element['variable']] > survey_element['max']: + if 'max' in survey_element and survey_element['max'] not in ["", None] and data[survey_element['variable']] > survey_element['max']: errors.append("'%s' value %s is too large (must be no more than%s)" % (survey_element['variable'], data[survey_element['variable']], survey_element['max'])) if type(data[survey_element['variable']]) not in (float, int): diff --git a/awx/main/tests/jobs.py b/awx/main/tests/jobs.py index 1d7ef4eeed..7d848cf05b 100644 --- a/awx/main/tests/jobs.py +++ b/awx/main/tests/jobs.py @@ -160,6 +160,16 @@ TEST_SURVEY_REQUIREMENTS = ''' "default": "" }, { + "type": "integer", + "question_name": "integerchoicewithoutmax", + "question_description": "I need an int here without max", + "variable": "int_answer_no_max", + "choices": "", + "min": 1, + "required": false, + "default": "" + }, + { "type": "float", "question_name": "float", "question_description": "I need a float here", @@ -972,6 +982,8 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase): self.post(launch_url, dict(int_answer=10, reqd_answer="foo"), expect=400) # Integer that's just riiiiight self.post(launch_url, dict(int_answer=3, reqd_answer="foo"), expect=202) + # Integer bigger than min with no max defined + self.post(launch_url, dict(int_answer_no_max=3, reqd_answer="foo"), expect=202) # Integer answer that's the wrong type self.post(launch_url, dict(int_answer="test", reqd_answer="foo"), expect=400) # Float that's too big