diff --git a/nomad/api/app.py b/nomad/api/app.py index 947e82eddefcd26b0431ffdbd59fc9edcfa45c36..e0d2782968fd07616b60c99be7e28787256906db 100644 --- a/nomad/api/app.py +++ b/nomad/api/app.py @@ -51,7 +51,8 @@ api = Api(app) @app.before_first_request def setup(): - infrastructure.setup() + if not api.app.config['TESTING']: + infrastructure.setup() @auth.verify_password diff --git a/nomad/files.py b/nomad/files.py index 6f0af85c1338f2305a323308f7b0ef8f0188252f..984b4fec3fc5e7c9d8a888b80e254eb6a02c86fc 100644 --- a/nomad/files.py +++ b/nomad/files.py @@ -653,7 +653,6 @@ class ZippedDataContainer(File, DataContainer): else: tags[name].append(value) - print(tags) return BaggedDataContainer._load_bagit_metadata(tags) def get_file(self, path): diff --git a/nomad/processing/data.py b/nomad/processing/data.py index 7544807874ad760fdcd01ca4d71da0cb57c809df..8d5d8c141b0e1c72d48f18fba57e711367eae2f5 100644 --- a/nomad/processing/data.py +++ b/nomad/processing/data.py @@ -444,7 +444,7 @@ class Upload(Chord): self.get_logger().info('unstage') self.in_staging = False RepoCalc.unstage(upload_id=self.upload_id) - # coe_repo.add_upload(self, restricted=False) # TODO allow users to choose restricted + coe_repo.add_upload(self, restricted=False) # TODO allow users to choose restricted self.save() @property @@ -455,6 +455,7 @@ class Upload(Chord): 'local_path': self.local_path, 'additional_metadata': self.additional_metadata, 'upload_id': self.upload_id, + 'upload_hash': self.upload_hash, 'upload_url': self.upload_url, 'upload_command': self.upload_command, 'upload_time': self.upload_time.isoformat() if self.upload_time is not None else None, diff --git a/tests/test_api.py b/tests/test_api.py index e68e43ed5226601c388e6bf668951bfe3f6fed48..fc973cc551196c7ac98d2572b08528b23cd96438 100644 --- a/tests/test_api.py +++ b/tests/test_api.py @@ -29,6 +29,7 @@ from tests.test_files import clear_files, archive, archive_log, archive_config from tests.test_normalizing import normalized_template_example # noqa pylint: disable=unused-import from tests.test_parsing import parsed_template_example # noqa pylint: disable=unused-import from tests.test_repo import example_elastic_calc # noqa pylint: disable=unused-import +from tests.test_coe_repo import assert_coe_upload # noqa @pytest.fixture(scope='function') @@ -166,7 +167,7 @@ def test_delete_empty_upload(client, mocksearch, test_user_auth, no_warn): assert rv.status_code == 404 -def assert_processing(client, test_user_auth, upload_id): +def assert_processing(client, test_user_auth, upload_id, repository_db): upload_endpoint = '/uploads/%s' % upload_id while True: @@ -190,6 +191,8 @@ def assert_processing(client, test_user_auth, upload_id): assert len(calc['tasks']) == 3 assert client.get('/logs/%s' % calc['archive_id']).status_code == 200 + empty_upload = upload['calcs']['pagination']['total'] == 0 + if upload['calcs']['pagination']['total'] > 1: rv = client.get('%s?page=2&per_page=1&order_by=status' % upload_endpoint) assert rv.status_code == 200 @@ -206,12 +209,13 @@ def assert_processing(client, test_user_auth, upload_id): rv = client.get('/uploads', headers=test_user_auth) assert rv.status_code == 200 assert_uploads(rv.data, count=0) + assert_coe_upload(upload['upload_hash'], repository_db, empty=empty_upload) @pytest.mark.parametrize('file', example_files) @pytest.mark.parametrize('mode', ['multipart', 'stream']) @pytest.mark.timeout(10) -def test_processing(client, file, mode, worker, mocksearch, test_user_auth, no_warn): +def test_processing(client, file, mode, worker, mocksearch, test_user_auth, no_warn, repository_db): rv = client.post('/uploads', headers=test_user_auth) assert rv.status_code == 200 upload = assert_upload(rv.data) @@ -237,12 +241,12 @@ def test_processing(client, file, mode, worker, mocksearch, test_user_auth, no_w assert rv.status_code == 200 upload = assert_upload(rv.data) - assert_processing(client, test_user_auth, upload_id) + assert_processing(client, test_user_auth, upload_id, repository_db) @pytest.mark.parametrize('file', example_files) @pytest.mark.timeout(10) -def test_processing_local_path(client, file, worker, mocksearch, test_user_auth, no_warn): +def test_processing_local_path(client, file, worker, mocksearch, test_user_auth, no_warn, repository_db): rv = client.post( '/uploads', headers=test_user_auth, data=json.dumps(dict(local_path=file)), @@ -252,7 +256,7 @@ def test_processing_local_path(client, file, worker, mocksearch, test_user_auth, upload = assert_upload(rv.data) upload_id = upload['upload_id'] - assert_processing(client, test_user_auth, upload_id) + assert_processing(client, test_user_auth, upload_id, repository_db) def test_repo_calc(client, example_elastic_calc, no_warn): diff --git a/tests/test_coe_repo.py b/tests/test_coe_repo.py index 3b0602022b9b85e835fe0ebde07804f35cd6cb47..b9220544e9ca9226ab018fb2135a658f1c4b42b6 100644 --- a/tests/test_coe_repo.py +++ b/tests/test_coe_repo.py @@ -1,3 +1,5 @@ +import pytest + from nomad.coe_repo import User, Calc, CalcMetaData, Upload, add_upload from tests.processing.test_data import processed_upload # pylint: disable=unused-import @@ -33,21 +35,26 @@ def test_rollback(repository_db): assert repository_db.query(Calc).filter_by(calc_id=calc_id).first() is None -def assert_upload(coe_upload_id, repository_db): - upload = repository_db.query(Upload).filter_by(upload_id=coe_upload_id).first() - assert upload is not None - for calc in repository_db.query(Calc).filter_by(origin_id=coe_upload_id): - assert calc.origin_id == coe_upload_id - metadata = repository_db.query(CalcMetaData).filter_by(calc_id=calc.calc_id).first() - assert metadata is not None - assert metadata.chemical_formula is not None +def assert_coe_upload(upload_hash, repository_db, empty=False): + coe_upload = repository_db.query(Upload).filter_by(upload_name=upload_hash).first() + if empty: + assert coe_upload is None + else: + assert coe_upload is not None + coe_upload_id = coe_upload.upload_id + for calc in repository_db.query(Calc).filter_by(origin_id=coe_upload_id): + assert calc.origin_id == coe_upload_id + metadata = repository_db.query(CalcMetaData).filter_by(calc_id=calc.calc_id).first() + assert metadata is not None + assert metadata.chemical_formula is not None +@pytest.mark.timeout(10) def test_add_upload(repository_db, processed_upload): coe_upload_id = add_upload(processed_upload, restricted=False) if coe_upload_id: - assert_upload(coe_upload_id, repository_db) + assert_coe_upload(processed_upload.upload_hash, repository_db) coe_upload_id = add_upload(processed_upload, restricted=False) if coe_upload_id: - assert_upload(coe_upload_id, repository_db) + assert_coe_upload(processed_upload.upload_hash, repository_db)