def test_alert_policy_exists_false(self, mock_set_clc_creds): test_params = {"alias": "testalias", "state": "absent"} self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {"12345": {"id": "12345", "name": "test1"}, "23456": {"id": "23456", "name": "test2"}} res = under_test._alert_policy_exists("notfound") self.assertEqual(res, False)
def test_get_alert_policy_id_fail_duplicate_names(self, mock_set_clc_creds): test_params = {"alias": "testalias", "state": "absent"} self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {"12345": {"id": "12345", "name": "test1"}, "23456": {"id": "23456", "name": "test1"}} policy_id = under_test._get_alert_policy_id(self.module, "test1") self.module.fail_json.assert_called_once_with(msg="multiple alert policies were found with policy name : test1")
def test_get_alert_policy_id(self, mock_set_clc_creds): test_params = {"alias": "testalias", "state": "absent"} self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {"12345": {"id": "12345", "name": "test1"}, "23456": {"id": "23456", "name": "test2"}} policy_id = under_test._get_alert_policy_id(self.module, "test2") self.assertEqual(policy_id, "23456")
def test_ensure_alert_policy_is_absent_no_id_no_name(self, mock_set_clc_creds, mock_get_id, mock_delete): test_params = {"alias": "testalias", "state": "absent"} mock_get_id.return_value = "12345" mock_delete.return_value = "success" self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {"12345", "23456"} changed, policy = under_test._ensure_alert_policy_is_absent() self.module.fail_json.assert_called_once_with(msg="Either alert policy id or policy name is required")
def test_alert_policy_exists_false(self, mock_set_clc_creds): test_params = { 'alias': 'testalias' , 'state': 'absent' } self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {'12345': {'id': '12345', 'name': 'test1'}, '23456': {'id': '23456', 'name': 'test2'}} res = under_test._alert_policy_exists('notfound') self.assertEqual(res, False)
def test_get_alert_policy_id_fail_duplicate_names(self, mock_set_clc_creds): test_params = { 'alias': 'testalias' , 'state': 'absent' } self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {'12345': {'id': '12345', 'name': 'test1'}, '23456': {'id': '23456', 'name': 'test1'}} policy_id = under_test._get_alert_policy_id(self.module, 'test1') self.module.fail_json.assert_called_once_with(msg='multiple alert policies were found with policy name : test1')
def test_get_alert_policy_id(self, mock_set_clc_creds): test_params = { 'alias': 'testalias' , 'state': 'absent' } self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {'12345': {'id': '12345', 'name': 'test1'}, '23456': {'id': '23456', 'name': 'test2'}} policy_id = under_test._get_alert_policy_id(self.module, 'test2') self.assertEqual(policy_id, '23456')
def test_ensure_alert_policy_is_absent_no_id_no_name( self, mock_set_clc_creds, mock_get_id, mock_delete): test_params = {'alias': 'testalias', 'state': 'absent'} mock_get_id.return_value = '12345' mock_delete.return_value = 'success' self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {'12345', '23456'} changed, policy = under_test._ensure_alert_policy_is_absent() self.module.fail_json.assert_called_once_with( msg='Either alert policy id or policy name is required')
def test_ensure_alert_policy_is_absent_no_id_present(self, mock_set_clc_creds, mock_get_id, mock_delete): test_params = {"id": "testid", "alias": "testalias", "state": "absent"} mock_get_id.return_value = "12345" mock_delete.return_value = "success" self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {"12345", "23456"} changed, policy = under_test._ensure_alert_policy_is_absent() self.assertEqual(changed, False) self.assertEqual(policy, None) self.assertFalse(self.module.fail_json.called)
def test_ensure_alert_policy_is_absent_no_id_no_name(self, mock_set_clc_creds, mock_get_id, mock_delete): test_params = { 'alias': 'testalias' , 'state': 'absent' } mock_get_id.return_value = '12345' mock_delete.return_value = 'success' self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {'12345', '23456'} changed, policy = under_test._ensure_alert_policy_is_absent() self.module.fail_json.assert_called_once_with(msg='Either alert policy id or policy name is required')
def test_ensure_alert_policy_is_absent_no_id_present( self, mock_set_clc_creds, mock_get_id, mock_delete): test_params = {'id': 'testid', 'alias': 'testalias', 'state': 'absent'} mock_get_id.return_value = '12345' mock_delete.return_value = 'success' self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {'12345', '23456'} changed, policy = under_test._ensure_alert_policy_is_absent() self.assertEqual(changed, False) self.assertEqual(policy, None) self.assertFalse(self.module.fail_json.called)
def test_ensure_alert_policy_is_absent_no_id_present(self, mock_set_clc_creds, mock_get_id, mock_delete): test_params = { 'id': 'testid' , 'alias': 'testalias' , 'state': 'absent' } mock_get_id.return_value = '12345' mock_delete.return_value = 'success' self.module.params = test_params self.module.check_mode = False under_test = ClcAlertPolicy(self.module) under_test.policy_dict = {'12345', '23456'} changed, policy = under_test._ensure_alert_policy_is_absent() self.assertEqual(changed, False) self.assertEqual(policy,None) self.assertFalse(self.module.fail_json.called)