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.modules.network.netscaler import netscaler_server

        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.modules.network.netscaler.netscaler_server.get_nitro_client',
                m):
            with patch(
                    'ansible.modules.network.netscaler.netscaler_server.nitro_exception',
                    MockException):
                self.module = netscaler_server
                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.modules.network.netscaler import netscaler_cs_policy

        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.modules.network.netscaler.netscaler_cs_policy.get_nitro_client', m):
            with patch('ansible.modules.network.netscaler.netscaler_cs_policy.nitro_exception', MockException):
                self.module = netscaler_cs_policy
                result = self.failed()
                self.assertTrue(result['msg'].startswith('nitro exception'), msg='nitro exception during login not handled properly')