Take survey title and description into account

This commit is contained in:
Matthew Jones
2014-09-10 15:19:53 -04:00
parent 59f3321b13
commit 9119b40966
2 changed files with 50 additions and 34 deletions

View File

@@ -215,7 +215,7 @@ class JobTemplate(UnifiedJobTemplate, JobOptions):
def variables_needed_to_start(self): def variables_needed_to_start(self):
vars = [] vars = []
if self.survey_enabled: if self.survey_enabled:
for survey_element in self.survey_spec: for survey_element in self.survey_spec["spec"]:
if survey_element['required']: if survey_element['required']:
vars.append(survey_element['variable']) vars.append(survey_element['variable'])
return vars return vars
@@ -224,7 +224,11 @@ class JobTemplate(UnifiedJobTemplate, JobOptions):
errors = [] errors = []
if not self.survey_enabled: if not self.survey_enabled:
return errors 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 \ if survey_element['variable'] not in data and \
survey_element['required']: survey_element['required']:
errors.append("'%s' value missing" % survey_element['variable']) errors.append("'%s' value missing" % survey_element['variable'])

View File

@@ -49,24 +49,31 @@ TEST_ASYNC_PLAYBOOK = '''
''' '''
TEST_SIMPLE_REQUIRED_SURVEY = ''' TEST_SIMPLE_REQUIRED_SURVEY = '''
[ {
{ "title": "Simple",
"type": "text", "description": "Description",
"question_name": "favorite color", "spec": [
"question_description": "What is your favorite color?", {
"variable": "favorite_color", "type": "text",
"choices": "", "question_name": "favorite color",
"min": "", "question_description": "What is your favorite color?",
"variable": "favorite_color",
"choices": "",
"min": "",
"max": "", "max": "",
"required": true, "required": true,
"default": "blue" "default": "blue"
} }
] ]
}
''' '''
TEST_SIMPLE_NONREQUIRED_SURVEY = ''' TEST_SIMPLE_NONREQUIRED_SURVEY = '''
[ {
{ "title": "Simple",
"description": "Description",
"spec": [
{
"type": "text", "type": "text",
"question_name": "unladen swallow", "question_name": "unladen swallow",
"question_description": "What is the airspeed velocity of an unladen swallow?", "question_description": "What is the airspeed velocity of an unladen swallow?",
@@ -76,13 +83,17 @@ TEST_SIMPLE_NONREQUIRED_SURVEY = '''
"max": "", "max": "",
"required": false, "required": false,
"default": "european" "default": "european"
} }
] ]
}
''' '''
TEST_SURVEY_REQUIREMENTS = ''' TEST_SURVEY_REQUIREMENTS = '''
[ {
{ "title": "Simple",
"description": "Description",
"spec": [
{
"type": "text", "type": "text",
"question_name": "cantbeshort", "question_name": "cantbeshort",
"question_description": "What is a long answer", "question_description": "What is a long answer",
@@ -92,8 +103,8 @@ TEST_SURVEY_REQUIREMENTS = '''
"max": "", "max": "",
"required": false, "required": false,
"default": "yes" "default": "yes"
}, },
{ {
"type": "text", "type": "text",
"question_name": "cantbelong", "question_name": "cantbelong",
"question_description": "What is a short answer", "question_description": "What is a short answer",
@@ -103,8 +114,8 @@ TEST_SURVEY_REQUIREMENTS = '''
"max": 5, "max": 5,
"required": false, "required": false,
"default": "yes" "default": "yes"
}, },
{ {
"type": "text", "type": "text",
"question_name": "reqd", "question_name": "reqd",
"question_description": "I should be required", "question_description": "I should be required",
@@ -114,8 +125,8 @@ TEST_SURVEY_REQUIREMENTS = '''
"max": "", "max": "",
"required": true, "required": true,
"default": "yes" "default": "yes"
}, },
{ {
"type": "multiplechoice", "type": "multiplechoice",
"question_name": "achoice", "question_name": "achoice",
"question_description": "Need one of these", "question_description": "Need one of these",
@@ -125,8 +136,8 @@ TEST_SURVEY_REQUIREMENTS = '''
"max": "", "max": "",
"required": false, "required": false,
"default": "yes" "default": "yes"
}, },
{ {
"type": "multiselect", "type": "multiselect",
"question_name": "mchoice", "question_name": "mchoice",
"question_description": "Can have multiples of these", "question_description": "Can have multiples of these",
@@ -136,8 +147,8 @@ TEST_SURVEY_REQUIREMENTS = '''
"max": "", "max": "",
"required": false, "required": false,
"default": "yes" "default": "yes"
}, },
{ {
"type": "integer", "type": "integer",
"question_name": "integerchoice", "question_name": "integerchoice",
"question_description": "I need an int here", "question_description": "I need an int here",
@@ -147,8 +158,8 @@ TEST_SURVEY_REQUIREMENTS = '''
"max": 5, "max": 5,
"required": false, "required": false,
"default": "" "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",
@@ -158,8 +169,8 @@ TEST_SURVEY_REQUIREMENTS = '''
"max": 5, "max": 5,
"required": false, "required": false,
"default": "" "default": ""
}, },
{ {
"type": "json", "type": "json",
"question_name": "jsonanswer", "question_name": "jsonanswer",
"question_description": "This answer should validate as json", "question_description": "This answer should validate as json",
@@ -169,8 +180,9 @@ TEST_SURVEY_REQUIREMENTS = '''
"max": "", "max": "",
"required": false, "required": false,
"default": "" "default": ""
} }
] ]
}
''' '''
class BaseJobTestMixin(BaseTestMixin): class BaseJobTestMixin(BaseTestMixin):