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

Added support for POTCAR files with ending.

parent 6d178e9d
......@@ -80,7 +80,8 @@ def always_restricted(path: str):
Used to put general restrictions on files, e.g. due to licensing issues. Will be
called during packing and while accessing public files.
"""
if os.path.basename(path) == 'POTCAR':
basename = os.path.basename(path)
if basename.startswith('POTCAR') and not basename.endswith('.stripped'):
return True
......
......@@ -767,7 +767,7 @@ class Upload(Proc):
Some files need preprocessing. Currently we need to add a stripped POTCAR version
and always restrict/embargo the original.
"""
if os.path.basename(path) == 'POTCAR':
if os.path.basename(path).startswith('POTCAR'):
# create checksum
hash = hashlib.sha224()
with open(self.staging_upload_files.raw_file_object(path).os_path, 'rb') as orig_f:
......
......@@ -490,20 +490,23 @@ class TestUploads:
# content_type='application/json')
# assert rv.status_code == 400
def test_potcar(self, api, proc_infra, test_user_auth):
@pytest.mark.parametrize('upload_file, ending', [
('examples_potcar.zip', ''),
('examples_potcar_gz.tgz', '.gz')])
def test_potcar(self, api, proc_infra, test_user_auth, upload_file, ending):
# only the owner, shared with people are supposed to download the original potcar file
example_file = 'tests/data/proc/examples_potcar.zip'
example_file = 'tests/data/proc/%s' % upload_file
rv = api.put('/uploads/?local_path=%s' % example_file, headers=test_user_auth)
upload = self.assert_upload(rv.data)
upload_id = upload['upload_id']
self.assert_processing(api, test_user_auth, upload_id)
self.assert_published(api, test_user_auth, upload_id, proc_infra, with_coe_repo=True)
rv = api.get('/raw/%s/examples_potcar/POTCAR' % upload_id)
rv = api.get('/raw/%s/examples_potcar/POTCAR%s' % (upload_id, ending))
assert rv.status_code == 401
rv = api.get('/raw/%s/examples_potcar/POTCAR' % upload_id, headers=test_user_auth)
rv = api.get('/raw/%s/examples_potcar/POTCAR%s' % (upload_id, ending), headers=test_user_auth)
assert rv.status_code == 200
rv = api.get('/raw/%s/examples_potcar/POTCAR.stripped' % upload_id)
rv = api.get('/raw/%s/examples_potcar/POTCAR%s.stripped' % (upload_id, ending))
assert rv.status_code == 200
......
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