def test_diff(self): self.assertFalse( fs.diff(os.path.join('futsu', 'test', 'test_diff_0.txt'), os.path.join('futsu', 'test', 'test_diff_1.txt'))) self.assertTrue( fs.diff(os.path.join('futsu', 'test', 'test_diff_0.txt'), os.path.join('futsu', 'test', 'test_diff_2.txt')))
def test_acl(self): client = fstorage.create_client() with tempfile.TemporaryDirectory() as tempdir: token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr()) src_fn = os.path.join('futsu', 'aws', 'test', 'test_storage.txt') tmp_gs_path = 's3://futsu-test/test-TOPTSPZHLZ-{0}'.format(token) tmp_http_path = 'https://futsu-test.s3-us-west-2.amazonaws.com/test-TOPTSPZHLZ-{0}'.format( token) tmp_filename = os.path.join(tempdir, 'QHDCXHYRKZ') client = fstorage.create_client() # no upload, should be 404 with self.assertRaises(Exception): ffstorage.path_to_local(tmp_filename, tmp_http_path) # upload fstorage.file_to_blob(tmp_gs_path, src_fn, client) # bad acl, should be 403 with self.assertRaises(Exception): ffstorage.path_to_local(tmp_filename, tmp_http_path) # set acl fstorage.set_blob_acl(tmp_gs_path, 'public-read', client) # should run ok ffstorage.path_to_local(tmp_filename, tmp_http_path) self.assertFalse(ffs.diff(src_fn, tmp_filename))
def test_s3(self): with tempfile.TemporaryDirectory() as tempdir: tmp_filename = os.path.join(tempdir, 'TMWGHOKDRE') src_file = os.path.join('futsu', 'test', 'test_storage_0.txt') token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr()) tmp_path = 's3://futsu-test/test-KWPIYZVIYK-{0}'.format(token) self.assertFalse(storage.is_blob_exist(tmp_path)) storage.local_to_path(tmp_path, src_file) self.assertTrue(storage.is_blob_exist(tmp_path)) storage.path_to_local(tmp_filename, tmp_path) self.assertFalse(fs.diff(tmp_filename, src_file)) storage.rm(tmp_path) self.assertFalse(storage.is_blob_exist(tmp_path)) tmp_gs_blob = 's3://futsu-test/test-LKUDEBPHEF-{0}'.format(token) bytes0 = b'SUZODZKFXW' storage.bytes_to_path(tmp_gs_blob, bytes0) bytes1 = storage.path_to_bytes(tmp_gs_blob) self.assertEqual(bytes0, bytes1) tmp_path_list = [ 's3://futsu-test/test-SVABRZZM-{0}/{1}'.format(token, i) for i in range(10) ] for tmp_path in tmp_path_list: storage.bytes_to_path(tmp_path, b'') ret_path_list = storage.find( 's3://futsu-test/test-SVABRZZM-{0}/'.format(token)) ret_path_list = sorted(list(ret_path_list)) self.assertEqual(ret_path_list, tmp_path_list)
def test_gcp(self): with tempfile.TemporaryDirectory() as tempdir: tmp_filename = os.path.join(tempdir, 'GPVRUHXTTC') src_file = os.path.join('futsu', 'test', 'test_storage_0.txt') token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr()) tmp_gs_blob = 'gs://futsu-test/test-NXMUHBDEMR-{0}'.format(token) self.assertFalse(storage.is_blob_exist(tmp_gs_blob)) storage.local_to_path(tmp_gs_blob, src_file) self.assertTrue(storage.is_blob_exist(tmp_gs_blob)) storage.path_to_local(tmp_filename, tmp_gs_blob) self.assertFalse(fs.diff(tmp_filename, src_file)) storage.rm(tmp_gs_blob) self.assertFalse(storage.is_blob_exist(tmp_gs_blob)) tmp_gs_blob = 'gs://futsu-test/test-DQZFYPFNUV-{0}'.format(token) bytes0 = b'RZCPRGZZBC' storage.bytes_to_path(tmp_gs_blob, bytes0) bytes1 = storage.path_to_bytes(tmp_gs_blob) self.assertEqual(bytes0, bytes1) tmp_path_list = [ 'gs://futsu-test/test-NKMYDMGJ-{0}/{1}'.format(token, i) for i in range(10) ] for tmp_path in tmp_path_list: storage.bytes_to_path(tmp_path, b'') ret_path_list = storage.find( 'gs://futsu-test/test-NKMYDMGJ-{0}/'.format(token)) ret_path_list = sorted(list(ret_path_list)) self.assertEqual(ret_path_list, tmp_path_list)
def test_local(self): with tempfile.TemporaryDirectory() as tempdir: tmp_filename = os.path.join(tempdir, 'QKDQXVOOME') src_file = os.path.join('futsu', 'test', 'test_storage_0.txt') self.assertFalse(storage.is_blob_exist(tmp_filename)) storage.local_to_path(tmp_filename, src_file) self.assertTrue(storage.is_blob_exist(tmp_filename)) self.assertFalse(fs.diff(tmp_filename, src_file)) storage.rm(tmp_filename) self.assertFalse(storage.is_blob_exist(tmp_filename)) tmp_filename = os.path.join(tempdir, 'NKNVMMYPUI') bytes0 = b'YENLUMVECW' storage.bytes_to_path(tmp_filename, bytes0) bytes1 = storage.path_to_bytes(tmp_filename) self.assertEqual(bytes0, bytes1) tmp_root_path = os.path.join(tempdir, 'BDHYVQKO') fs.makedirs(tmp_root_path) tmp_path_list = [ os.path.join(tmp_root_path, '{0}'.format(i)) for i in range(10) ] for tmp_path in tmp_path_list: storage.bytes_to_path(tmp_path, b'') ret_path_list = storage.find(tmp_root_path) ret_path_list = sorted(list(ret_path_list)) self.assertEqual(ret_path_list, tmp_path_list)
def test_cp(self): with tempfile.TemporaryDirectory() as tempdir: tmp_filename = os.path.join(tempdir, 'YHGASBIGHI') fs.cp(tmp_filename, os.path.join('futsu', 'test', 'test_cp_0.txt')) self.assertFalse( fs.diff(tmp_filename, os.path.join('futsu', 'test', 'test_cp_0.txt')))
def test_aws_file(self): client = fstorage.create_client() with tempfile.TemporaryDirectory() as tempdir: token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr()) src_fn = os.path.join('futsu', 'aws', 'test', 'test_storage.txt') tmp_gs_path = 's3://futsu-test/test-TOPTSPZHLZ-{0}'.format(token) tmp_filename = os.path.join(tempdir, 'QDVBADVVVW') fstorage.file_to_blob(tmp_gs_path, src_fn, client) fstorage.blob_to_file(tmp_filename, tmp_gs_path, client) self.assertFalse(ffs.diff(src_fn, tmp_filename))
def test_gcp_file(self): client = gcstorage.client.Client() with tempfile.TemporaryDirectory() as tempdir: token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr()) src_fn = os.path.join('futsu', 'gcp', 'test', 'test_storage.txt') tmp_gs_path = 'gs://futsu-test/test-CQJWTXYXEJ-{0}'.format(token) tmp_filename = os.path.join(tempdir, 'PKQXWFJWRB') fstorage.file_to_blob(tmp_gs_path, src_fn, client) fstorage.blob_to_file(tmp_filename, tmp_gs_path, client) self.assertFalse(ffs.diff(src_fn, tmp_filename))