Commit bc0d05a9 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added tests and fixes for local_path uploads in the api.

parent 3a0eaead
......@@ -197,6 +197,14 @@ class UploadsRes(Resource):
name=json_data.get('name'),
local_path=json_data.get('local_path'))
if upload.local_path is not None:
logger = get_logger(
__name__, endpoint='uploads', action='post', upload_id=upload.upload_id)
logger.debug('file already uploaded')
upload.upload_time = datetime.now()
upload.process()
logger.debug('initiated processing')
return upload.json_dict, 200
......
......@@ -24,7 +24,6 @@ from datetime import datetime
import shutil
import os.path
from nomad import config
from nomad.files import UploadFile, ArchiveFile, ArchiveLogFile
from nomad.processing import Upload, Calc
from nomad.processing.base import task as task_decorator
......
......@@ -157,34 +157,8 @@ def test_delete_empty_upload(client, test_user_auth, no_warn):
assert rv.status_code == 404
@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):
rv = client.post('/uploads', headers=test_user_auth)
assert rv.status_code == 200
upload = assert_upload(rv.data)
upload_id = upload['upload_id']
upload_cmd = upload['upload_command']
headers = dict(Authorization='Basic %s' % re.search(r'.*Authorization: Basic ([^\s]+).*', upload_cmd).group(1))
def assert_processing(client, test_user_auth, upload_id):
upload_endpoint = '/uploads/%s' % upload_id
upload_file_endpoint = '%s/file' % upload_endpoint
upload_url = upload['upload_url']
assert upload_url.endswith(upload_file_endpoint)
if mode == 'multipart':
rv = client.put(
upload_file_endpoint,
data=dict(file=(open(file, 'rb'), 'file')),
headers=headers)
elif mode == 'stream':
with open(file, 'rb') as f:
rv = client.put(upload_file_endpoint, data=f.read(), headers=headers)
else:
assert False
assert rv.status_code == 200
upload = assert_upload(rv.data)
while True:
time.sleep(0.1)
......@@ -199,7 +173,7 @@ def test_processing(client, file, mode, worker, mocksearch, test_user_auth, no_w
assert len(upload['tasks']) == 4
assert upload['status'] == 'SUCCESS'
assert upload['current_task'] == 'cleanup'
assert UploadFile(upload['upload_id']).exists()
assert UploadFile(upload['upload_id'], upload.get('local_path')).exists()
calcs = upload['calcs']['results']
for calc in calcs:
assert calc['status'] == 'SUCCESS'
......@@ -225,6 +199,53 @@ def test_processing(client, file, mode, worker, mocksearch, test_user_auth, no_w
assert_uploads(rv.data, count=0)
@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):
rv = client.post('/uploads', headers=test_user_auth)
assert rv.status_code == 200
upload = assert_upload(rv.data)
upload_id = upload['upload_id']
upload_cmd = upload['upload_command']
headers = dict(Authorization='Basic %s' % re.search(r'.*Authorization: Basic ([^\s]+).*', upload_cmd).group(1))
upload_endpoint = '/uploads/%s' % upload_id
upload_file_endpoint = '%s/file' % upload_endpoint
upload_url = upload['upload_url']
assert upload_url.endswith(upload_file_endpoint)
if mode == 'multipart':
rv = client.put(
upload_file_endpoint,
data=dict(file=(open(file, 'rb'), 'file')),
headers=headers)
elif mode == 'stream':
with open(file, 'rb') as f:
rv = client.put(upload_file_endpoint, data=f.read(), headers=headers)
else:
assert False
assert rv.status_code == 200
upload = assert_upload(rv.data)
assert_processing(client, test_user_auth, upload_id)
@pytest.mark.parametrize('file', example_files)
@pytest.mark.timeout(10)
def test_processing_local_path(client, file, worker, mocksearch, test_user_auth, no_warn):
rv = client.post(
'/uploads', headers=test_user_auth,
data=json.dumps(dict(local_path=file)),
content_type='application/json')
assert rv.status_code == 200
upload = assert_upload(rv.data)
upload_id = upload['upload_id']
assert_processing(client, test_user_auth, upload_id)
def test_repo_calc(client, example_elastic_calc, no_warn):
rv = client.get(
'/repo/%s/%s' % (example_elastic_calc.upload_hash, example_elastic_calc.calc_hash))
......
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