mirror of
https://github.com/ansible/awx.git
synced 2026-02-19 12:10:06 -03:30
Merge pull request #168 from chrismeyersfsu/fix-extra_vars
job template launch handle extra_vars
This commit is contained in:
@@ -1801,6 +1801,9 @@ class JobLaunchSerializer(BaseSerializer):
|
|||||||
except (yaml.YAMLError, TypeError, AttributeError):
|
except (yaml.YAMLError, TypeError, AttributeError):
|
||||||
raise serializers.ValidationError(dict(extra_vars=['Must be valid JSON or YAML']))
|
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):
|
if self.get_survey_enabled(obj):
|
||||||
validation_errors = obj.survey_variable_validation(extra_vars)
|
validation_errors = obj.survey_variable_validation(extra_vars)
|
||||||
if validation_errors:
|
if validation_errors:
|
||||||
|
|||||||
@@ -1152,6 +1152,27 @@ class JobTemplateSurveyTest(BaseJobTestMixin, django.test.TestCase):
|
|||||||
job_extra = json.loads(job.extra_vars)
|
job_extra = json.loads(job.extra_vars)
|
||||||
self.assertTrue("favorite_color" in job_extra)
|
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):
|
with self.current_user(self.user_sue):
|
||||||
response = self.post(url, json.loads(TEST_SIMPLE_NONREQUIRED_SURVEY), expect=200)
|
response = self.post(url, json.loads(TEST_SIMPLE_NONREQUIRED_SURVEY), expect=200)
|
||||||
response = self.get(launch_url)
|
response = self.get(launch_url)
|
||||||
|
|||||||
Reference in New Issue
Block a user