adds tests

This commit is contained in:
Tim O'Meara
2020-08-11 11:48:23 -05:00
parent d5a0363af3
commit f26de929d6
2 changed files with 39 additions and 2 deletions

View File

@@ -21,7 +21,8 @@ def test_admin_views(admin_client, monkeypatch):
func='test.fail',
started=timezone.now(),
stopped=timezone.now(),
success=False)
success=False,
attempt_count=1)
tag = uuid()
t = Task.objects.create(
id=tag[1],
@@ -29,7 +30,8 @@ def test_admin_views(admin_client, monkeypatch):
func='test.success',
started=timezone.now(),
stopped=timezone.now(),
success=True)
success=True,
attempt_count=1)
q = OrmQ.objects.create(
key='test',
payload=SignedPackage.dumps({'id': 1, 'func': 'test', 'name': 'test'}))

View File

@@ -397,6 +397,41 @@ def test_bad_secret(broker, monkeypatch):
broker.delete_queue()
@pytest.mark.django_db
def test_attempt_count(broker, monkeypatch):
monkeypatch.setattr(Conf, 'ATTEMPT_COUNT', 3)
tag = uuid()
task = {'id': tag[1],
'name': tag[0],
'func': 'math.copysign',
'args': (1, -1),
'kwargs': {},
'started': timezone.now(),
'stopped': timezone.now(),
'success': False,
'result': None}
# initial save - no success
save_task(task, broker)
assert Task.objects.filter(id=task['id']).exists()
saved_task = Task.objects.get(id=task['id'])
assert saved_task.attempt_count == 1
sleep(0.5)
# second save
old_stopped = task['stopped']
task['stopped'] = timezone.now()
save_task(task, broker)
saved_task = Task.objects.get(id=task['id'])
assert saved_task.attempt_count == 2
# third save -
task['stopped'] = timezone.now()
save_task(task, broker)
saved_task = Task.objects.get(id=task['id'])
assert saved_task.attempt_count == 3
# task should be removed from queue
assert broker.queue_size() == 0
@pytest.mark.django_db
def test_update_failed(broker):
tag = uuid()