mirror of
https://github.com/ansible/awx.git
synced 2026-03-01 00:38:45 -03:30
Don't strictly require a max or min when the other is included and
parsing surveys
This commit is contained in:
@@ -240,19 +240,19 @@ class JobTemplate(UnifiedJobTemplate, JobOptions):
|
|||||||
errors.append("'%s' value missing" % survey_element['variable'])
|
errors.append("'%s' value missing" % survey_element['variable'])
|
||||||
elif survey_element['type'] in ["textarea", "text"]:
|
elif survey_element['type'] in ["textarea", "text"]:
|
||||||
if survey_element['variable'] in data:
|
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)" %
|
errors.append("'%s' value %s is too small (must be at least %s)" %
|
||||||
(survey_element['variable'], data[survey_element['variable']], survey_element['min']))
|
(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)" %
|
errors.append("'%s' value %s is too large (must be no more than%s)" %
|
||||||
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
|
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
|
||||||
elif survey_element['type'] == 'integer':
|
elif survey_element['type'] == 'integer':
|
||||||
if survey_element['variable'] in data:
|
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']:
|
data[survey_element['variable']] < survey_element['min']:
|
||||||
errors.append("'%s' value %s is too small (must be at least %s)" %
|
errors.append("'%s' value %s is too small (must be at least %s)" %
|
||||||
(survey_element['variable'], data[survey_element['variable']], survey_element['min']))
|
(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']:
|
data[survey_element['variable']] > survey_element['max']:
|
||||||
errors.append("'%s' value %s is too large (must be no more than%s)" %
|
errors.append("'%s' value %s is too large (must be no more than%s)" %
|
||||||
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
|
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
|
||||||
@@ -261,10 +261,10 @@ class JobTemplate(UnifiedJobTemplate, JobOptions):
|
|||||||
survey_element['variable']))
|
survey_element['variable']))
|
||||||
elif survey_element['type'] == 'float':
|
elif survey_element['type'] == 'float':
|
||||||
if survey_element['variable'] in data:
|
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)" %
|
errors.append("'%s' value %s is too small (must be at least %s)" %
|
||||||
(survey_element['variable'], data[survey_element['variable']], survey_element['min']))
|
(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)" %
|
errors.append("'%s' value %s is too large (must be no more than%s)" %
|
||||||
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
|
(survey_element['variable'], data[survey_element['variable']], survey_element['max']))
|
||||||
if type(data[survey_element['variable']]) not in (float, int):
|
if type(data[survey_element['variable']]) not in (float, int):
|
||||||
|
|||||||
@@ -160,6 +160,16 @@ TEST_SURVEY_REQUIREMENTS = '''
|
|||||||
"default": ""
|
"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",
|
"type": "float",
|
||||||
"question_name": "float",
|
"question_name": "float",
|
||||||
"question_description": "I need a float here",
|
"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)
|
self.post(launch_url, dict(int_answer=10, reqd_answer="foo"), expect=400)
|
||||||
# Integer that's just riiiiight
|
# Integer that's just riiiiight
|
||||||
self.post(launch_url, dict(int_answer=3, reqd_answer="foo"), expect=202)
|
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
|
# Integer answer that's the wrong type
|
||||||
self.post(launch_url, dict(int_answer="test", reqd_answer="foo"), expect=400)
|
self.post(launch_url, dict(int_answer="test", reqd_answer="foo"), expect=400)
|
||||||
# Float that's too big
|
# Float that's too big
|
||||||
|
|||||||
Reference in New Issue
Block a user