Commit ad793848 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added tasks_status parameters to uploads reset CLI command.

parent d8840320
Pipeline #102427 passed with stages
in 24 minutes and 16 seconds
......@@ -267,8 +267,10 @@ def chown(ctx, username, uploads):
@uploads.command(help='Reset the processing state.')
@click.argument('UPLOADS', nargs=-1)
@click.option('--with-calcs', is_flag=True, help='Also reset all calculations.')
@click.option('--success', is_flag=True, help='Set the tasks status to success instead of pending')
@click.option('--failure', is_flag=True, help='Set the tasks status to failure instead of pending.')
def reset(ctx, uploads, with_calcs):
def reset(ctx, uploads, with_calcs, success, failure):
_, uploads = query_uploads(ctx, uploads)
uploads_count = uploads.count()
......@@ -276,12 +278,22 @@ def reset(ctx, uploads, with_calcs):
i = 0
for upload in uploads:
{'$set': proc.Calc.reset_pymongo_update()})
if with_calcs:
calc_update = proc.Calc.reset_pymongo_update()
if success:
calc_update['tasks_status'] = proc.SUCCESS
if failure:
calc_update['tasks_status'] = proc.FAILURE
dict(upload_id=upload.upload_id), {'$set': calc_update})
upload.process_status = None
if success:
upload.tasks_status = proc.SUCCESS
if failure:
upload.tasks_status = proc.FAILURE
i += 1
print('resetted %d of %d uploads' % (i, uploads_count))
......@@ -307,19 +307,39 @@ class TestAdminUploads:
perform_test(True, False)
perform_test(True, True)
def test_reset(self, non_empty_processed):
@pytest.mark.parametrize('with_calcs,success,failure', [
(True, False, False),
(False, False, False),
(True, True, False),
(False, False, True)])
def test_reset(self, non_empty_processed, with_calcs, success, failure):
upload_id = non_empty_processed.upload_id
result = click.testing.CliRunner().invoke(
cli, ['admin', 'uploads', 'reset', '--with-calcs', upload_id], catch_exceptions=False)
upload = Upload.objects(upload_id=upload_id).first()
calc = Calc.objects(upload_id=upload_id).first()
assert upload.tasks_status == proc.SUCCESS
assert calc.tasks_status == proc.SUCCESS
args = ['admin', 'uploads', 'reset']
if with_calcs: args.append('--with-calcs')
if success: args.append('--success')
if failure: args.append('--failure')
result = click.testing.CliRunner().invoke(cli, args, catch_exceptions=False)
assert result.exit_code == 0
assert 'reset' in result.stdout
upload = Upload.objects(upload_id=upload_id).first()
calc = Calc.objects(upload_id=upload_id).first()
assert upload.tasks_status == proc.PENDING
assert calc.tasks_status == proc.PENDING
expected_state = proc.PENDING
if success: expected_state = proc.SUCCESS
if failure: expected_state = proc.FAILURE
assert upload.tasks_status == expected_state
if not with_calcs:
assert calc.tasks_status == proc.SUCCESS
assert calc.tasks_status == expected_state
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment