diff --git a/nomad/cli/client/integrationtests.py b/nomad/cli/client/integrationtests.py index e1fa43bc32c64475e5b3bf18f773234c13275dc8..0a21dcb1d494647bac7ebe50bc1d7ba97248e147 100644 --- a/nomad/cli/client/integrationtests.py +++ b/nomad/cli/client/integrationtests.py @@ -18,30 +18,50 @@ as a final integration test. """ import time +import os +import click from .client import client -example_file = 'tests/data/proc/examples_vasp.zip' +multi_code_example_file = 'tests/data/integration/multi_code_data.zip' +simple_example_file = 'tests/data/integration/examples_vasp.zip' @client.command(help='Runs a few example operations as a test.') -def integrationtests(): +@click.option( + '--with-publish', is_flag=True, + help='Also publish the upload. Should not be done on an production environment.') +def integrationtests(with_publish): from .client import create_client client = create_client() - print('upload with multiple code data') - with open(example_file, 'rb') as f: - upload = client.uploads.upload(name='integration test upload', file=f).response().result + print('get the upload command') + command = client.uploads.get_upload_command().response().result.upload_command_with_name - def get_upload(): - return client.uploads.get_upload(upload_id=upload.upload_id, per_page=100).response().result + print('upload multi code test data with curl') + command = command.replace('<local_file>', multi_code_example_file) + command = command.replace('<name>', 'integration_test_upload') + command += ' -k' + code = os.system(command) + assert code == 0, 'curl command must be successful' + uploads = client.uploads.get_uploads(name='integration_test_upload').response().result.results + assert len(uploads) == 1, 'exactly one test upload must be on the server' + upload = uploads[0] + + def get_upload(upload): + upload = client.uploads.get_upload( + upload_id=upload.upload_id, per_page=100).response().result + + while upload.tasks_running: + time.sleep(0.3) + upload = client.uploads.get_upload( + upload_id=upload.upload_id, per_page=100).response().result + + return upload print('observe the upload process to be finished') - upload = get_upload() - while upload.tasks_running: - time.sleep(0.3) - upload = get_upload() + upload = get_upload(upload) assert upload.tasks_status == 'SUCCESS' total = upload.calcs.pagination.total @@ -51,26 +71,64 @@ def integrationtests(): try: print('get repo data') for calc in upload.calcs.results: - repo = client.repo.get_repo_calc(upload_id=upload.upload_id, calc_id=calc.calc_id).response().result + repo = client.repo.get_repo_calc( + upload_id=upload.upload_id, calc_id=calc.calc_id).response().result repo['calc_id'] == calc.calc_id print('get archive data') for calc in upload.calcs.results: - client.archive.get_archive_calc(upload_id=upload.upload_id, calc_id=calc.calc_id).response() + client.archive.get_archive_calc( + upload_id=upload.upload_id, calc_id=calc.calc_id).response() print('get archive logs') for calc in upload.calcs.results: - client.archive.get_archive_logs(upload_id=upload.upload_id, calc_id=calc.calc_id).response() + client.archive.get_archive_logs( + upload_id=upload.upload_id, calc_id=calc.calc_id).response() print('perform search on data') search = client.repo.search(owner='staging', per_page=100).response().result assert search.pagination.total >= total assert len(search.results) <= search.pagination.total + finally: print('delete the upload again') client.uploads.delete_upload(upload_id=upload.upload_id).response() while upload.process_running: - upload = client.uploads.get_upload(upload_id=upload.upload_id).response().result + upload = client.uploads.get_upload( + upload_id=upload.upload_id).response().result + + print('upload simple data with API') + with open(simple_example_file, 'rb') as f: + upload = client.uploads.upload( + name='integration test upload', file=f).response().result - # TODO publish upload - # TODO admin delete published upload -- this functionality does not yet exist + print('observe the upload process to be finished') + upload = get_upload(upload) + + if with_publish: + try: + print('publish upload') + client.uploads.exec_upload_operation( + upload_id=upload.upload_id, + payload=dict(operation='publish')).response() + + while upload.process_running: + upload = client.uploads.get_upload( + upload_id=upload.upload_id).response().result + + assert upload.tasks_status == 'SUCCESS', 'publish must be successful' + + except Exception as e: + print('delete the upload after exception') + client.uploads.delete_upload(upload_id=upload.upload_id).response() + while upload.process_running: + upload = client.uploads.get_upload( + upload_id=upload.upload_id).response().result + raise e + + else: + print('delete the upload again') + client.uploads.delete_upload(upload_id=upload.upload_id).response() + while upload.process_running: + upload = client.uploads.get_upload( + upload_id=upload.upload_id).response().result diff --git a/tests/data/integration/examples_vasp.zip b/tests/data/integration/examples_vasp.zip new file mode 100644 index 0000000000000000000000000000000000000000..ae79b3c581238553454744fd6e5e4315849c4cd4 Binary files /dev/null and b/tests/data/integration/examples_vasp.zip differ diff --git a/tests/data/integration/multi_code_data.zip b/tests/data/integration/multi_code_data.zip new file mode 100644 index 0000000000000000000000000000000000000000..0e8f0a752531f974f9c4bb28a72c09469e0c990d Binary files /dev/null and b/tests/data/integration/multi_code_data.zip differ diff --git a/tests/data/parsers/parser_test_data_05_03_2019.zip b/tests/data/parsers/parser_test_data_05_03_2019.zip deleted file mode 100644 index 74c233a475acbca84a13300853aa96fe9a7f7379..0000000000000000000000000000000000000000 Binary files a/tests/data/parsers/parser_test_data_05_03_2019.zip and /dev/null differ