Commit 5579c76e authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Unstaging will add the data to the legace nomad coe repository db.

parent 876069cc
......@@ -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
......
......@@ -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):
......
......@@ -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,
......
......@@ -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):
......
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)
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