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


Python Mock.configure_mock方法代码示例

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


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

示例1: test_present_gslb_site_identical_flow

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_present_gslb_site_identical_flow(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='present',
        ))
        from ansible.modules.network.netscaler import netscaler_gslb_site

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        glsb_site_proxy_attrs = {
            'diff_object.return_value': {},
        }
        gslb_site_proxy_mock = Mock()
        gslb_site_proxy_mock.configure_mock(**glsb_site_proxy_attrs)
        config_proxy_mock = Mock(return_value=gslb_site_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_gslb_site',
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            gslb_site_exists=Mock(side_effect=[True, True]),
            gslb_site_identical=Mock(side_effect=[True, True]),
            nitro_exception=self.MockException,
            ensure_feature_is_enabled=Mock(),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_gslb_site
            self.exited()
            gslb_site_proxy_mock.assert_not_called()
开发者ID:awiddersheim,项目名称:ansible,代码行数:36,代码来源:test_netscaler_gslb_site.py

示例2: test_absent_gslb_site_failed_delete

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_absent_gslb_site_failed_delete(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='absent',
        ))
        from ansible.modules.network.netscaler import netscaler_gslb_site

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        glsb_site_proxy_attrs = {
            'diff_object.return_value': {},
        }
        gslb_site_proxy_mock = Mock()
        gslb_site_proxy_mock.configure_mock(**glsb_site_proxy_attrs)
        config_proxy_mock = Mock(return_value=gslb_site_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_gslb_site',
            nitro_exception=self.MockException,
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            gslb_site_exists=Mock(side_effect=[True, True]),
            gslb_site_identical=Mock(side_effect=[False, False]),
            ensure_feature_is_enabled=Mock(),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_gslb_site
            result = self.failed()
            self.assertEqual(result['msg'], 'GSLB site still exists')
            self.assertTrue(result['failed'])
开发者ID:awiddersheim,项目名称:ansible,代码行数:37,代码来源:test_netscaler_gslb_site.py

示例3: test_ensure_feature_is_enabled

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
 def test_ensure_feature_is_enabled(self):
     client = Mock()
     attrs = {'get_enabled_features.return_value': ['GSLB']}
     client.configure_mock(**attrs)
     ensure_feature_is_enabled(client, 'GSLB')
     ensure_feature_is_enabled(client, 'LB')
     client.enable_features.assert_called_once_with('LB')
开发者ID:awiddersheim,项目名称:ansible,代码行数:9,代码来源:test_netscaler_module_utils.py

示例4: test_graceful_login_error

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_graceful_login_error(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='present',
        ))
        from ansible.modules.network.netscaler import netscaler_gslb_site

        if sys.version_info[:2] == (2, 6):
            self.skipTest('requests library not available under python2.6')

        class MockException(Exception):
            pass
        client_mock = Mock()
        attrs = {'login.side_effect': requests.exceptions.SSLError}
        client_mock.configure_mock(**attrs)
        m = Mock(return_value=client_mock)
        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_gslb_site',
            get_nitro_client=m,
            nitro_exception=MockException,
        ):
            self.module = netscaler_gslb_site
            result = self.failed()
            self.assertTrue(result['msg'].startswith('SSL Error'), msg='SSL Error was not handled gracefully')
开发者ID:awiddersheim,项目名称:ansible,代码行数:28,代码来源:test_netscaler_gslb_site.py

示例5: test_absent_server_noop_flow

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_absent_server_noop_flow(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='absent',
        ))
        from ansible.modules.network.netscaler import netscaler_ssl_certkey

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        ssl_certkey_proxy_attrs = {
            'diff_object.return_value': {},
        }
        ssl_certkey_proxy_mock = Mock()
        ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
        config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_ssl_certkey',
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            key_exists=Mock(side_effect=[False, False]),
            key_identical=Mock(side_effect=[False, False]),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_ssl_certkey
            self.exited()
            ssl_certkey_proxy_mock.assert_not_called()
开发者ID:awiddersheim,项目名称:ansible,代码行数:34,代码来源:test_netscaler_ssl_certkey.py

示例6: test_present_server_update_immutable_attribute

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_present_server_update_immutable_attribute(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='present',
        ))
        from ansible.modules.network.netscaler import netscaler_ssl_certkey

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        ssl_certkey_proxy_attrs = {
            'diff_object.return_value': {},
        }
        ssl_certkey_proxy_mock = Mock()
        ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
        config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_ssl_certkey',
            nitro_exception=self.MockException,
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=['domain']),
            key_exists=Mock(side_effect=[True, True]),
            key_identical=Mock(side_effect=[False, False]),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_ssl_certkey
            result = self.failed()
            self.assertEqual(result['msg'], 'Cannot update immutable attributes [\'domain\']')
            self.assertTrue(result['failed'])
