def testDownloadCollection(self):
        self.client.login(username=self.user)
        pk1 = self.Collection1.pk
        request = self.factory.get("/collections/%s/download" % pk1)
        request.user = self.user
        response = download_collection(request, str(pk1))

        self.assertTrue(len(response.getvalue()))  # If there is something in the response, the file was generated.
        self.assertEqual(response.status_code, 200)
Beispiel #2
0
    def testDownloadCollection(self):
        self.client.login(username=self.user)
        pk1 = self.Collection1.pk
        request = self.factory.get('/collections/%s/download' % pk1)
        request.user = self.user
        response = download_collection(request, str(pk1))

        self.assertTrue(len(response.getvalue(
        )))  # If there is something in the response, the file was generated.
        self.assertEqual(response.status_code, 200)
    def testDownloadCollection(self):
        self.client.login(username=self.user)
        pk1 = self.Collection1.pk
        request = self.factory.get('/collections/%s/download' %pk1)
        request.user = self.user
        response = download_collection(request, str(pk1))

        self.assertTrue(response.streaming_content)
        self.assertEqual(response.status_code, 200)

        zf = zipfile.ZipFile(io.BytesIO(''.join(response.streaming_content)))

        self.assertEqual(len(zf.filelist), 1)  # 1 Atlas
        self.assertIsNone(zf.testzip())
        self.assertIn("Collection1/VentralFrontal_thr75_summaryimage_2mm.nii.gz", zf.namelist())
Beispiel #4
0
    def testDownloadCollection(self):
        self.client.login(username=self.user)
        pk1 = self.Collection1.pk
        request = self.factory.get('/collections/%s/download' %pk1)
        request.user = self.user
        response = download_collection(request, str(pk1))

        self.assertTrue(response.streaming_content)
        self.assertEqual(response.status_code, 200)

        zf = zipfile.ZipFile(io.BytesIO(''.join(response.streaming_content)))

        self.assertEqual(len(zf.filelist), 1)  # 1 Atlas
        self.assertIsNone(zf.testzip())
        self.assertIn("Collection1/VentralFrontal_thr75_summaryimage_2mm.nii.gz", zf.namelist())
Beispiel #5
0
    def testDownloadCollection_NIDM_results(self):

        collection = Collection(owner=self.user, name="Collection2")
        collection.save()

        # Upload NIMDResult zip file
        zip_file = open(
            os.path.join(TEST_PATH, 'test_data/nidm/auditory.nidm.zip'), 'rb')
        post_dict = {
            'name': 'auditory',
            'description': '{0} upload test'.format('spm_auditory_v1.2.0'),
            'collection': collection.pk,
        }
        fname = os.path.basename(
            os.path.join(TEST_PATH, 'test_data/nidm/auditory.nidm.zip'))
        file_dict = {'zip_file': SimpleUploadedFile(fname, zip_file.read())}
        form = NIDMResultsForm(post_dict, file_dict)
        form.save()

        # Upload Statistic Map
        image = save_statmap_form(image_path=os.path.join(
            TEST_PATH, 'test_data/statmaps/all.nii.gz'),
                                  collection=collection,
                                  image_name="all.nii.gz")

        factory = RequestFactory()
        self.client.login(username=self.user)
        request = factory.get('/collections/%s/download' % collection.pk,
                              {'format': 'img.zip'})
        request.user = self.user
        response = download_collection(request, str(collection.pk))

        self.assertTrue(response.streaming_content)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get('Content-Disposition'),
                         "attachment; filename=" + collection.name + ".zip")

        zf = zipfile.ZipFile(io.BytesIO(''.join(response.streaming_content)))

        self.assertEqual(len(zf.filelist), 2)  # 1 NIDMResult, 1 Statmap
        self.assertIsNone(zf.testzip())
        self.assertIn("Collection2/all.nii.gz", zf.namelist())
        self.assertIn("Collection2/auditory.nidm.zip", zf.namelist())
Beispiel #6
0
    def testDownloadCollection_NIDM_results(self):

        collection = Collection(owner=self.user, name="Collection2")
        collection.save()

        # Upload NIMDResult zip file
        zip_file = open(os.path.join(TEST_PATH, 'test_data/nidm/auditory.nidm.zip'), 'rb')
        post_dict = {
            'name': 'auditory',
            'description': '{0} upload test'.format('spm_auditory_v1.2.0'),
            'collection': collection.pk,
        }
        fname = os.path.basename(os.path.join(TEST_PATH, 'test_data/nidm/auditory.nidm.zip'))
        file_dict = {
            'zip_file': SimpleUploadedFile(fname, zip_file.read())}
        form = NIDMResultsForm(post_dict, file_dict)
        form.save()

        # Upload Statistic Map
        image = save_statmap_form(image_path=os.path.join(TEST_PATH, 'test_data/statmaps/all.nii.gz'),
                                   collection=collection,
                                   image_name="all.nii.gz")

        factory = RequestFactory()
        self.client.login(username=self.user)
        request = factory.get('/collections/%s/download' % collection.pk, {'format': 'img.zip'})
        request.user = self.user
        response = download_collection(request, str(collection.pk))

        self.assertTrue(response.streaming_content)
        self.assertEqual(response.status_code, 200)
        self.assertEqual(response.get('Content-Disposition'), "attachment; filename=" + collection.name + ".zip")

        zf = zipfile.ZipFile(io.BytesIO(''.join(response.streaming_content)))

        self.assertEqual(len(zf.filelist),2)  # 1 NIDMResult, 1 Statmap
        self.assertIsNone(zf.testzip())
        self.assertIn("Collection2/all.nii.gz", zf.namelist())
        self.assertIn("Collection2/auditory.nidm.zip", zf.namelist())