From 7e06aab63e3c85782201653e4ba59f4c75ef51cc Mon Sep 17 00:00:00 2001
From: Harsha Kethineni <harshakethineni@flywheel.io>
Date: Wed, 6 Sep 2017 16:54:42 -0500
Subject: [PATCH] test for #917

---
 .../integration_tests/python/test_download.py | 35 +++++++++++++++++++
 1 file changed, 35 insertions(+)

diff --git a/test/integration_tests/python/test_download.py b/test/integration_tests/python/test_download.py
index 9e675df3..3a722cfb 100644
--- a/test/integration_tests/python/test_download.py
+++ b/test/integration_tests/python/test_download.py
@@ -67,6 +67,41 @@ def test_download(data_builder, file_form, as_admin, api_db):
 
     tar.close()
 
+    # Download one session with many acquisitions and make sure they are in the same subject folder
+
+    acquisition3 = data_builder.create_acquisition(session=session)
+    r = as_admin.post('/acquisitions/' + acquisition3 + '/files', files=file_form(
+        file_name, meta={'name': file_name, 'type': 'csv'}))
+    assert r.ok
+
+    r = as_admin.post('/download', json={
+        'optional': False,
+        'nodes': [
+            {'level': 'acquisition', '_id': acquisition},
+            {'level': 'acquisition', '_id': acquisition3},
+        ]
+    })
+    assert r.ok
+    ticket = r.json()['ticket']
+
+    # Perform the download
+    r = as_admin.get('/download', params={'ticket': ticket})
+    assert r.ok
+
+    tar_file = cStringIO.StringIO(r.content)
+    tar = tarfile.open(mode="r", fileobj=tar_file)
+
+    # Verify a single file in tar with correct file name
+    found_second_session = False 
+    for tarinfo in tar:
+        assert os.path.basename(tarinfo.name) == file_name
+        if 'session1_0' in str(tarinfo.name):
+            found_second_session = True
+    assert not found_second_session
+
+    tar.close()
+
+
     # Try to perform the download from a different IP
     update_result = api_db.downloads.update_one(
         {'_id': ticket},
-- 
GitLab