1
0
mirror of https://github.com/ansible/awx.git synced 2024-10-31 15:21:13 +03:00

Add tests for changed flag on job events.

This commit is contained in:
Chris Church 2013-07-02 14:41:05 -04:00
parent 4762166caf
commit fccf663d42
3 changed files with 12 additions and 6 deletions

View File

@ -1130,11 +1130,9 @@ class JobEvent(models.Model):
def save(self, *args, **kwargs):
if self.event in self.FAILED_EVENTS:
self.failed = True
try:
if self.event_data['res']['changed']:
self.changed = True
except (KeyError, IndexError, AttributeError):
pass
res = self.event_data.get('res', None)
if isinstance(res, dict) and res.get('changed', False):
self.changed = True
try:
if not self.host and self.event_data.get('host', ''):
self.host = self.job.inventory.hosts.get(name=self.event_data['host'])

View File

@ -159,6 +159,7 @@ class RunJobTest(BaseCeleryTest):
'inventory': self.inventory,
'project': self.project,
'credential': self.credential,
'job_type': 'run',
}
try:
opts['playbook'] = self.project.playbooks[0]
@ -178,6 +179,7 @@ class RunJobTest(BaseCeleryTest):
'inventory': self.inventory,
'project': self.project,
'credential': self.credential,
'job_type': 'run',
}
try:
opts['playbook'] = self.project.playbooks[0]
@ -219,6 +221,8 @@ class RunJobTest(BaseCeleryTest):
unicode(job_event) # For test coverage.
job_event.save()
should_be_failed = bool(runner_status not in ('ok', 'skipped'))
should_be_changed = bool(runner_status in ('ok', 'failed') and
job.job_type == 'run')
host_pks = set([self.host.pk])
qs = job_events.filter(event='playbook_on_start')
self.assertEqual(qs.count(), 1)
@ -227,6 +231,7 @@ class RunJobTest(BaseCeleryTest):
self.assertFalse(evt.play, evt)
self.assertFalse(evt.task, evt)
self.assertEqual(evt.failed, should_be_failed)
self.assertEqual(evt.changed, should_be_changed)
self.assertEqual(set(evt.hosts.values_list('pk', flat=True)),
host_pks)
qs = job_events.filter(event='playbook_on_play_start')
@ -236,6 +241,7 @@ class RunJobTest(BaseCeleryTest):
self.assertTrue(evt.play, evt)
self.assertFalse(evt.task, evt)
self.assertEqual(evt.failed, should_be_failed)
self.assertEqual(evt.changed, should_be_changed)
self.assertEqual(set(evt.hosts.values_list('pk', flat=True)),
host_pks)
qs = job_events.filter(event='playbook_on_task_start')
@ -245,6 +251,7 @@ class RunJobTest(BaseCeleryTest):
self.assertTrue(evt.play, evt)
self.assertTrue(evt.task, evt)
self.assertEqual(evt.failed, should_be_failed)
self.assertEqual(evt.changed, should_be_changed)
self.assertEqual(set(evt.hosts.values_list('pk', flat=True)),
host_pks)
qs = job_events.filter(event=('runner_on_%s' % runner_status))
@ -254,6 +261,7 @@ class RunJobTest(BaseCeleryTest):
self.assertTrue(evt.play, evt)
self.assertTrue(evt.task, evt)
self.assertEqual(evt.failed, should_be_failed)
self.assertEqual(evt.changed, should_be_changed)
self.assertEqual(set(evt.hosts.values_list('pk', flat=True)),
host_pks)
qs = job_events.filter(event__startswith='runner_')

View File

@ -35,7 +35,7 @@ from awx.main.serializers import *
def handle_error(request, status=404):
context = {}
print request.path, status
#print request.path, status
if request.path.startswith('/admin/'):
template_name = 'admin/%d.html' % status
else: