Esempio n. 1
0
    def test_download_file_from_s3_if_needed(self):
        s3 = get_s3_client()
        s3.create_bucket(Bucket='bucket')
        file_path = download_file_from_s3_if_needed('/local/path/to/file')
        self.assertEqual(file_path, '/local/path/to/file')

        s3.put_object(Bucket='bucket', Key='subdir/file.ext', Body='')
        file_path = \
            download_file_from_s3_if_needed('/vsis3/bucket/subdir/file.ext')
        self.assertTrue('file.ext' in file_path)

        s3.put_object(Bucket='bucket', Key='subdir/file.shp', Body='')
        s3.put_object(Bucket='bucket', Key='subdir/file.shx', Body='')
        s3.put_object(Bucket='bucket', Key='subdir/file.dbf', Body='')
        s3.put_object(Bucket='bucket', Key='subdir/file.prj', Body='')
        file_path = \
            download_file_from_s3_if_needed('/vsis3/bucket/subdir/file.shp')
        self.assertTrue('file.shp' in file_path)

        # Check zip file
        directory_path = get_temporary_directory()
        zip_file_path = os.path.join(directory_path, 'file.zip')
        with ZipFile(zip_file_path, 'w') as zipObj:
            for file_name in ['test.shp', 'test.shx', 'test.dbf',
                              'test.prj', 'test.cpg']:
                file_path = os.path.join(directory_path, file_name)
                print('Test file', file=open(file_path, 'w'))
                zipObj.write(file_path)

        s3.upload_file(zip_file_path, 'bucket', 'subdir/file.zip')
        file_path = \
            download_file_from_s3_if_needed('/vsis3/bucket/subdir/file.zip')
        self.assertTrue('test.shp' in file_path)
Esempio n. 2
0
 def test_upload_to_s3_if_applicable(self):
     s3 = get_s3_client()
     s3.create_bucket(Bucket='bucket')
     directory_path = get_temporary_directory()
     file_path = os.path.join(directory_path, 'file.ext')
     print('Test file', file=open(file_path, 'w'))
     upload_to_s3_if_applicable(file_path, 'bucket', 'subdir/file.ext')
     response = s3.head_object(Bucket='bucket', Key='subdir/file.ext')
     self.assertTrue(response['ContentLength'] > 0)
Esempio n. 3
0
 def test_download_from_s3(self):
     s3 = get_s3_client()
     s3.create_bucket(Bucket='bucket')
     s3.put_object(Bucket='bucket', Key='subdir/file.ext', Body='')
     directory_path = get_temporary_directory()
     file_path = \
         download_from_s3('/vsis3/bucket/subdir/file.ext', directory_path)
     self.assertEqual(file_path, os.path.join(directory_path, 'file.ext'))
     self.assertTrue(os.path.exists(file_path))
Esempio n. 4
0
 def test_get_temporary_directory(self):
     directory_path = get_temporary_directory()
     self.assertTrue('HazImp-' in directory_path)