diff --git a/tests/integration_tests/python/test_migrate_storage.py b/tests/integration_tests/python/test_migrate_storage.py index 5cc179984..6695d9f38 100644 --- a/tests/integration_tests/python/test_migrate_storage.py +++ b/tests/integration_tests/python/test_migrate_storage.py @@ -310,3 +310,85 @@ def mocked(*args, **kwargs): assert config.fs.exists(util.path_from_uuid(file_2_id)) assert any(log.message == 'Probably the following file has been updated during the migration and its hash is changed, cleaning up from the new filesystem' for log in caplog.records) + + +def test_migrate_analysis(files_to_migrate, as_admin, migrate_storage, default_payload, data_builder, file_form): + """Testing analysis migration""" + + # get file storing by hash in legacy storage + (project_id, file_name_1, url_1, file_path_1) = files_to_migrate[0] + # get ile storing by uuid in legacy storage + (_, _,url_2, file_path_2) = files_to_migrate[1] + + gear_doc = default_payload['gear']['gear'] + gear_doc['inputs'] = { + 'csv': { + 'base': 'file' + } + } + gear = data_builder.create_gear(gear=gear_doc) + + # create project analysis (job) using project's file as input + r = as_admin.post('/projects/' + project_id + '/analyses', params={'job': 'true'}, json={ + 'analysis': {'label': 'test analysis job'}, + 'job': { + 'gear_id': gear, + 'inputs': { + 'csv': { + 'type': 'projects', + 'id': project_id, + 'name': file_name_1 + } + }, + 'tags': ['example'] + } + }) + assert r.ok + analysis_id1 = r.json()['_id'] + + r = as_admin.get('/projects/' + project_id + '/analyses/' + analysis_id1) + assert r.ok + analysis_files1 = '/projects/' + project_id + '/analyses/' + analysis_id1 + '/files' + + # run the migration + migrate_storage.migrate_containers() + + # delete files from the legacy storage + config.legacy_fs.remove(file_path_1) + config.legacy_fs.remove(file_path_2) + + # get the files from the new filesystem + # get the ticket + r = as_admin.get(url_1, params={'ticket': ''}) + assert r.ok + ticket = r.json()['ticket'] + + # download the file + assert as_admin.get(url_1, params={'ticket': ticket}).ok + + # get the ticket + r = as_admin.get(url_2, params={'ticket': ''}) + assert r.ok + ticket = r.json()['ticket'] + + # download the file + assert as_admin.get(url_2, params={'ticket': ticket}).ok + + # get analysis download ticket for single file + r = as_admin.get(analysis_files1 + '/' + file_name_1, params={'ticket': ''}) + assert r.ok + ticket = r.json()['ticket'] + + # download single analysis file w/ ticket + r = as_admin.get(analysis_files1 + '/' + file_name_1, params={'ticket': ticket}) + assert r.ok + + r = as_admin.get('/projects/' + project_id + '/analyses/' + analysis_id1) + assert r.ok + input_file_id = r.json()['files'][0]['_id'] + + r = as_admin.get('/projects/' + project_id) + assert r.ok + project_file_id = r.json()['files'][0]['_id'] + + assert input_file_id == project_file_id