From d20b81e4048d2cbb44aee5ef4793b6533be620fe Mon Sep 17 00:00:00 2001 From: Harsha Kethineni Date: Tue, 1 Aug 2017 12:47:55 -0500 Subject: [PATCH] tests added to show download filters working --- .../integration_tests/python/test_download.py | 64 +++++++++++++++++++ 1 file changed, 64 insertions(+) diff --git a/test/integration_tests/python/test_download.py b/test/integration_tests/python/test_download.py index 15b548dc9..b2dcc6d50 100644 --- a/test/integration_tests/python/test_download.py +++ b/test/integration_tests/python/test_download.py @@ -293,3 +293,67 @@ def test_analysis_download(data_builder, file_form, as_admin): # get zip member r = as_admin.get(new_analysis_files + '/two.zip', params={'ticket': ticket, 'member': 'two.csv'}) assert r.ok + +def test_filters(data_builder, file_form, as_admin): + + project = data_builder.create_project() + session = data_builder.create_session() + acquisition = data_builder.create_acquisition() + acquisition2 = data_builder.create_acquisition() + + as_admin.post('/acquisitions/' + acquisition + '/files', files=file_form( + "test.csv", meta={'name': "test.csv", 'type': 'csv', 'tags': ['red', 'blue']})) + as_admin.post('/acquisitions/' + acquisition + '/files', files=file_form( + 'test.dicom', meta={'name': 'test.dicom', 'type': 'dicom', 'tags': ['red']})) + as_admin.post('/acquisitions/' + acquisition2 + '/files', files=file_form( + 'test.nifti', meta={'name': 'test.nifti', 'type': 'nifti'})) + r = as_admin.get('/acquisitions/' + acquisition) + assert r.ok + + # Malformed filters + r = as_admin.post('/download', json={ + 'optional': False, + 'filters': [ + {'tags': 'red'} + ], + 'nodes': [ + {'level': 'session', '_id': session}, + ] + }) + assert r.status_code == 400 + + # No filters + r = as_admin.post('/download', json={ + 'optional': False, + 'nodes': [ + {'level': 'session', '_id': session}, + ] + }) + assert r.ok + assert r.json()['file_cnt'] == 3 + + # Filter by tags + r = as_admin.post('/download', json={ + 'optional': False, + 'filters': [ + {'tags': {'+':['red']}} + ], + 'nodes': [ + {'level': 'session', '_id': session}, + ] + }) + assert r.ok + assert r.json()['file_cnt'] == 2 + + # Filter by type + r = as_admin.post('/download', json={ + 'optional': False, + 'filters': [ + {'types': {'+':['nifti']}} + ], + 'nodes': [ + {'level': 'session', '_id': session}, + ] + }) + assert r.ok + assert r.json()['file_cnt'] == 1