From cea9dbdb4ff2da829e2c2df02325eead328990e0 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Tue, 28 Apr 2015 07:57:24 -0400 Subject: [PATCH 1/2] yet another extra_vars fix --- awx/api/serializers.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/awx/api/serializers.py b/awx/api/serializers.py index e358d86c3b..2881b52b94 100644 --- a/awx/api/serializers.py +++ b/awx/api/serializers.py @@ -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: From df6b6e55a78fbc833fd242536c11afe040c5dc00 Mon Sep 17 00:00:00 2001 From: Chris Meyers Date: Tue, 28 Apr 2015 08:28:36 -0400 Subject: [PATCH 2/2] add tests that trigger error without fix provided --- awx/main/tests/jobs/jobs_monolithic.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/awx/main/tests/jobs/jobs_monolithic.py b/awx/main/tests/jobs/jobs_monolithic.py index b4c6c554f6..cb251be088 100644 --- a/awx/main/tests/jobs/jobs_monolithic.py +++ b/awx/main/tests/jobs/jobs_monolithic.py @@ -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)