mirror of
https://github.com/ansible/awx.git
synced 2026-03-09 13:39:27 -02:30
Adding a job_tasks test.
This commit is contained in:
56
awx/api/tests/job_tasks.py
Normal file
56
awx/api/tests/job_tasks.py
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
# Copyright (c) 2014 Ansible, Inc.
|
||||||
|
# All Rights Reserved.
|
||||||
|
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
|
from django.contrib.auth.models import User
|
||||||
|
from django.core.urlresolvers import reverse
|
||||||
|
from django.test import LiveServerTestCase
|
||||||
|
from django.test.utils import override_settings
|
||||||
|
|
||||||
|
from rest_framework.test import APIClient
|
||||||
|
|
||||||
|
import mock
|
||||||
|
|
||||||
|
from awx.api.views import JobJobTasksList
|
||||||
|
from awx.main.models import Job, JobTemplate, JobEvent
|
||||||
|
from awx.main.tests.jobs import BaseJobTestMixin, MIDDLEWARE_CLASSES
|
||||||
|
|
||||||
|
|
||||||
|
@override_settings(CELERY_ALWAYS_EAGER=True,
|
||||||
|
CELERY_EAGER_PROPAGATES_EXCEPTIONS=True,
|
||||||
|
CALLBACK_CONSUMER_PORT='',
|
||||||
|
ANSIBLE_TRANSPORT='local',
|
||||||
|
MIDDLEWARE_CLASSES=MIDDLEWARE_CLASSES)
|
||||||
|
class JobTasksTests(BaseJobTestMixin, LiveServerTestCase):
|
||||||
|
"""A set of tests to ensure that the job_tasks endpoint, available at
|
||||||
|
`/api/v1/jobs/{id}/job_tasks/`, works as expected.
|
||||||
|
"""
|
||||||
|
def setUp(self):
|
||||||
|
super(JobTasksTests, self).setUp()
|
||||||
|
settings.INTERNAL_API_URL = self.live_server_url
|
||||||
|
|
||||||
|
def test_tasks_endpoint(self):
|
||||||
|
"""Establish that the `job_tasks` endpoint shows what we expect,
|
||||||
|
which is a rollup of information about each of the corresponding
|
||||||
|
job events.
|
||||||
|
"""
|
||||||
|
# Create a job
|
||||||
|
job = self.make_job(self.jt_ops_east_run, self.user_sue, 'new')
|
||||||
|
job.signal_start()
|
||||||
|
|
||||||
|
# Get the initial job event.
|
||||||
|
event = job.job_events.get(event='playbook_on_play_start')
|
||||||
|
|
||||||
|
# Actually make the request for the job tasks.
|
||||||
|
with self.current_user(self.user_sue):
|
||||||
|
url = '/api/v1/jobs/%d/job_tasks/?event_id=%d' % (job.id, event.id)
|
||||||
|
response = self.get(url)
|
||||||
|
|
||||||
|
# Test to make sure we got back what we expected.
|
||||||
|
result = response['results'][0]
|
||||||
|
self.assertEqual(result['host_count'], 1)
|
||||||
|
self.assertEqual(result['changed_count'], 1)
|
||||||
|
self.assertFalse(result['failed'])
|
||||||
|
self.assertTrue(result['changed'])
|
||||||
@@ -1572,7 +1572,8 @@ class JobJobTasksList(BaseJobEventsList):
|
|||||||
data.setdefault(parent_id, [])
|
data.setdefault(parent_id, [])
|
||||||
data[parent_id].append(line)
|
data[parent_id].append(line)
|
||||||
|
|
||||||
# Iterate over the start events and compile information about each one.
|
# Iterate over the start events and compile information about each one
|
||||||
|
# using their children.
|
||||||
qs = parent_task.children.filter(event__in=STARTING_EVENTS,
|
qs = parent_task.children.filter(event__in=STARTING_EVENTS,
|
||||||
id__in=data.keys())
|
id__in=data.keys())
|
||||||
for task_start_event in qs:
|
for task_start_event in qs:
|
||||||
|
|||||||
Reference in New Issue
Block a user