fix awx_collections tests by comparing Decimal to float, instead of comparing strings

This commit is contained in:
Seth Foster 2021-04-08 13:38:35 -04:00
parent f05ffa521a
commit 89e28d6d4a
No known key found for this signature in database
GPG Key ID: 86E90D96F7184028
3 changed files with 8 additions and 6 deletions

View File

@ -846,8 +846,6 @@ class UnifiedJob(
dq = decimal.Decimal('1.000')
if self.elapsed is None:
self.elapsed = decimal.Decimal(0.0).quantize(dq)
if 'elapsed' not in update_fields:
update_fields.append('elapsed')
# If we have a start and finished time, and haven't already calculated
# out the time that elapsed, do so.

View File

@ -13,9 +13,10 @@ def test_ad_hoc_command_wait_successful(run_module, admin_user):
command = AdHocCommand.objects.create(status='successful', started=now(), finished=now())
result = run_module('tower_ad_hoc_command_wait', dict(command_id=command.id), admin_user)
result.pop('invocation', None)
result['elapsed'] = float(result['elapsed'])
assert result.pop('finished', '')[:10] == str(command.finished)[:10]
assert result.pop('started', '')[:10] == str(command.started)[:10]
assert result == {"status": "successful", "changed": False, "elapsed": str(command.elapsed), "id": command.id}
assert result == {"status": "successful", "changed": False, "elapsed": command.elapsed, "id": command.id}
@pytest.mark.django_db
@ -23,13 +24,14 @@ def test_ad_hoc_command_wait_failed(run_module, admin_user):
command = AdHocCommand.objects.create(status='failed', started=now(), finished=now())
result = run_module('tower_ad_hoc_command_wait', dict(command_id=command.id), admin_user)
result.pop('invocation', None)
result['elapsed'] = float(result['elapsed'])
assert result.pop('finished', '')[:10] == str(command.finished)[:10]
assert result.pop('started', '')[:10] == str(command.started)[:10]
assert result == {
"status": "failed",
"failed": True,
"changed": False,
"elapsed": str(command.elapsed),
"elapsed": command.elapsed,
"id": command.id,
"msg": "The ad hoc command - 1, failed",
}

View File

@ -13,9 +13,10 @@ def test_job_wait_successful(run_module, admin_user):
job = Job.objects.create(status='successful', started=now(), finished=now())
result = run_module('tower_job_wait', dict(job_id=job.id), admin_user)
result.pop('invocation', None)
result['elapsed'] = float(result['elapsed'])
assert result.pop('finished', '')[:10] == str(job.finished)[:10]
assert result.pop('started', '')[:10] == str(job.started)[:10]
assert result == {"status": "successful", "changed": False, "elapsed": str(job.elapsed), "id": job.id}
assert result == {"status": "successful", "changed": False, "elapsed": job.elapsed, "id": job.id}
@pytest.mark.django_db
@ -23,9 +24,10 @@ def test_job_wait_failed(run_module, admin_user):
job = Job.objects.create(status='failed', started=now(), finished=now())
result = run_module('tower_job_wait', dict(job_id=job.id), admin_user)
result.pop('invocation', None)
result['elapsed'] = float(result['elapsed'])
assert result.pop('finished', '')[:10] == str(job.finished)[:10]
assert result.pop('started', '')[:10] == str(job.started)[:10]
assert result == {"status": "failed", "failed": True, "changed": False, "elapsed": str(job.elapsed), "id": job.id, "msg": "Job with id 1 failed"}
assert result == {"status": "failed", "failed": True, "changed": False, "elapsed": job.elapsed, "id": job.id, "msg": "Job with id 1 failed"}
@pytest.mark.django_db