def test_graceful_nitro_error_on_login(self): set_module_args( dict( nitro_user='******', nitro_pass='******', nsip='192.0.2.1', state='present', )) from ansible_collections.notmintest.not_a_real_collection.plugins.modules import netscaler_lb_monitor class MockException(Exception): def __init__(self, *args, **kwargs): self.errorcode = 0 self.message = '' client_mock = Mock() client_mock.login = Mock(side_effect=MockException) m = Mock(return_value=client_mock) with patch.multiple( 'ansible_collections.notmintest.not_a_real_collection.plugins.modules.netscaler_lb_monitor', get_nitro_client=m, nitro_exception=MockException, ): self.module = netscaler_lb_monitor result = self.failed() self.assertTrue( result['msg'].startswith('nitro exception'), msg='nitro exception during login not handled properly')
def test_graceful_nitro_error_on_login(self): self.set_module_state('present') from ansible_collections.notmintest.not_a_real_collection.plugins.modules import netscaler_servicegroup class MockException(Exception): def __init__(self, *args, **kwargs): self.errorcode = 0 self.message = '' client_mock = Mock() client_mock.login = Mock(side_effect=MockException) m = Mock(return_value=client_mock) with patch('ansible_collections.notmintest.not_a_real_collection.plugins.modules.netscaler_servicegroup.get_nitro_client', m): with patch('ansible_collections.notmintest.not_a_real_collection.plugins.modules.netscaler_servicegroup.nitro_exception', MockException): self.module = netscaler_servicegroup result = self.failed() self.assertTrue(result['msg'].startswith('nitro exception'), msg='nitro exception during login not handled properly')