def test_ensure_group_is_present_parent_and_group_exist(self): # Setup Test mock_group = mock.MagicMock() mock_group.name = "MockGroup" mock_parent = mock.MagicMock() mock_parent.name = "MockParent" mock_parent.Create.return_value = mock_group mock_grandparent = mock.MagicMock() mock_grandparent.name = "MockGrandparent" mock_rootgroup = mock.MagicMock() mock_rootgroup.name = "MockRootGroup" mock_group_dict = {mock_parent.name: (mock_parent, mock_grandparent), mock_group.name: (mock_group, mock_parent)} under_test = ClcGroup(self.module) under_test.group_dict = mock_group_dict under_test.root_group = mock_rootgroup # Test result_changed, result_group = under_test._ensure_group_is_present( group_name=mock_group.name, parent_name=mock_parent.name, group_description="Mock Description") # Assert Expected Result self.assertFalse(result_changed) self.assertEqual(result_group, mock_group) self.assertFalse(self.module.fail_json.called)
def test_ensure_group_is_present_parent_not_exist(self): # Setup Test mock_group = mock.MagicMock() mock_group.name = "MockGroup" mock_parent = mock.MagicMock() mock_parent.name = "MockParent" mock_rootgroup = mock.MagicMock() mock_rootgroup.name = "MockRootGroup" mock_group_dict = {} under_test = ClcGroup(self.module) under_test.group_dict = mock_group_dict under_test.root_group = mock_rootgroup # Test result_changed, result_group = under_test._ensure_group_is_present( group_name=mock_group.name, parent_name=mock_parent.name, group_description="Mock Description") # Assert Expected Result self.module.fail_json.assert_called_once_with( msg="parent group: " + mock_parent.name + " does not exist")
def test_process_request_state_present(self, mock_set_creds, mock_clc_sdk): self.module.params = { 'location': 'UC1', 'name': 'MyCoolGroup', 'parent': 'Default Group', 'description': 'Test Group', 'state': 'present', 'wait': 'True' } mock_group = mock.MagicMock() mock_group.data = {"name": "MyCoolGroup"} under_test = ClcGroup(self.module) under_test.set_clc_credentials_from_env = mock.MagicMock() under_test._ensure_group_is_present = mock.MagicMock( return_value=( True, mock_group)) under_test.process_request() self.assertFalse(self.module.fail_json.called) self.module.exit_json.assert_called_once_with( changed=True, group=mock_group.data)
def test_ensure_group_is_present_parent_and_group_exist(self): # Setup Test mock_group = mock.MagicMock() mock_group.name = "MockGroup" mock_parent = mock.MagicMock() mock_parent.name = "MockParent" mock_parent.Create.return_value = mock_group mock_grandparent = mock.MagicMock() mock_grandparent.name = "MockGrandparent" mock_rootgroup = mock.MagicMock() mock_rootgroup.name = "MockRootGroup" mock_group_dict = { mock_parent.name: (mock_parent, mock_grandparent), mock_group.name: (mock_group, mock_parent) } under_test = ClcGroup(self.module) under_test.group_dict = mock_group_dict under_test.root_group = mock_rootgroup # Test result_changed, result_group = under_test._ensure_group_is_present( group_name=mock_group.name, parent_name=mock_parent.name, group_description="Mock Description") # Assert Expected Result self.assertFalse(result_changed) self.assertEqual(result_group, mock_group) self.assertFalse(self.module.fail_json.called)
def test_ensure_group_is_present_parent_not_exist(self): # Setup Test mock_group = mock.MagicMock() mock_group.name = "MockGroup" mock_parent = mock.MagicMock() mock_parent.name = "MockParent" mock_rootgroup = mock.MagicMock() mock_rootgroup.name = "MockRootGroup" mock_group_dict = {} under_test = ClcGroup(self.module) under_test.group_dict = mock_group_dict under_test.root_group = mock_rootgroup # Test result_changed, result_group = under_test._ensure_group_is_present( group_name=mock_group.name, parent_name=mock_parent.name, group_description="Mock Description") # Assert Expected Result self.module.fail_json.assert_called_once_with( msg="parent group: " + mock_parent.name + " does not exist")
def test_process_request_state_present(self, mock_set_creds, mock_clc_sdk): self.module.params = { 'location': 'UC1', 'name': 'MyCoolGroup', 'parent': 'Default Group', 'description': 'Test Group', 'state': 'present', 'wait': 'True' } mock_group = mock.MagicMock() mock_group.data = {"name": "MyCoolGroup"} under_test = ClcGroup(self.module) under_test.set_clc_credentials_from_env = mock.MagicMock() under_test._ensure_group_is_present = mock.MagicMock( return_value=(True, mock_group)) under_test.process_request() self.assertFalse(self.module.fail_json.called) self.module.exit_json.assert_called_once_with(changed=True, group=mock_group.data)