Beispiel #1
0
    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))
Beispiel #2
0
    def test_rmtree_big(self):
        token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr())

        s3_client = fstorage.create_client()

        path0 = 's3://futsu-test/test-HOSPFEUB-{token}'.format(token=token)
        for i in range(1234):
            print('UQYFVDQC create {i}'.format(i=i))
            path00 = fstorage.join(path0, str(i))
            fstorage.bytes_to_blob(path00, b'', s3_client)
            self.assertTrue(fstorage.is_blob_exist(path00, s3_client))

        self.assertEqual(len(list(fstorage.find_blob_itr(path0, s3_client))),
                         1234)

        print('TLWHHGHX rmtree')
        fstorage.rmtree(path0, s3_client)

        self.assertEqual(len(list(fstorage.find_blob_itr(path0, s3_client))),
                         0)

        for i in range(1234):
            print('UQYFVDQC check {i}'.format(i=i))
            path00 = fstorage.join(path0, str(i))
            self.assertFalse(fstorage.is_blob_exist(path00, s3_client))
Beispiel #3
0
    def test_rmtree(self):
        token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr())
        path0 = 's3://futsu-test/test-HOSPFEUB-{token}'.format(token=token)
        path00 = fstorage.join(path0, 'ITGDLUVB')
        path000 = fstorage.join(path00, 'WKBXFDTH', 'CMCXBJYN')
        path001 = fstorage.join(path00, 'MGNZJTXL', 'RGWIYPEG')
        path01 = fstorage.join(path0, 'GMZSNRPD', 'UOAUKUKG', 'VJUOXIQY')
        path02 = fstorage.join(path0, 'ITGDLUVBx')

        s3_client = fstorage.create_client()

        fstorage.bytes_to_blob(path000, b'', s3_client)
        fstorage.bytes_to_blob(path001, b'', s3_client)
        fstorage.bytes_to_blob(path01, b'', s3_client)
        fstorage.bytes_to_blob(path02, b'', s3_client)

        self.assertTrue(fstorage.is_blob_exist(path000, s3_client))
        self.assertTrue(fstorage.is_blob_exist(path001, s3_client))
        self.assertTrue(fstorage.is_blob_exist(path01, s3_client))
        self.assertTrue(fstorage.is_blob_exist(path02, s3_client))

        fstorage.rmtree(path00, s3_client)

        self.assertFalse(fstorage.is_blob_exist(path000, s3_client))
        self.assertFalse(fstorage.is_blob_exist(path001, s3_client))
        self.assertTrue(fstorage.is_blob_exist(path01, s3_client))
        self.assertTrue(fstorage.is_blob_exist(path02, s3_client))
Beispiel #4
0
    def test_exist(self):
        token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr())
        tmp_gs_path = 's3://futsu-test/test-YYAZXVHGVW-{0}'.format(token)

        client = fstorage.create_client()
        self.assertFalse(fstorage.is_blob_exist(tmp_gs_path, client))
        fstorage.string_to_blob(tmp_gs_path, 'EYKVKUAUNU', client)
        self.assertTrue(fstorage.is_blob_exist(tmp_gs_path, client))
Beispiel #5
0
    def test_aws_string(self):
        token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr())
        tmp_gs_path = 's3://futsu-test/test-PPCFADJEPR-{0}'.format(token)

        client = fstorage.create_client()
        fstorage.string_to_blob(tmp_gs_path, 'NSODRIGNUR', client)
        s = fstorage.blob_to_string(tmp_gs_path, client)
        self.assertEqual(s, 'NSODRIGNUR')
Beispiel #6
0
    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))
Beispiel #7
0
    def test_delete(self):
        token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr())
        tmp_gs_path = 's3://futsu-test/test-WABWGQVWRP-{0}'.format(token)

        client = fstorage.create_client()

        self.assertFalse(fstorage.is_blob_exist(tmp_gs_path, client))

        fstorage.blob_rm(tmp_gs_path, client)

        self.assertFalse(fstorage.is_blob_exist(tmp_gs_path, client))

        fstorage.string_to_blob(tmp_gs_path, 'RPUBYBJZSN', client)
        self.assertTrue(fstorage.is_blob_exist(tmp_gs_path, client))

        fstorage.blob_rm(tmp_gs_path, client)

        self.assertFalse(fstorage.is_blob_exist(tmp_gs_path, client))
Beispiel #8
0
    def test_find_blob_itr(self):
        client = fstorage.create_client()
        token = '{ts}-{r}'.format(ts=int(time.time()), r=randstr())
        tmp_gs_path_list = [
            's3://futsu-test/test-JJLVOWMQ-{0}/{1}'.format(token, i)
            for i in range(10)
        ]
        for tmp_gs_path in tmp_gs_path_list:
            fstorage.bytes_to_blob(tmp_gs_path, b'ZPMSMMAU', client)

        blob_list = fstorage.find_blob_itr(
            's3://futsu-test/test-JJLVOWMQ-{0}/'.format(token), client)
        blob_list = list(blob_list)
        self.assertEqual(len(blob_list), 10)
        blob_list = sorted(blob_list)
        self.assertEqual(blob_list, tmp_gs_path_list)

        blob_list = fstorage.find_blob_itr(
            's3://futsu-test/test-JJLVOWMQ-{0}/'.format(token),
            client,
            MaxKeys=5)
        blob_list = list(blob_list)
        self.assertEqual(len(blob_list), 10)
        blob_list = sorted(blob_list)
        self.assertEqual(blob_list, tmp_gs_path_list)

        blob_list = fstorage.find_blob_itr(
            's3://futsu-test/test-JJLVOWMQ-{0}/'.format(token),
            client,
            MaxKeys=20)
        blob_list = list(blob_list)
        self.assertEqual(len(blob_list), 10)
        blob_list = sorted(blob_list)
        self.assertEqual(blob_list, tmp_gs_path_list)

        blob_list = fstorage.find_blob_itr(
            's3://futsu-test/test-HPYHCAMK-{0}/'.format(token), client)
        blob_list = list(blob_list)
        self.assertEqual(len(blob_list), 0)