Skip to content

Commit

Permalink
route file download and info to contain slashes
Browse files Browse the repository at this point in the history
  • Loading branch information
hkethi002 committed Mar 19, 2018
1 parent 6342cc4 commit 62e7abd
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 24 deletions.
6 changes: 3 additions & 3 deletions api/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
'tag': '[^/]{1,32}',

# Filename
'fname': '[^/]+',
'fname': '.+',

# Note ID
'nid': '[0-9a-f]{24}',
Expand Down Expand Up @@ -272,9 +272,9 @@ def prefix(path, routes):
route('/packfile', FileListHandler, h='packfile', m=['POST']),
route('/packfile-end', FileListHandler, h='packfile_end'),
route('/<list_name:files>', FileListHandler, m=['POST']),
route('/<list_name:files>/info/<name:{fname}>', FileListHandler, h='get_info', m=['GET']),
route('/<list_name:files>/info/<name:{fname}>', FileListHandler, h='modify_info', m=['POST']),
route('/<list_name:files>/<name:{fname}>', FileListHandler, m=['GET', 'PUT', 'DELETE']),
route('/<list_name:files>/<name:{fname}>/info', FileListHandler, h='get_info', m=['GET']),
route('/<list_name:files>/<name:{fname}>/info', FileListHandler, h='modify_info', m=['POST']),

route( '/<sub_cont_name:{cname}|all>/analyses', AnalysesHandler, h='get_all', m=['GET']),
route( '/analyses', AnalysesHandler, h='get_all', m=['GET']),
Expand Down
2 changes: 1 addition & 1 deletion tests/integration_tests/python/test_access_log.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
40 changes: 20 additions & 20 deletions tests/integration_tests/python/test_containers.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand All @@ -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

Expand All @@ -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
Expand All @@ -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'] == {}

Expand Down

0 comments on commit 62e7abd

Please sign in to comment.