示例#1
0
    def test_copy_to_root_and_delete(self):
        # Source without "/"
        source_path = "gs://aries_test/test_folder/test_subfolder"
        # Destination is the bucket root, whether it ends with "/" does not matter.
        dest_path = "gs://aries_test"

        try:
            folder = StorageFolder(source_path)
            folder.copy(dest_path)
            copied = StorageFolder("gs://aries_test/test_subfolder/")
            self.assert_object_counts(copied, 1, 0, 1)
            self.assertEqual(copied.file_names[0], "file_in_subfolder.txt")
            # Delete the copied files
            StorageFolder("gs://aries_test/test_subfolder/").delete()
            # With "/"
            source_path = "gs://aries_test/test_folder/test_subfolder"
            dest_path = "gs://aries_test/"
            folder = StorageFolder(source_path)
            folder.copy(dest_path)
            copied = StorageFolder("gs://aries_test/test_subfolder/")
            self.assert_object_counts(copied, 1, 0, 1)
            self.assertEqual(copied.file_names[0], "file_in_subfolder.txt")
        finally:
            # Delete the copied files
            StorageFolder("gs://aries_test/test_subfolder/").delete()
示例#2
0
    def test_copy_folder(self):
        # Source folder to be copied
        src_folder_uri = os.path.join(self.TEST_ROOT, "test_folder_0")
        sub_folder = StorageFolder(src_folder_uri)
        # Source folder should exist
        self.assertTrue(sub_folder.exists())

        # Destination folder
        dst_folder_uri = os.path.join(self.TEST_ROOT, "new_folder",
                                      "test_folder_0")

        dst_parent = os.path.join(self.TEST_ROOT, "new_folder")
        with TempFolder(dst_parent):
            # Destination folder should not exist
            dst_folder = StorageFolder(dst_folder_uri)
            if dst_folder.exists():
                dst_folder.delete()
            self.assertFalse(dst_folder.exists())

            # Copy the folder
            if not dst_parent.endswith("/"):
                dst_parent += "/"
            logger.debug("Copying from %s into %s" %
                         (sub_folder.uri, dst_parent))
            sub_folder.copy(dst_parent)

            # Destination folder should now exist and contain an empty file
            self.assertTrue(dst_folder.exists())
            file_paths = [f.uri for f in dst_folder.files]
            self.assertEqual(len(file_paths), 2)
            self.assertIn(os.path.join(dst_folder_uri, "empty_file"),
                          file_paths)
            self.assertIn(os.path.join(dst_folder_uri, "abc.txt"), file_paths)
示例#3
0
    def test_copy_and_delete_folder(self):
        source_path = "gs://aries_test/test_folder/"
        # Destination path ends with "/", the original folder name will be preserved.
        dest_path = "gs://aries_test/copy_test/"
        folder = StorageFolder(source_path)
        folder.copy(dest_path)
        copied = StorageFolder(dest_path)
        self.assert_object_counts(copied, 0, 1, 2)
        self.assertEqual(copied.folder_names[0], "test_folder")
        # Delete the copied files
        copied.delete()
        self.assertEqual(len(copied.files), 0)
        self.assertEqual(len(copied.folders), 0)

        # Copy contents only.
        dest_path = "gs://aries_test/copy_test/new_name"
        copied = StorageFolder(dest_path)
        try:
            folder = StorageFolder(source_path)
            folder.copy(dest_path, contents_only=True)
            logger.debug(copied.objects)
            self.assert_object_counts(copied, 1, 1, 2)
            self.assertEqual(copied.folder_names[0], "test_subfolder")
        finally:
            # Delete the copied files
            StorageFolder("gs://aries_test/copy_test/").delete()