当前位置: 首页>>代码示例>>Python>>正文


Python RackspaceCtrl.find_storage_image_names方法代码示例

本文整理汇总了Python中gns3.cloud.rackspace_ctrl.RackspaceCtrl.find_storage_image_names方法的典型用法代码示例。如果您正苦于以下问题:Python RackspaceCtrl.find_storage_image_names方法的具体用法?Python RackspaceCtrl.find_storage_image_names怎么用?Python RackspaceCtrl.find_storage_image_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在gns3.cloud.rackspace_ctrl.RackspaceCtrl的用法示例。


在下文中一共展示了RackspaceCtrl.find_storage_image_names方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TestRackspaceCtrl

# 需要导入模块: from gns3.cloud.rackspace_ctrl import RackspaceCtrl [as 别名]
# 或者: from gns3.cloud.rackspace_ctrl.RackspaceCtrl import find_storage_image_names [as 别名]

#.........这里部分代码省略.........
            f.write(test_data)

        self.ctrl.storage_driver = mock.MagicMock()
        mock_container = mock.MagicMock()
        mock_container.list_objects = mock.MagicMock(
            return_value=[MockStorageObject("test_folder/test.txt"), MockStorageObject("test_folder/test.txt.md5")]
        )
        self.ctrl.storage_driver.create_container = mock.MagicMock(return_value=mock_container)

        mock_container.get_object = mock.MagicMock(return_value=MockStorageObject("", bytes(test_data_hash, "utf8")))

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

        self.assertFalse(self.ctrl.storage_driver.upload_object_via_stream.called)
        self.assertEqual(return_value, False)

    def test_download_file__exists__same_hash(self):
        test_data = b"abcdefghi"
        test_data_hash = hashlib.md5(test_data).hexdigest()
        test_file = tempfile.NamedTemporaryFile()
        with test_file.file as f:
            f.write(test_data)

        self.ctrl.storage_driver = mock.MagicMock()
        mock_container = mock.MagicMock()
        self.ctrl.storage_driver.get_container = mock.MagicMock(return_value=mock_container)

        file_object = MockStorageObject("test_file.txt")
        file_object.download = mock.MagicMock()
        file_hash_object = MockStorageObject("test_file.txt", bytes(test_data_hash, "utf8"))

        mock_container.get_object = lambda name: {"test_file.txt": file_object, "test_file.txt.md5": file_hash_object}[
            name
        ]

        self.ctrl.download_file("test_file.txt", test_file.name)

        self.assertFalse(file_object.download.called)

    def test_download_file__exists__different_hash(self):
        test_data = b"abcdefghij"
        test_data_hash = "some_garbage_hash"
        test_file = tempfile.NamedTemporaryFile()
        with test_file.file as f:
            f.write(test_data)

        self.ctrl.storage_driver = mock.MagicMock()
        mock_container = mock.MagicMock()
        self.ctrl.storage_driver.get_container = mock.MagicMock(return_value=mock_container)

        file_object = MockStorageObject("test_file.txt")
        file_object.download = mock.MagicMock()
        file_hash_object = MockStorageObject("test_file.txt", bytes(test_data_hash, "utf8"))

        mock_container.get_object = lambda name: {"test_file.txt": file_object, "test_file.txt.md5": file_hash_object}[
            name
        ]

        self.ctrl.download_file("test_file.txt", test_file.name)

        file_object.download.assert_called_once_with(test_file.name)

    def test_find_storage_image_names(self):
        self.ctrl.storage_driver = mock.MagicMock()
        mock_container = mock.MagicMock()
        self.ctrl.storage_driver.get_container = mock.MagicMock(return_value=mock_container)
        mock_container.list_objects = mock.MagicMock(
            return_value=[
                MockStorageObject("images/IOS/test_image_1.image"),
                MockStorageObject("images/IOS/test_image_1.image.md5"),
                MockStorageObject("images/IOS/test_image_2.img"),
                MockStorageObject("images/IOS/test_image_2.img.md5"),
                MockStorageObject("images/IOS/test_image_3.img"),
                MockStorageObject("projects/project1.zip"),
                MockStorageObject("test_image_1.image"),
            ]
        )

        image_names = self.ctrl.find_storage_image_names(["test_image_1.image", "test_image_2.img"])

        self.assertDictEqual(
            image_names,
            {"test_image_1.image": "images/IOS/test_image_1.image", "test_image_2.img": "images/IOS/test_image_2.img"},
        )

    def test_find_storage_image_names__missing(self):
        self.ctrl.storage_driver = mock.MagicMock()
        mock_container = mock.MagicMock()
        self.ctrl.storage_driver.get_container = mock.MagicMock(return_value=mock_container)
        mock_container.list_objects = mock.MagicMock(
            return_value=[
                MockStorageObject("images/IOS/test_image_1.image"),
                MockStorageObject("images/IOS/test_image_1.image.md5"),
                MockStorageObject("images/IOS/test_image_2.img.md5"),
                MockStorageObject("projects/project1.zip"),
                MockStorageObject("test_image_1.image"),
            ]
        )

        self.assertRaises(Exception, self.ctrl.find_storage_image_names, ["test_image_1.image", "test_image_2.img"])
开发者ID:planctechnologies,项目名称:gns3-gui,代码行数:104,代码来源:test_cloud_unit.py


注:本文中的gns3.cloud.rackspace_ctrl.RackspaceCtrl.find_storage_image_names方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。