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)