def test_create_new_lb_monitor_workflow(self): set_module_args( dict( nitro_user='******', nitro_pass='******', nsip='192.0.2.1', state='present', save_config=False, )) from ansible_collections.community.network.plugins.modules.network.netscaler import netscaler_lb_monitor lb_monitor_proxy_mock = Mock(diff_object=Mock(return_value={})) with patch.multiple( 'ansible_collections.community.network.plugins.modules.network.netscaler.netscaler_lb_monitor', get_nitro_client=Mock(return_value=Mock()), lbmonitor_exists=Mock(side_effect=[False, True]), lbmonitor_identical=Mock(side_effect=[True]), ConfigProxy=Mock(return_value=lb_monitor_proxy_mock), ensure_feature_is_enabled=Mock(return_value=True), ): self.module = netscaler_lb_monitor result = self.exited() lb_monitor_proxy_mock.assert_has_calls([call.add()]) self.assertTrue(result['changed'])
def test_new_gslb_site_execution_flow(self): set_module_args( dict( nitro_user='******', nitro_pass='******', nsip='192.0.2.1', state='present', )) from ansible_collections.community.network.plugins.modules.network.netscaler import netscaler_gslb_service 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_collections.community.network.plugins.modules.network.netscaler.netscaler_gslb_service', get_nitro_client=m, gslb_service_exists=Mock(side_effect=[False, True]), gslb_service_identical=Mock(side_effect=[True]), nitro_exception=self.MockException, ensure_feature_is_enabled=Mock(), monkey_patch_nitro_api=Mock(), ConfigProxy=config_proxy_mock, ): self.module = netscaler_gslb_service self.exited() gslb_service_proxy_mock.assert_has_calls([call.add()])
def test_new_ssl_certkey_execution_flow(self): set_module_args( dict( nitro_user='******', nitro_pass='******', nsip='192.0.2.1', state='present', )) from ansible_collections.community.network.plugins.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_collections.community.network.plugins.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()])
def test_new_cs_vserver_execution_flow(self): set_module_args( dict( nitro_user='******', nitro_pass='******', nsip='192.0.2.1', state='present', )) from ansible_collections.community.network.plugins.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) with patch.multiple( 'ansible_collections.community.network.plugins.modules.network.netscaler.netscaler_cs_vserver', get_nitro_client=m, cs_vserver_exists=Mock(side_effect=[False, True]), cs_vserver_identical=Mock(side_effect=[True]), ensure_feature_is_enabled=Mock(return_value=True), ConfigProxy=config_proxy_mock, nitro_exception=self.MockException, do_state_change=Mock(return_value=Mock(errorcode=0)), ): self.module = netscaler_cs_vserver self.exited() cs_vserver_proxy_mock.assert_has_calls([call.add()])
def test_create_non_existing_service(self): self.set_module_state('present') from ansible_collections.community.network.plugins.modules.network.netscaler import netscaler_service service_proxy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } service_proxy_mock.configure_mock(**attrs) m = MagicMock(return_value=service_proxy_mock) service_exists_mock = Mock(side_effect=[False, True]) with patch.multiple( 'ansible_collections.community.network.plugins.modules.network.netscaler.netscaler_service', ConfigProxy=m, service_exists=service_exists_mock, do_state_change=Mock(return_value=Mock(errorcode=0)), ): self.module = netscaler_service result = self.exited() service_proxy_mock.assert_has_calls([call.add()]) self.assertTrue(result['changed'], msg='Change not recorded')
def test_create_non_existing_cs_policy(self): self.set_module_state('present') from ansible_collections.community.network.plugins.modules.network.netscaler import netscaler_cs_policy cs_policy_mock = MagicMock() attrs = { 'diff_object.return_value': {}, } cs_policy_mock.configure_mock(**attrs) m = MagicMock(return_value=cs_policy_mock) policy_exists_mock = Mock(side_effect=[False, True]) with patch.multiple( 'ansible_collections.community.network.plugins.modules.network.netscaler.netscaler_cs_policy', ConfigProxy=m, policy_exists=policy_exists_mock, nitro_exception=self.MockException, ensure_feature_is_enabled=Mock(), ): self.module = netscaler_cs_policy result = self.exited() cs_policy_mock.assert_has_calls([call.add()]) self.assertTrue(result['changed'], msg='Change not recorded')