From 9119b40966266a6caa667afda0c972bb69dc1647 Mon Sep 17 00:00:00 2001 From: Matthew Jones Date: Wed, 10 Sep 2014 15:19:53 -0400 Subject: [PATCH] Take survey title and description into account --- awx/main/models/jobs.py | 8 +++-- awx/main/tests/jobs.py | 76 ++++++++++++++++++++++++----------------- 2 files changed, 50 insertions(+), 34 deletions(-) diff --git a/awx/main/models/jobs.py b/awx/main/models/jobs.py index eb38eac4ac..9522663392 100644 --- a/awx/main/models/jobs.py +++ b/awx/main/models/jobs.py @@ -215,7 +215,7 @@ class JobTemplate(UnifiedJobTemplate, JobOptions): def variables_needed_to_start(self): vars = [] if self.survey_enabled: - for survey_element in self.survey_spec: + for survey_element in self.survey_spec["spec"]: if survey_element['required']: vars.append(survey_element['variable']) return vars @@ -224,7 +224,11 @@ class JobTemplate(UnifiedJobTemplate, JobOptions): errors = [] if not self.survey_enabled: return errors - for survey_element in self.survey_spec: + if 'title' not in self.survey_spec: + errors.append("'title' missing from survey spec") + if 'description' not in self.survey_spec: + errors.append("'description' missing from survey spec") + for survey_element in self.survey_spec["spec"]: if survey_element['variable'] not in data and \ survey_element['required']: errors.append("'%s' value missing" % survey_element['variable']) diff --git a/awx/main/tests/jobs.py b/awx/main/tests/jobs.py index 278a78c3fe..93336c5694 100644 --- a/awx/main/tests/jobs.py +++ b/awx/main/tests/jobs.py @@ -49,24 +49,31 @@ TEST_ASYNC_PLAYBOOK = ''' ''' TEST_SIMPLE_REQUIRED_SURVEY = ''' -[ - { - "type": "text", - "question_name": "favorite color", - "question_description": "What is your favorite color?", - "variable": "favorite_color", - "choices": "", - "min": "", +{ + "title": "Simple", + "description": "Description", + "spec": [ + { + "type": "text", + "question_name": "favorite color", + "question_description": "What is your favorite color?", + "variable": "favorite_color", + "choices": "", + "min": "", "max": "", "required": true, "default": "blue" - } -] + } + ] +} ''' TEST_SIMPLE_NONREQUIRED_SURVEY = ''' -[ - { +{ + "title": "Simple", + "description": "Description", + "spec": [ + { "type": "text", "question_name": "unladen swallow", "question_description": "What is the airspeed velocity of an unladen swallow?", @@ -76,13 +83,17 @@ TEST_SIMPLE_NONREQUIRED_SURVEY = ''' "max": "", "required": false, "default": "european" - } -] + } + ] +} ''' TEST_SURVEY_REQUIREMENTS = ''' -[ - { +{ + "title": "Simple", + "description": "Description", + "spec": [ + { "type": "text", "question_name": "cantbeshort", "question_description": "What is a long answer", @@ -92,8 +103,8 @@ TEST_SURVEY_REQUIREMENTS = ''' "max": "", "required": false, "default": "yes" - }, - { + }, + { "type": "text", "question_name": "cantbelong", "question_description": "What is a short answer", @@ -103,8 +114,8 @@ TEST_SURVEY_REQUIREMENTS = ''' "max": 5, "required": false, "default": "yes" - }, - { + }, + { "type": "text", "question_name": "reqd", "question_description": "I should be required", @@ -114,8 +125,8 @@ TEST_SURVEY_REQUIREMENTS = ''' "max": "", "required": true, "default": "yes" - }, - { + }, + { "type": "multiplechoice", "question_name": "achoice", "question_description": "Need one of these", @@ -125,8 +136,8 @@ TEST_SURVEY_REQUIREMENTS = ''' "max": "", "required": false, "default": "yes" - }, - { + }, + { "type": "multiselect", "question_name": "mchoice", "question_description": "Can have multiples of these", @@ -136,8 +147,8 @@ TEST_SURVEY_REQUIREMENTS = ''' "max": "", "required": false, "default": "yes" - }, - { + }, + { "type": "integer", "question_name": "integerchoice", "question_description": "I need an int here", @@ -147,8 +158,8 @@ TEST_SURVEY_REQUIREMENTS = ''' "max": 5, "required": false, "default": "" - }, - { + }, + { "type": "float", "question_name": "float", "question_description": "I need a float here", @@ -158,8 +169,8 @@ TEST_SURVEY_REQUIREMENTS = ''' "max": 5, "required": false, "default": "" - }, - { + }, + { "type": "json", "question_name": "jsonanswer", "question_description": "This answer should validate as json", @@ -169,8 +180,9 @@ TEST_SURVEY_REQUIREMENTS = ''' "max": "", "required": false, "default": "" - } -] + } + ] +} ''' class BaseJobTestMixin(BaseTestMixin):