From 827a8ade1e6cac1ab9297a168f52b67b32366191 Mon Sep 17 00:00:00 2001 From: Megan Henning <meganhenning@flywheel.io> Date: Fri, 2 Mar 2018 12:02:22 -0600 Subject: [PATCH] Add tests --- .../python/test_containers.py | 63 ++++++++++++++++--- 1 file changed, 53 insertions(+), 10 deletions(-) diff --git a/tests/integration_tests/python/test_containers.py b/tests/integration_tests/python/test_containers.py index 07352d7a..695c14b1 100644 --- a/tests/integration_tests/python/test_containers.py +++ b/tests/integration_tests/python/test_containers.py @@ -1235,7 +1235,8 @@ def test_fields_list_requests(data_builder, file_form, as_admin): assert not a['files'][0].get('info') -def test_container_delete_tag(data_builder, default_payload, as_root, as_admin, as_user, file_form, api_db): + +def test_container_delete_tag(data_builder, default_payload, as_root, as_admin, as_user, as_drone, file_form, api_db): gear_doc = default_payload['gear']['gear'] gear_doc['inputs'] = {'csv': {'base': 'file'}} gear = data_builder.create_gear(gear=gear_doc) @@ -1245,15 +1246,8 @@ def test_container_delete_tag(data_builder, default_payload, as_root, as_admin, acquisition = data_builder.create_acquisition() collection = data_builder.create_collection() assert as_admin.post('/acquisitions/' + acquisition + '/files', files=file_form('test.csv')).ok - r = as_admin.post('/sessions/' + session + '/analyses', params={'job': 'true'}, json={ - 'analysis': {'label': 'with-job'}, - 'job': { - 'gear_id': gear, - 'inputs': {'csv': {'type': 'acquisition', 'id': acquisition, 'name': 'test.csv'}} - } - }) - assert r.ok - analysis = r.json()['_id'] + assert as_drone.post('/acquisitions/' + acquisition + '/files', files=file_form('test2.csv')).ok + r = as_admin.put('/collections/' + collection, json={ 'contents': {'operation': 'add', 'nodes': [{'level': 'session', '_id': session}]} }) @@ -1263,13 +1257,62 @@ def test_container_delete_tag(data_builder, default_payload, as_root, as_admin, r = as_root.delete('/groups/' + group) assert r.status_code == 400 + # try to delete project without perms + r = as_user.delete('/projects/' + project) + assert r.status_code == 403 + assert r.json()['reason'] == 'permission_denied' + + # try to delete session without perms + r = as_user.delete('/sessions/' + session) + assert r.status_code == 403 + assert r.json()['reason'] == 'permission_denied' + + # try to delete acquisition with perms + r = as_user.delete('/acquisitions/' + acquisition) + assert r.status_code == 403 + assert r.json()['reason'] == 'permission_denied' + + # Add user as rw + r = as_user.get('/users/self') + assert r.ok + uid = r.json()['_id'] + + r = as_admin.post('/projects/' + project + '/permissions', json={ + '_id': uid, + 'access': 'rw' + }) + assert r.ok + # try to delete project without admin perms r = as_user.delete('/projects/' + project) assert r.status_code == 403 + assert r.json()['reason'] == 'permission_denied' + + # try to delete a session with "original data" without admin perms + r = as_user.delete('/sessions/' + session) + assert r.status_code == 403 + assert r.json()['reason'] == 'original_data_present' + + # try to delete an acquisition with "original data" without admin perms + r = as_user.delete('/acquisitions/' + acquisition) + assert r.status_code == 403 + assert r.json()['reason'] == 'original_data_present' + + # Add session level analysis + r = as_admin.post('/sessions/' + session + '/analyses', params={'job': 'true'}, json={ + 'analysis': {'label': 'with-job'}, + 'job': { + 'gear_id': gear, + 'inputs': {'csv': {'type': 'acquisition', 'id': acquisition, 'name': 'test.csv'}} + } + }) + assert r.ok + analysis = r.json()['_id'] # try to delete acquisition referenced by analysis r = as_admin.delete('/acquisitions/' + acquisition) assert r.status_code == 403 + assert r.json()['reason'] == 'analysis_conflict' # try to delete acquisition file referenced by analysis r = as_admin.delete('/acquisitions/' + acquisition + '/files/test.csv') -- GitLab