diff --git a/churchtools_api/groups.py b/churchtools_api/groups.py index e0282ef..bcc7046 100644 --- a/churchtools_api/groups.py +++ b/churchtools_api/groups.py @@ -376,3 +376,41 @@ def get_group_roles(self, group_id: int): else: logging.warning( "Something went wrong fetching group roles: {}".format(response.status_code)) + + def add_parent_group(self, group_id: int, parent_group_id: int): + """ + Add a parent for a group + :param group_id: int: required group id + :param parent_group_id: int: required parent group id + :return: True if successful + :rtype: bool + """ + url = self.domain + \ + '/api/groups/{}/parents/{}'.format(group_id, parent_group_id) + response = self.session.put(url=url) + + if response.status_code == 201: + logging.debug("First response of Add Parent Group successful") + return True + else: + logging.warning("Something went wrong adding parent group: {}".format( + response.status_code)) + + def delete_parent_group(self, group_id: int, parent_group_id: int): + """ + Delete a parent from a group + :param group_id: int: required group id + :param parent_group_id: int: required parent group id + :return: True if successful + :rtype: bool + """ + url = self.domain + \ + '/api/groups/{}/parents/{}'.format(group_id, parent_group_id) + response = self.session.delete(url=url) + + if response.status_code == 204: + logging.debug("First response of Delete Parent Group successful") + return True + else: + logging.warning("Something went wrong deleting parent group: {}".format( + response.status_code)) diff --git a/tests/test_churchtools_api.py b/tests/test_churchtools_api.py index c7e0cb7..041c091 100644 --- a/tests/test_churchtools_api.py +++ b/tests/test_churchtools_api.py @@ -361,6 +361,17 @@ def test_get_group_roles(self): self.assertIn('groupTypeId', role) self.assertIn('name', role) + def test_add_and_remove_parent_group(self): + """ + Checks if a parent group can be added to and removed from a group + :return: + """ + ret = self.api.add_parent_group(group_id=103, parent_group_id=104) + self.assertTrue(ret) + + ret = self.api.remove_parent_group(group_id=103, parent_group_id=104) + self.assertTrue(ret) + def test_get_global_permissions(self): """ IMPORTANT - This test method and the parameters used depend on the target system!