當前位置: 首頁>>代碼示例>>Python>>正文


Python RackspaceCtrl.delete_file方法代碼示例

本文整理匯總了Python中gns3.cloud.rackspace_ctrl.RackspaceCtrl.delete_file方法的典型用法代碼示例。如果您正苦於以下問題:Python RackspaceCtrl.delete_file方法的具體用法?Python RackspaceCtrl.delete_file怎麽用?Python RackspaceCtrl.delete_file使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在gns3.cloud.rackspace_ctrl.RackspaceCtrl的用法示例。


在下文中一共展示了RackspaceCtrl.delete_file方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestRackspaceCtrl

# 需要導入模塊: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 別名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import delete_file [as 別名]

#.........這裏部分代碼省略.........
        self.assertTrue("member_id" in r_images2[0])
        self.assertTrue("member_id" in r_images2[1])
        self.assertEqual(r_images[0]["member_id"], r_images2[0]["member_id"])
        self.assertEqual(r_images[1]["member_id"], r_images2[1]["member_id"])
        self.assertTrue("status" in r_images2[0])
        self.assertTrue("status" in r_images2[1])
        self.assertEqual(r_images2[0]["status"], "ALREADYREQUESTED")
        self.assertEqual(r_images2[1]["status"], "ALREADYREQUESTED")
        print("Done.")

    def test_upload_file(self):
        try:
            test_data = "abcdefg"
            test_file = tempfile.NamedTemporaryFile(mode="w")
            with test_file.file as f:
                f.write(test_data)

            return_value = self.ctrl.upload_file(test_file.name, "test_folder/test_file.txt")

            container = self.ctrl.storage_driver.get_container(self.ctrl.GNS3_CONTAINER_NAME)
            file_object = container.get_object("test_folder/test_file.txt")
            hash_object = container.get_object("test_folder/test_file.txt.md5")

            cloud_file_hash = ""
            for chunk in hash_object.as_stream():
                cloud_file_hash += chunk.decode("utf8")

            cloud_file_contents = ""
            for chunk in file_object.as_stream():
                cloud_file_contents += chunk.decode("utf8")

            self.assertEqual(cloud_file_hash, hashlib.md5(test_data.encode("utf8")).hexdigest())
            self.assertEqual(cloud_file_contents, test_data)
            self.assertEqual(return_value, True)

        finally:
            self._delete_container()

    def test_list_projects(self):
        container = self.ctrl.storage_driver.create_container(self.ctrl.GNS3_CONTAINER_NAME)

        try:
            container.upload_object_via_stream(StringIO("abcd"), "projects/project1.gns3.zip")
            container.upload_object_via_stream(StringIO("abcd"), "projects/project1.gns3.zip.md5")
            container.upload_object_via_stream(StringIO("abcd"), "projects/project2.gns3.zip")
            container.upload_object_via_stream(StringIO("abcd"), "some_file.txt")
            container.upload_object_via_stream(StringIO("abcd"), "some_file2.zip")

            projects = self.ctrl.list_projects()

            self.assertDictEqual(
                projects, {"project1.gns3": "projects/project1.gns3.zip", "project2.gns3": "projects/project2.gns3.zip"}
            )

        finally:
            self._delete_container()

    def test_download_file(self):
        container = self.ctrl.storage_driver.create_container(self.ctrl.GNS3_CONTAINER_NAME)

        try:
            test_data = b"abcdef"
            container.upload_object_via_stream(BytesIO(test_data), "projects/project1.gns3.zip")

            downloaded_data = self.ctrl.download_file("projects/project1.gns3.zip")

            self.assertEqual(downloaded_data.read(), test_data)

        finally:
            self._delete_container()

    def test_download_file__to_filesystem(self):
        container = self.ctrl.storage_driver.create_container(self.ctrl.GNS3_CONTAINER_NAME)

        try:
            test_data = b"abcd"
            container.upload_object_via_stream(BytesIO(test_data), "projects/project1.gns3.zip")

            self.ctrl.download_file("projects/project1.gns3.zip", "downloaded_file.zip")

            with open("downloaded_file.zip", "rb") as f:
                self.assertEqual(f.read(), test_data)

        finally:
            self._delete_container()
            os.remove("downloaded_file.zip")

    def test_delete_file(self):
        container = self.ctrl.storage_driver.create_container(self.ctrl.GNS3_CONTAINER_NAME)

        try:
            container.upload_object_via_stream(StringIO("abcde"), "projects/project1.gns3.zip")
            container.upload_object_via_stream(StringIO("1234"), "projects/project1.gns3.zip.md5")

            self.ctrl.delete_file("projects/project1.gns3.zip")

            self.assertRaises(ObjectDoesNotExistError, container.get_object, "projects/project1.gns3.zip")
            self.assertRaises(ObjectDoesNotExistError, container.get_object, "projects/project1.gns3.zip.md5")
        finally:
            self._delete_container()
開發者ID:planctechnologies,項目名稱:gns3-gui,代碼行數:104,代碼來源:test_cloud_integration.py


注:本文中的gns3.cloud.rackspace_ctrl.RackspaceCtrl.delete_file方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。