diff --git a/nomad/client/__init__.py b/nomad/client/__init__.py index 250bc3b374f96f315572a6ddad88f14f4ae11992..dad12c28eb36e0e77e4f340d33fc4e0a009379a9 100644 --- a/nomad/client/__init__.py +++ b/nomad/client/__init__.py @@ -16,5 +16,5 @@ Swagger/bravado based python client library for the API and various usefull shell commands. """ -from . import local, migration, misc, upload +from . import local, migration, misc, upload, integrationtests from .main import cli, create_client diff --git a/nomad/client/integrationtests.py b/nomad/client/integrationtests.py new file mode 100644 index 0000000000000000000000000000000000000000..3cc64b3bf03740cd5f3d076c94d408b9477a7230 --- /dev/null +++ b/nomad/client/integrationtests.py @@ -0,0 +1,76 @@ +# Copyright 2018 Markus Scheidgen +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an"AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +""" +A command that runs some example operations on a working nomad@FAIRDI installation +as a final integration test. +""" + +import time + +from .main import cli + + +example_file = 'tests/data/proc/examples_vasp.zip' + + +@cli.command(help='Runs a few example operations as a test.') +def integrationtests(): + from .main 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 + + def get_upload(): + return client.uploads.get_upload(upload_id=upload.upload_id, per_page=100).response().result + + print('observe the upload process to be finished') + upload = get_upload() + while upload.tasks_running: + time.sleep(0.3) + upload = get_upload() + + assert upload.tasks_status == 'SUCCESS' + total = upload.calcs.pagination.total + assert 100 > total > 0 + assert len(upload.calcs.results) == total + + 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['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() + + 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() + + print('perform search on data') + search = client.repo.get_calcs(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) + while upload.process_running: + upload = client.uploads.get_upload(upload_id=upload.upload_id).response().result + + # TODO publish upload + # TODO admin delete published upload -- this functionality does not yet exist diff --git a/tests/data/test_coe_uploads.sh b/tests/data/test_coe_uploads.sh deleted file mode 100755 index d3b03217997e3afe31c77c53e7d588b98fb658bc..0000000000000000000000000000000000000000 --- a/tests/data/test_coe_uploads.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh -python nomad/client.py /nomad/nomadlab/raw-data/data/ReU/ReUaDKWQVZ55N8aJqgQr48Uiljy1z.zip -python nomad/client.py /nomad/nomadlab/raw-data/data/R--/R--24XOABhczATS4I5QIDg-0MXd_8.zip -python nomad/client.py /nomad/nomadlab/raw-data/data/R-1/R-173P-ju6WxRSCnbb1eAL3gO0BtF.zip -python nomad/client.py /nomad/nomadlab/raw-data/data/R2V/R2VndW9osqfkbNZXN0ETXe8Jo8WYj.zip -python nomad/client.py /nomad/nomadlab/raw-data/data/R6J/R6JYXAnfqhWvN329Pniz0Zg6OUTIm.zip \ No newline at end of file diff --git a/tests/data/test_coe_uploads.txt b/tests/data/test_coe_uploads.txt new file mode 100755 index 0000000000000000000000000000000000000000..7b07d3ab2ce4f20a3e2c41be2c8d6f5729047882 --- /dev/null +++ b/tests/data/test_coe_uploads.txt @@ -0,0 +1,5 @@ +/nomad/nomadlab/raw-data/data/ReU/ReUaDKWQVZ55N8aJqgQr48Uiljy1z.zip +/nomad/nomadlab/raw-data/data/R--/R--24XOABhczATS4I5QIDg-0MXd_8.zip +/nomad/nomadlab/raw-data/data/R-1/R-173P-ju6WxRSCnbb1eAL3gO0BtF.zip +/nomad/nomadlab/raw-data/data/R2V/R2VndW9osqfkbNZXN0ETXe8Jo8WYj.zip +/nomad/nomadlab/raw-data/data/R6J/R6JYXAnfqhWvN329Pniz0Zg6OUTIm.zip \ No newline at end of file