Exemplo n.º 1
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)
Exemplo n.º 2
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()
Exemplo n.º 3
0
 def __exit__(self, exc_type, exc_val, exc_tb):
     folder = StorageFolder(self.folder_uri)
     if folder.exists():
         folder.delete()