From 62e7abddfa42db2ab1b596db80e9bee82496b03d Mon Sep 17 00:00:00 2001 From: Harsha Kethineni Date: Mon, 19 Mar 2018 16:16:37 -0500 Subject: [PATCH] route file download and info to contain slashes --- api/api.py | 6 +-- .../python/test_access_log.py | 2 +- .../python/test_containers.py | 40 +++++++++---------- 3 files changed, 24 insertions(+), 24 deletions(-) diff --git a/api/api.py b/api/api.py index db7a9dc70..31db2048e 100644 --- a/api/api.py +++ b/api/api.py @@ -41,7 +41,7 @@ 'tag': '[^/]{1,32}', # Filename - 'fname': '[^/]+', + 'fname': '.+', # Note ID 'nid': '[0-9a-f]{24}', @@ -272,9 +272,9 @@ def prefix(path, routes): route('/packfile', FileListHandler, h='packfile', m=['POST']), route('/packfile-end', FileListHandler, h='packfile_end'), route('/', FileListHandler, m=['POST']), + route('//info/', FileListHandler, h='get_info', m=['GET']), + route('//info/', FileListHandler, h='modify_info', m=['POST']), route('//', FileListHandler, m=['GET', 'PUT', 'DELETE']), - route('///info', FileListHandler, h='get_info', m=['GET']), - route('///info', FileListHandler, h='modify_info', m=['POST']), route( '//analyses', AnalysesHandler, h='get_all', m=['GET']), route( '/analyses', AnalysesHandler, h='get_all', m=['GET']), diff --git a/tests/integration_tests/python/test_access_log.py b/tests/integration_tests/python/test_access_log.py index b690b1bae..31a538c9d 100644 --- a/tests/integration_tests/python/test_access_log.py +++ b/tests/integration_tests/python/test_access_log.py @@ -256,7 +256,7 @@ def test_access_log_succeeds(data_builder, as_admin, log_db): log_records_count_before = log_db.access_log.count({}) - r = as_admin.get('/projects/' + project + '/files/' + file_name + '/info') + r = as_admin.get('/projects/' + project + '/files/info/' + file_name) assert r.ok assert r.json()['name'] == file_name diff --git a/tests/integration_tests/python/test_containers.py b/tests/integration_tests/python/test_containers.py index dc11cfda1..00bd3d92f 100644 --- a/tests/integration_tests/python/test_containers.py +++ b/tests/integration_tests/python/test_containers.py @@ -612,7 +612,7 @@ def test_edit_file_attributes(data_builder, as_admin, file_form): assert as_admin.put('/projects/' + project + '/files/' + file_name, json=payload).ok - r = as_admin.get('/projects/' + project + '/files/' + file_name + '/info') + r = as_admin.get('/projects/' + project + '/files/info/' + file_name) assert r.ok file_object = r.json() @@ -786,33 +786,33 @@ def test_edit_file_info(data_builder, as_admin, file_form): # Assert getting file info 404s properly - r = as_admin.get('/projects/' + project + '/files/' + 'not_real.txt' + '/info') + r = as_admin.get('/projects/' + project + '/files/info/' + 'not_real.txt') assert r.status_code == 404 - r = as_admin.get('/projects/' + '000000000000000000000000' + '/files/' + 'not_real.txt' + '/info') + r = as_admin.get('/projects/' + '000000000000000000000000' + '/files/info/' + 'not_real.txt') assert r.status_code == 404 r = as_admin.post('/projects/' + project + '/files', files=file_form(file_name)) assert r.ok - r = as_admin.get('/projects/' + project + '/files/' + file_name + '/info') + r = as_admin.get('/projects/' + project + '/files/info/' + file_name) assert r.ok assert r.json()['info'] == {} # Send improper payload - r = as_admin.post('/projects/' + project + '/files/' + file_name + '/info', json={ + r = as_admin.post('/projects/' + project + '/files/info/' + file_name, json={ 'delete': ['map'], 'replace': {'not_going': 'to_happen'} }) assert r.status_code == 400 # Send improper payload - r = as_admin.post('/projects/' + project + '/files/' + file_name + '/info', json={ + r = as_admin.post('/projects/' + project + '/files/info/' + file_name, json={ 'delete': {'a': 'map'}, }) assert r.status_code == 400 # Send improper payload - r = as_admin.post('/projects/' + project + '/files/' + file_name + '/info', json={ + r = as_admin.post('/projects/' + project + '/files/info/' + file_name, json={ 'set': 'cannot do this', }) assert r.status_code == 400 @@ -828,60 +828,60 @@ def test_edit_file_info(data_builder, as_admin, file_form): } - r = as_admin.post('/projects/' + project + '/files/' + file_name + '/info', json={ + r = as_admin.post('/projects/' + project + '/files/info/' + file_name, json={ 'replace': file_info }) assert r.ok - r = as_admin.get('/projects/' + project + '/files/' + file_name + '/info') + r = as_admin.get('/projects/' + project + '/files/info/' + file_name) assert r.ok assert r.json()['info'] == file_info # Use 'set' to add new key - r = as_admin.post('/projects/' + project + '/files/' + file_name + '/info', json={ + r = as_admin.post('/projects/' + project + '/files/info/' + file_name, json={ 'set': {'map': 'no longer a map'} }) assert r.ok file_info['map'] = 'no longer a map' - r = as_admin.get('/projects/' + project + '/files/' + file_name + '/info') + r = as_admin.get('/projects/' + project + '/files/info/' + file_name) assert r.ok assert r.json()['info'] == file_info # Use 'set' to do full replace of "map" key - r = as_admin.post('/projects/' + project + '/files/' + file_name + '/info', json={ + r = as_admin.post('/projects/' + project + '/files/info/' + file_name, json={ 'set': {'map': 'no longer a map'} }) assert r.ok file_info['map'] = 'no longer a map' - r = as_admin.get('/projects/' + project + '/files/' + file_name + '/info') + r = as_admin.get('/projects/' + project + '/files/info/' + file_name) assert r.ok assert r.json()['info'] == file_info # Use 'delete' to unset "map" key - r = as_admin.post('/projects/' + project + '/files/' + file_name + '/info', json={ + r = as_admin.post('/projects/' + project + '/files/info/' + file_name, json={ 'delete': ['map', 'a'] }) assert r.ok file_info.pop('map') file_info.pop('a') - r = as_admin.get('/projects/' + project + '/files/' + file_name + '/info') + r = as_admin.get('/projects/' + project + '/files/info/' + file_name) assert r.ok assert r.json()['info'] == file_info # Use 'delete' on keys that do not exist - r = as_admin.post('/projects/' + project + '/files/' + file_name + '/info', json={ + r = as_admin.post('/projects/' + project + '/files/info/' + file_name, json={ 'delete': ['madeup', 'keys'] }) assert r.ok - r = as_admin.get('/projects/' + project + '/files/' + file_name + '/info') + r = as_admin.get('/projects/' + project + '/files/info/' + file_name) assert r.ok assert r.json()['info'] == file_info @@ -895,7 +895,7 @@ def test_edit_file_info(data_builder, as_admin, file_form): # Add reserved key and ensure it is returned BIDS_map = {'BIDS':{'project_label': 'TEST'}} - r = as_admin.post('/projects/' + project + '/files/' + file_name + '/info', json={ + r = as_admin.post('/projects/' + project + '/files/info/' + file_name, json={ 'set': BIDS_map }) assert r.ok @@ -909,12 +909,12 @@ def test_edit_file_info(data_builder, as_admin, file_form): # Use 'replace' to set file info to {} - r = as_admin.post('/projects/' + project + '/files/' + file_name + '/info', json={ + r = as_admin.post('/projects/' + project + '/files/info/' + file_name, json={ 'replace': {} }) assert r.ok - r = as_admin.get('/projects/' + project + '/files/' + file_name + '/info') + r = as_admin.get('/projects/' + project + '/files/info/' + file_name) assert r.ok assert r.json()['info'] == {}