Add tests for job template launch with invalid/inactive credential, fix bug that allowed an inactive credential to be passed if the job template already had an active credential.

This commit is contained in:
Chris Church
2015-04-26 12:28:39 -04:00
parent 2093b3db7a
commit 0d4c1a4245
2 changed files with 27 additions and 17 deletions

View File

@@ -492,9 +492,14 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase):
j = Job.objects.get(pk=response['job'])
self.assertTrue(j.status == 'new')
# Can't launch a job template without a credential defined
# Can't launch a job template without a credential defined (or if we
# pass an invalid/inactive credential value).
with self.current_user(self.user_sue):
response = self.post(no_launch_url, {}, expect=400)
response = self.post(no_launch_url, {'credential': 0}, expect=400)
response = self.post(no_launch_url, {'credential': 'one'}, expect=400)
self.cred_doug.mark_inactive()
response = self.post(no_launch_url, {'credential': self.cred_doug.pk}, expect=400)
# Job Templates without projects can not be launched
with self.current_user(self.user_sue):
@@ -503,9 +508,9 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase):
jt = JobTemplate.objects.get(pk=response['id'])
jt.project = None
jt.save()
launch_url = reverse('api:job_template_launch',
args=(response['id'],))
self.post(launch_url, {}, expect=400)
launch_url2 = reverse('api:job_template_launch',
args=(response['id'],))
self.post(launch_url2, {}, expect=400)
# Job Templates without inventory can not be launched
with self.current_user(self.user_sue):
@@ -514,9 +519,15 @@ class JobTemplateTest(BaseJobTestMixin, django.test.TestCase):
jt = JobTemplate.objects.get(pk=response['id'])
jt.inventory = None
jt.save()
launch_url = reverse('api:job_template_launch',
args=(response['id'],))
self.post(launch_url, {}, expect=400)
launch_url3 = reverse('api:job_template_launch',
args=(response['id'],))
self.post(launch_url3, {}, expect=400)
# Job Templates with deleted credentials cannot be launched.
self.cred_sue.mark_inactive()
with self.current_user(self.user_sue):
response = self.post(launch_url, {}, expect=400)
class JobTest(BaseJobTestMixin, django.test.TestCase):