示例#1
0
    def test_prepare_data_sample_zip_fail(self):

        data_sample = DataSample(key=uuid.uuid4(),
                                 path=self.data_sample_filename)
        data_sample.save()

        subtuple = {'key': 'bar', 'dataset': {'data_sample_keys': ['fake_pk']}}

        subtuple2 = {
            'key': 'bar',
            'dataset': {
                'data_sample_keys': [data_sample.key]
            }
        }

        with mock.patch('substrapp.models.DataSample.objects.get') as mget:
            mget.return_value = data_sample

            subtuple_directory = build_subtuple_folders(subtuple)

            with self.assertRaises(Exception):
                prepare_data_sample(subtuple_directory, subtuple)

            with self.assertRaises(Exception):
                prepare_data_sample('/fake/directory/failure', subtuple2)
示例#2
0
    def test_put_data_tar(self):

        checksum, datasamples_path_from_file = store_datasamples_archive(
            self.data_sample_tar)

        key = str(uuid.uuid4())
        data_sample = DataSample(key=key,
                                 path=datasamples_path_from_file,
                                 checksum=checksum)
        data_sample.save()

        subtuple = {
            'key': 'bar',
            'dataset': {
                'data_sample_keys': [str(data_sample.key)]
            }
        }

        with mock.patch('substrapp.models.DataSample.objects.get') as mget:
            mget.return_value = data_sample

            subtuple_directory = build_subtuple_folders(subtuple)

            prepare_data_sample(subtuple_directory, subtuple)

            # check folder has been correctly renamed with key of directory containing uncompressed data_sample
            self.assertFalse(
                os.path.exists(os.path.join(MEDIA_ROOT, 'datasamples', 'foo')))
            self.assertTrue(
                os.path.exists(os.path.join(MEDIA_ROOT, 'datasamples', key)))

            # check subtuple folder has been created and sym links exists
            self.assertTrue(
                os.path.exists(
                    os.path.join(MEDIA_ROOT, 'subtuple/bar/data',
                                 data_sample.key)))
            self.assertTrue(
                os.path.islink(
                    os.path.join(MEDIA_ROOT, 'subtuple/bar/data',
                                 data_sample.key)))
            self.assertTrue(
                os.path.exists(
                    os.path.join(MEDIA_ROOT, 'subtuple/bar/data',
                                 data_sample.key, 'LABEL_0024900.csv')))
            self.assertTrue(
                os.path.exists(
                    os.path.join(MEDIA_ROOT, 'subtuple/bar/data',
                                 data_sample.key, 'IMG_0024900.jpg')))
示例#3
0
    def test_prepare_data_sample_zip(self):

        dir_pkhash, datasamples_path_from_file = store_datasamples_archive(
            self.data_sample)

        data_sample = DataSample(pkhash=dir_pkhash,
                                 path=datasamples_path_from_file)
        data_sample.save()

        subtuple = {'key': 'bar', 'dataset': {'keys': [data_sample.pk]}}

        with mock.patch('substrapp.models.DataSample.objects.get') as mget:
            mget.return_value = data_sample

            subtuple_directory = build_subtuple_folders(subtuple)

            prepare_data_sample(subtuple_directory, subtuple)

            # check folder has been correctly renamed with pk of directory containing uncompressed data sample
            self.assertFalse(
                os.path.exists(os.path.join(MEDIA_ROOT, 'datasamples', 'foo')))
            self.assertTrue(
                os.path.exists(
                    os.path.join(MEDIA_ROOT, 'datasamples', dir_pkhash)))

            # check subtuple folder has been created and sym links exists
            self.assertTrue(
                os.path.exists(
                    os.path.join(MEDIA_ROOT, 'subtuple/bar/data',
                                 data_sample.pk)))
            self.assertTrue(
                os.path.islink(
                    os.path.join(MEDIA_ROOT, 'subtuple/bar/data',
                                 data_sample.pk)))
            self.assertTrue(
                os.path.exists(
                    os.path.join(MEDIA_ROOT, 'subtuple/bar/data',
                                 data_sample.pk, 'LABEL_0024900.csv')))
            self.assertTrue(
                os.path.exists(
                    os.path.join(MEDIA_ROOT, 'subtuple/bar/data',
                                 data_sample.pk, 'IMG_0024900.jpg')))