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


Python Mock.put_archive方法代码示例

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


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

示例1: test_call_success

# 需要导入模块: from salttesting.mock import Mock [as 别名]
# 或者: from salttesting.mock.Mock import put_archive [as 别名]
    def test_call_success(self):
        '''
        test module calling inside containers
        '''
        ret = None
        docker_run_all_mock = MagicMock(
            return_value={
                'retcode': 0,
                'stdout': '{"retcode": 0, "comment": "container cmd"}',
                'stderr': 'err',
            })
        docker_copy_to_mock = MagicMock(
            return_value={
                'retcode': 0
            })
        client = Mock()
        client.put_archive = Mock()

        with patch.dict(dockerng_mod.__opts__, {'cachedir': '/tmp'}):
            with patch.dict(dockerng_mod.__salt__, {'dockerng.run_all': docker_run_all_mock,
                                                    'dockerng.copy_to': docker_copy_to_mock}):
                with patch.dict(dockerng_mod.__context__, {'docker.client': client}):
                    # call twice to verify tmp path later
                    for i in range(2):
                        ret = dockerng_mod.call(
                            'ID',
                            'test.arg',
                            1, 2,
                            arg1='val1')

        # Check that the directory is different each time
        # [ call(name, [args]), ...
        self.assertIn('mkdir', docker_run_all_mock.mock_calls[0][1][1])
        self.assertIn('mkdir', docker_run_all_mock.mock_calls[3][1][1])
        self.assertNotEqual(docker_run_all_mock.mock_calls[0][1][1],
                            docker_run_all_mock.mock_calls[3][1][1])

        self.assertIn('salt-call', docker_run_all_mock.mock_calls[1][1][1])
        self.assertIn('salt-call', docker_run_all_mock.mock_calls[4][1][1])
        self.assertNotEqual(docker_run_all_mock.mock_calls[1][1][1],
                            docker_run_all_mock.mock_calls[4][1][1])

        # check directory cleanup
        self.assertIn('rm -rf', docker_run_all_mock.mock_calls[2][1][1])
        self.assertIn('rm -rf', docker_run_all_mock.mock_calls[5][1][1])
        self.assertNotEqual(docker_run_all_mock.mock_calls[2][1][1],
                            docker_run_all_mock.mock_calls[5][1][1])

        self.assertEqual({"retcode": 0, "comment": "container cmd"}, ret)
开发者ID:bryson,项目名称:salt,代码行数:51,代码来源:dockerng_test.py


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