mirror of
https://github.com/ansible/awx.git
synced 2026-03-21 02:47:35 -02:30
Merge pull request #75 from chrismeyersfsu/fix-6083
make password survey field behave like text field
This commit is contained in:
@@ -170,13 +170,14 @@ class SurveyJobTemplateMixin(models.Model):
|
|||||||
errors.append("Value %s for '%s' expected to be a string." % (data[survey_element['variable']],
|
errors.append("Value %s for '%s' expected to be a string." % (data[survey_element['variable']],
|
||||||
survey_element['variable']))
|
survey_element['variable']))
|
||||||
return errors
|
return errors
|
||||||
if not data[survey_element['variable']] == '$encrypted$' and not survey_element['type'] == 'password':
|
|
||||||
if 'min' in survey_element and survey_element['min'] not in ["", None] and len(data[survey_element['variable']]) < int(survey_element['min']):
|
if 'min' in survey_element and survey_element['min'] not in ["", None] and len(data[survey_element['variable']]) < int(survey_element['min']):
|
||||||
errors.append("'%s' value %s is too small (length is %s must be at least %s)." %
|
errors.append("'%s' value %s is too small (length is %s must be at least %s)." %
|
||||||
(survey_element['variable'], data[survey_element['variable']], len(data[survey_element['variable']]), survey_element['min']))
|
(survey_element['variable'], data[survey_element['variable']], len(data[survey_element['variable']]), survey_element['min']))
|
||||||
if 'max' in survey_element and survey_element['max'] not in ["", None] and len(data[survey_element['variable']]) > int(survey_element['max']):
|
if 'max' in survey_element and survey_element['max'] not in ["", None] and len(data[survey_element['variable']]) > int(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 type(data[survey_element['variable']]) != int:
|
if type(data[survey_element['variable']]) != int:
|
||||||
|
|||||||
@@ -139,7 +139,7 @@ def create_instance_group(name, instances=None):
|
|||||||
return mk_instance_group(name=name, instance=instances)
|
return mk_instance_group(name=name, instance=instances)
|
||||||
|
|
||||||
|
|
||||||
def create_survey_spec(variables=None, default_type='integer', required=True):
|
def create_survey_spec(variables=None, default_type='integer', required=True, min=None, max=None):
|
||||||
'''
|
'''
|
||||||
Returns a valid survey spec for a job template, based on the input
|
Returns a valid survey spec for a job template, based on the input
|
||||||
argument specifying variable name(s)
|
argument specifying variable name(s)
|
||||||
@@ -174,10 +174,14 @@ def create_survey_spec(variables=None, default_type='integer', required=True):
|
|||||||
spec_item.setdefault('question_description', "A question about %s." % var_name)
|
spec_item.setdefault('question_description', "A question about %s." % var_name)
|
||||||
if spec_item['type'] == 'integer':
|
if spec_item['type'] == 'integer':
|
||||||
spec_item.setdefault('default', 0)
|
spec_item.setdefault('default', 0)
|
||||||
spec_item.setdefault('max', spec_item['default'] + 100)
|
spec_item.setdefault('max', max or spec_item['default'] + 100)
|
||||||
spec_item.setdefault('min', spec_item['default'] - 100)
|
spec_item.setdefault('min', min or spec_item['default'] - 100)
|
||||||
else:
|
else:
|
||||||
spec_item.setdefault('default', '')
|
spec_item.setdefault('default', '')
|
||||||
|
if min:
|
||||||
|
spec_item.setdefault('min', min)
|
||||||
|
if max:
|
||||||
|
spec_item.setdefault('max', max)
|
||||||
spec.append(spec_item)
|
spec.append(spec_item)
|
||||||
|
|
||||||
survey_spec = {}
|
survey_spec = {}
|
||||||
|
|||||||
@@ -93,24 +93,29 @@ def test_update_kwargs_survey_invalid_default(survey_spec_factory):
|
|||||||
|
|
||||||
|
|
||||||
@pytest.mark.survey
|
@pytest.mark.survey
|
||||||
@pytest.mark.parametrize("question_type,default,expect_use,expect_value", [
|
@pytest.mark.parametrize("question_type,default,min,max,expect_use,expect_value", [
|
||||||
("multiplechoice", "", False, 'N/A'), # historical bug
|
("text", "", 0, 0, True, ''), # default used
|
||||||
("multiplechoice", "zeb", False, 'N/A'), # zeb not in choices
|
("text", "", 1, 0, False, 'N/A'), # value less than min length
|
||||||
("multiplechoice", "coffee", True, 'coffee'),
|
("password", "", 1, 0, False, 'N/A'), # passwords behave the same as text
|
||||||
("multiselect", None, False, 'N/A'), # NOTE: Behavior is arguable, value of [] may be prefered
|
("multiplechoice", "", 0, 0, False, 'N/A'), # historical bug
|
||||||
("multiselect", "", False, 'N/A'),
|
("multiplechoice", "zeb", 0, 0, False, 'N/A'), # zeb not in choices
|
||||||
("multiselect", ["zeb"], False, 'N/A'),
|
("multiplechoice", "coffee", 0, 0, True, 'coffee'),
|
||||||
("multiselect", ["milk"], True, ["milk"]),
|
("multiselect", None, 0, 0, False, 'N/A'), # NOTE: Behavior is arguable, value of [] may be prefered
|
||||||
("multiselect", ["orange\nmilk"], False, 'N/A'), # historical bug
|
("multiselect", "", 0, 0, False, 'N/A'),
|
||||||
|
("multiselect", ["zeb"], 0, 0, False, 'N/A'),
|
||||||
|
("multiselect", ["milk"], 0, 0, True, ["milk"]),
|
||||||
|
("multiselect", ["orange\nmilk"], 0, 0, False, 'N/A'), # historical bug
|
||||||
])
|
])
|
||||||
def test_optional_survey_question_defaults(
|
def test_optional_survey_question_defaults(
|
||||||
survey_spec_factory, question_type, default, expect_use, expect_value):
|
survey_spec_factory, question_type, default, min, max, expect_use, expect_value):
|
||||||
spec = survey_spec_factory([
|
spec = survey_spec_factory([
|
||||||
{
|
{
|
||||||
"required": False,
|
"required": False,
|
||||||
"default": default,
|
"default": default,
|
||||||
"choices": "orange\nmilk\nchocolate\ncoffee",
|
"choices": "orange\nmilk\nchocolate\ncoffee",
|
||||||
"variable": "c",
|
"variable": "c",
|
||||||
|
"min": min,
|
||||||
|
"max": max,
|
||||||
"type": question_type
|
"type": question_type
|
||||||
},
|
},
|
||||||
])
|
])
|
||||||
|
|||||||
Reference in New Issue
Block a user