开发者ID:awiddersheim,项目名称:ansible,代码行数:36,代码来源:test_netscaler_ssl_certkey.py

示例7: test_present_server_identical_flow

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_present_server_identical_flow(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='present',
        ))
        from ansible.modules.network.netscaler import netscaler_server

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_attrs = {
            'diff_object.return_value': {},
        }
        server_proxy_mock = Mock()
        server_proxy_mock.configure_mock(**server_proxy_attrs)
        config_proxy_mock = Mock(return_value=server_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_server',
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            server_exists=Mock(side_effect=[True, True]),
            server_identical=Mock(side_effect=[True, True]),
            ConfigProxy=config_proxy_mock,
            do_state_change=Mock(return_value=Mock(errorcode=0))
        ):
            self.module = netscaler_server
            self.exited()
            server_proxy_mock.assert_not_called()
开发者ID:awiddersheim,项目名称:ansible,代码行数:35,代码来源:test_netscaler_server.py

示例8: test_new_ssl_certkey_execution_flow

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_new_ssl_certkey_execution_flow(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='present',
        ))
        from ansible.modules.network.netscaler import netscaler_ssl_certkey

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        ssl_certkey_proxy_attrs = {
            'diff_object.return_value': {},
        }
        ssl_certkey_proxy_mock = Mock()
        ssl_certkey_proxy_mock.configure_mock(**ssl_certkey_proxy_attrs)
        config_proxy_mock = Mock(return_value=ssl_certkey_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_ssl_certkey',
            get_nitro_client=m,
            key_exists=Mock(side_effect=[False, True]),
            key_identical=Mock(side_effect=[True]),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_ssl_certkey
            self.exited()
            ssl_certkey_proxy_mock.assert_has_calls([call.add()])
开发者ID:awiddersheim,项目名称:ansible,代码行数:32,代码来源:test_netscaler_ssl_certkey.py

示例9: test_absent_server_failed_delete

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_absent_server_failed_delete(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='absent',
        ))
        from ansible.modules.network.netscaler import netscaler_server

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_attrs = {
            'diff_object.return_value': {},
        }
        server_proxy_mock = Mock()
        server_proxy_mock.configure_mock(**server_proxy_attrs)
        config_proxy_mock = Mock(return_value=server_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_server',
            nitro_exception=self.MockException,
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            server_exists=Mock(side_effect=[True, True]),
            server_identical=Mock(side_effect=[False, False]),
            ConfigProxy=config_proxy_mock,
            do_state_change=Mock(return_value=Mock(errorcode=0))
        ):
            self.module = netscaler_server
            result = self.failed()
            self.assertEqual(result['msg'], 'Server seems to be present')
            self.assertTrue(result['failed'])
开发者ID:awiddersheim,项目名称:ansible,代码行数:37,代码来源:test_netscaler_server.py

示例10: test_new_gslb_vserver_execution_flow

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_new_gslb_vserver_execution_flow(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='present',
        ))
        from ansible.modules.network.netscaler import netscaler_gslb_vserver

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        glsb_service_proxy_attrs = {
            'diff_object.return_value': {},
        }
        gslb_service_proxy_mock = Mock()
        gslb_service_proxy_mock.configure_mock(**glsb_service_proxy_attrs)
        config_proxy_mock = Mock(return_value=gslb_service_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_gslb_vserver',
            get_nitro_client=m,
            gslb_vserver_exists=Mock(side_effect=[False, True]),
            gslb_vserver_identical=Mock(side_effect=[True]),
            nitro_exception=self.MockException,
            do_state_change=Mock(return_value=Mock(errorcode=0)),
            ensure_feature_is_enabled=Mock(),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_gslb_vserver
            self.exited()
            gslb_service_proxy_mock.assert_has_calls([call.add()])
开发者ID:awiddersheim,项目名称:ansible,代码行数:35,代码来源:test_netscaler_gslb_vserver.py

示例11: test_present_cs_action_failed_create

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_present_cs_action_failed_create(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='present',
        ))
        from ansible.modules.network.netscaler import netscaler_cs_action

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_attrs = {
            'diff_object.return_value': {},
        }
        cs_action_proxy_mock = Mock()
        cs_action_proxy_mock.configure_mock(**server_proxy_attrs)
        config_proxy_mock = Mock(return_value=cs_action_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_cs_action',
            nitro_exception=self.MockException,
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            action_exists=Mock(side_effect=[False, False]),
            action_identical=Mock(side_effect=[False, False]),
            ensure_feature_is_enabled=Mock(return_value=True),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_cs_action
            result = self.failed()
            self.assertEqual(result['msg'], 'Content switching action does not exist')
            self.assertTrue(result['failed'])
开发者ID:ernstp,项目名称:ansible,代码行数:37,代码来源:test_netscaler_cs_action.py

示例12: test_absent_cs_action_execution_flow

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_absent_cs_action_execution_flow(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='absent',
        ))
        from ansible.modules.network.netscaler import netscaler_cs_action

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_attrs = {
            'diff_object.return_value': {},
        }
        cs_action_proxy_mock = Mock()
        cs_action_proxy_mock.configure_mock(**server_proxy_attrs)
        config_proxy_mock = Mock(return_value=cs_action_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_cs_action',
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            action_exists=Mock(side_effect=[True, False]),
            action_identical=Mock(side_effect=[False, True]),
            ensure_feature_is_enabled=Mock(return_value=True),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_cs_action
            self.exited()
            cs_action_proxy_mock.assert_has_calls([call.delete()])
开发者ID:ernstp,项目名称:ansible,代码行数:35,代码来源:test_netscaler_cs_action.py

示例13: test_graceful_no_connection_error

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_graceful_no_connection_error(self):

        if sys.version_info[:2] == (2, 6):
            self.skipTest('requests library not available under python2.6')
        self.set_module_state('present')
        from ansible.modules.network.netscaler import netscaler_cs_policy

        client_mock = Mock()
        attrs = {'login.side_effect': requests.exceptions.ConnectionError}
        client_mock.configure_mock(**attrs)
        m = Mock(return_value=client_mock)
        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_cs_policy',
            get_nitro_client=m,
            nitro_exception=self.MockException,
        ):
            self.module = netscaler_cs_policy
            result = self.failed()
            self.assertTrue(result['msg'].startswith('Connection error'), msg='Connection error was not handled gracefully')
