Merge pull request #168 from chrismeyersfsu/fix-extra_vars

job template launch handle extra_vars
This commit is contained in:
Chris Meyers 2015-04-28 09:49:29 -04:00
commit 718e5dd620
2 changed files with 24 additions and 0 deletions

View File

@ -1801,6 +1801,9 @@ class JobLaunchSerializer(BaseSerializer):
except (yaml.YAMLError, TypeError, AttributeError):
raise serializers.ValidationError(dict(extra_vars=['Must be valid JSON or YAML']))
if not isinstance(extra_vars, dict):
extra_vars = {}
if self.get_survey_enabled(obj):
validation_errors = obj.survey_variable_validation(extra_vars)
if validation_errors:

View File

@ -1152,6 +1152,27 @@ class JobTemplateSurveyTest(BaseJobTestMixin, django.test.TestCase):
job_extra = json.loads(job.extra_vars)
self.assertTrue("favorite_color" in job_extra)
# launch job template with required survey without providing survey data
with self.current_user(self.user_sue):
self.post(url, json.loads(TEST_SIMPLE_REQUIRED_SURVEY), expect=200)
response = self.get(launch_url)
self.assertTrue('favorite_color' in response['variables_needed_to_start'])
response = self.post(launch_url, dict(extra_vars=dict()), expect=400)
# Note: The below assertion relies on how survey_variable_validation() crafts
# the error message
self.assertIn("'favorite_color' value missing", response['variables_needed_to_start'])
# launch job template with required survey without providing survey data and without
# even providing extra_vars
with self.current_user(self.user_sue):
self.post(url, json.loads(TEST_SIMPLE_REQUIRED_SURVEY), expect=200)
response = self.get(launch_url)
self.assertTrue('favorite_color' in response['variables_needed_to_start'])
response = self.post(launch_url, {}, expect=400)
# Note: The below assertion relies on how survey_variable_validation() crafts
# the error message
self.assertIn("'favorite_color' value missing", response['variables_needed_to_start'])
with self.current_user(self.user_sue):
response = self.post(url, json.loads(TEST_SIMPLE_NONREQUIRED_SURVEY), expect=200)
response = self.get(launch_url)