1
0
mirror of https://github.com/ansible/awx.git synced 2024-11-02 01:21:21 +03:00

Return URL to new job created from job template callback.

This commit is contained in:
Chris Church 2014-04-15 15:41:49 -04:00
parent 7eed13cca4
commit 130d1f071f
2 changed files with 6 additions and 2 deletions

View File

@ -1231,7 +1231,8 @@ class JobTemplateCallback(GenericAPIView):
data = dict(msg='Error starting job!') data = dict(msg='Error starting job!')
return Response(data, status=status.HTTP_400_BAD_REQUEST) return Response(data, status=status.HTTP_400_BAD_REQUEST)
else: else:
return Response(status=status.HTTP_202_ACCEPTED) headers = {'Location': job.get_absolute_url()}
return Response(status=status.HTTP_202_ACCEPTED, headers=headers)
class JobTemplateJobsList(SubListCreateAPIView): class JobTemplateJobsList(SubListCreateAPIView):

View File

@ -1181,9 +1181,12 @@ class JobTemplateCallbackTest(BaseJobTestMixin, django.test.LiveServerTestCase):
host_ip = self.get_test_ips_for_host(host.name)[0] host_ip = self.get_test_ips_for_host(host.name)[0]
jobs_qs = job_template.jobs.filter(launch_type='callback').order_by('-pk') jobs_qs = job_template.jobs.filter(launch_type='callback').order_by('-pk')
self.assertEqual(jobs_qs.count(), 0) self.assertEqual(jobs_qs.count(), 0)
self.post(url, data, expect=202, remote_addr=host_ip) result = self.post(url, data, expect=202, remote_addr=host_ip)
self.assertTrue('Location' in result.response, result.response)
self.assertEqual(jobs_qs.count(), 1) self.assertEqual(jobs_qs.count(), 1)
job = jobs_qs[0] job = jobs_qs[0]
self.assertEqual(urlparse.urlsplit(result.response['Location']).path,
job.get_absolute_url())
self.assertEqual(job.launch_type, 'callback') self.assertEqual(job.launch_type, 'callback')
self.assertEqual(job.limit, host.name) self.assertEqual(job.limit, host.name)
self.assertEqual(job.hosts.count(), 1) self.assertEqual(job.hosts.count(), 1)