开发者ID:ernstp,项目名称:ansible,代码行数:21,代码来源:test_netscaler_cs_policy.py

示例14: test_cs_vserver_ssl_called

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_cs_vserver_ssl_called(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='present',
            servicetype='SSL',
        ))
        from ansible.modules.network.netscaler import netscaler_cs_vserver

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        server_proxy_attrs = {
            'diff_object.return_value': {},
        }
        cs_vserver_proxy_mock = Mock()
        cs_vserver_proxy_mock.configure_mock(**server_proxy_attrs)
        config_proxy_mock = Mock(return_value=cs_vserver_proxy_mock)
        ssl_certkey_bindings_sync_mock = Mock()

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_cs_vserver',
            nitro_exception=self.MockException,
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            cs_vserver_exists=Mock(side_effect=[True, True]),
            cs_vserver_identical=Mock(side_effect=[False, True]),
            ensure_feature_is_enabled=Mock(return_value=True),
            ssl_certkey_bindings_identical=Mock(side_effect=[False, True]),
            ssl_certkey_bindings_sync=ssl_certkey_bindings_sync_mock,
            do_state_change=Mock(return_value=Mock(errorcode=0)),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_cs_vserver
            result = self.exited()
            self.assertTrue(result['changed'])
            self.assertTrue(ssl_certkey_bindings_sync_mock.called)
开发者ID:awiddersheim,项目名称:ansible,代码行数:42,代码来源:test_netscaler_cs_vserver.py

示例15: test_present_gslb_vserver_service_bindings_error_flow

# 需要导入模块: from ansible.compat.tests.mock import Mock [as 别名]
# 或者: from ansible.compat.tests.mock.Mock import configure_mock [as 别名]
    def test_present_gslb_vserver_service_bindings_error_flow(self):
        set_module_args(dict(
            nitro_user='user',
            nitro_pass='pass',
            nsip='1.1.1.1',
            state='present',
        ))
        from ansible.modules.network.netscaler import netscaler_gslb_vserver

        client_mock = Mock()

        m = Mock(return_value=client_mock)

        glsb_service_proxy_attrs = {
            'diff_object.return_value': {},
        }
        gslb_service_proxy_mock = Mock()
        gslb_service_proxy_mock.configure_mock(**glsb_service_proxy_attrs)
        config_proxy_mock = Mock(return_value=gslb_service_proxy_mock)

        with patch.multiple(
            'ansible.modules.network.netscaler.netscaler_gslb_vserver',
            get_nitro_client=m,
            diff_list=Mock(return_value={}),
            get_immutables_intersection=Mock(return_value=[]),
            gslb_vserver_exists=Mock(side_effect=[True, True]),
            gslb_vserver_identical=Mock(side_effect=[True, True, True]),
            service_bindings_identical=Mock(side_effect=[False, False, False]),
            do_state_change=Mock(return_value=Mock(errorcode=0)),
            nitro_exception=self.MockException,
            ensure_feature_is_enabled=Mock(),
            ConfigProxy=config_proxy_mock,
        ):
            self.module = netscaler_gslb_vserver
            result = self.failed()
            self.assertEqual(result['msg'], 'Service bindings differ from configured')
            self.assertTrue(result['failed'])
开发者ID:awiddersheim,项目名称:ansible,代码行数:39,代码来源:test_netscaler_gslb_vserver.py


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