Skip to content

Commit

Permalink
Implement [add/remove]_parent_group()
Browse files Browse the repository at this point in the history
Closes #90
  • Loading branch information
fschrempf committed Nov 29, 2023
1 parent ff557bb commit 59fecc5
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 0 deletions.
38 changes: 38 additions & 0 deletions churchtools_api/groups.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
11 changes: 11 additions & 0 deletions tests/test_churchtools_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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!
Expand Down

0 comments on commit 59fecc5

Please sign in to comment.