Skip to content

Commit

Permalink
Merge pull request #884 from scitran/download-filter
Browse files Browse the repository at this point in the history
Tests added to show download filters working
  • Loading branch information
hkethi002 authored Aug 4, 2017
2 parents e4fbd1c + d20b81e commit 3e273f6
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions test/integration_tests/python/test_download.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 3e273f6

Please sign in to comment.