From 130d1f071f0bd2ca881b62d412fedf8e7f8e1f59 Mon Sep 17 00:00:00 2001 From: Chris Church Date: Tue, 15 Apr 2014 15:41:49 -0400 Subject: [PATCH] Return URL to new job created from job template callback. --- awx/api/views.py | 3 ++- awx/main/tests/jobs.py | 5 ++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/awx/api/views.py b/awx/api/views.py index e0fb47a57b..add9c6352d 100644 --- a/awx/api/views.py +++ b/awx/api/views.py @@ -1231,7 +1231,8 @@ class JobTemplateCallback(GenericAPIView): data = dict(msg='Error starting job!') return Response(data, status=status.HTTP_400_BAD_REQUEST) 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): diff --git a/awx/main/tests/jobs.py b/awx/main/tests/jobs.py index 1845b66154..e74ca55a32 100644 --- a/awx/main/tests/jobs.py +++ b/awx/main/tests/jobs.py @@ -1181,9 +1181,12 @@ class JobTemplateCallbackTest(BaseJobTestMixin, django.test.LiveServerTestCase): host_ip = self.get_test_ips_for_host(host.name)[0] jobs_qs = job_template.jobs.filter(launch_type='callback').order_by('-pk') 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) 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.limit, host.name) self.assertEqual(job.hosts.count(), 1)