Commit 695b74f7 authored by Markus Scheidgen's avatar Markus Scheidgen
Browse files

Added fix to deal with data/ prefixed mainfile uri based raw file paths.

parent 0ef1184d
Pipeline #40945 passed with stages
in 14 minutes and 26 seconds
......@@ -32,6 +32,12 @@ from nomad.utils import get_logger
from .app import app, base_path
def fix_file_paths(path):
""" Removed the leading data from file paths that where given in mainfile uris. """
# TODO, mainfile URI's should change or this implementation should change
return path[5:]
@app.route('%s/raw/<string:upload_hash>/<path:upload_filepath>' % base_path, methods=['GET'])
def get_raw_file(upload_hash, upload_filepath):
"""
......@@ -55,6 +61,7 @@ def get_raw_file(upload_hash, upload_filepath):
:status 404: upload with given hash does not exist or the given file does not exist
:returns: the gzipped raw data in the body or a zip file when wildcard was used
"""
upload_filepath = fix_file_paths(upload_filepath)
repository_file = RepositoryFile(upload_hash)
if not repository_file.exists():
......@@ -123,7 +130,7 @@ def get_raw_files(upload_hash):
if files_str is None:
abort(400, message="No files argument given.")
files = [file.strip() for file in files_str.split(',')]
files = [fix_file_paths(file.strip()) for file in files_str.split(',')]
return respond_to_get_raw_files(upload_hash, files, compress)
......@@ -164,7 +171,7 @@ def get_raw_files_post(upload_hash):
compress = json_data.get('compress', False)
if not isinstance(compress, bool):
abort(400, message='Compress value %s is not a bool.' % str(compress))
files = [file.strip() for file in json_data['files']]
files = [fix_file_paths(file.strip()) for file in json_data['files']]
return respond_to_get_raw_files(upload_hash, files, compress)
......
......@@ -407,7 +407,7 @@ class TestRaw:
return upload_hash
def test_raw_file(self, client, example_upload_hash):
url = '/raw/%s/%s' % (example_upload_hash, example_file_mainfile)
url = '/raw/%s/data/%s' % (example_upload_hash, example_file_mainfile)
rv = client.get(url)
assert rv.status_code == 200
assert len(rv.data) > 0
......@@ -420,7 +420,7 @@ class TestRaw:
assert 'files' not in data
def test_raw_file_listing(self, client, example_upload_hash):
url = '/raw/%s/examples' % example_upload_hash
url = '/raw/%s/data/examples' % example_upload_hash
rv = client.get(url)
assert rv.status_code == 404
data = json.loads(rv.data)
......@@ -428,7 +428,7 @@ class TestRaw:
@pytest.mark.parametrize('compress', [True, False])
def test_raw_file_wildcard(self, client, example_upload_hash, compress):
url = '/raw/%s/examples*' % example_upload_hash
url = '/raw/%s/data/examples*' % example_upload_hash
if compress:
url = '%s?compress=1' % url
rv = client.get(url)
......@@ -452,7 +452,7 @@ class TestRaw:
@pytest.mark.parametrize('compress', [True, False])
def test_raw_files(self, client, example_upload_hash, compress):
url = '/raw/%s?files=%s' % (
example_upload_hash, ','.join(example_file_contents))
example_upload_hash, ','.join(['data/%s' % file for file in example_file_contents]))
if compress:
url = '%s&compress=1' % url
rv = client.get(url)
......@@ -466,7 +466,7 @@ class TestRaw:
@pytest.mark.parametrize('compress', [True, False, None])
def test_raw_files_post(self, client, example_upload_hash, compress):
url = '/raw/%s' % example_upload_hash
data = dict(files=example_file_contents)
data = dict(files=['data/%s' % file for file in example_file_contents])
if compress is not None:
data.update(compress=compress)
rv = client.post(url, data=json.dumps(data), content_type='application/json')
......@@ -479,7 +479,7 @@ class TestRaw:
@pytest.mark.parametrize('compress', [True, False])
def test_raw_files_missing_file(self, client, example_upload_hash, compress):
url = '/raw/%s?files=%s,missing/file.txt' % (example_upload_hash, example_file_mainfile)
url = '/raw/%s?files=data/%s,missing/file.txt' % (example_upload_hash, example_file_mainfile)
if compress:
url = '%s&compress=1' % url
rv = client.get(url)
......
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