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 Dec 1, 2023
1 parent 74759bd commit 257b06c
Show file tree
Hide file tree
Showing 2 changed files with 57 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 @@ -377,3 +377,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 group 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 remove_parent_group(self, group_id: int, parent_group_id: int):
"""
REmove a parent group 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 Remove Parent Group successful")
return True
else:
logging.warning("Something went wrong removing parent group: {}".format(
response.status_code))
19 changes: 19 additions & 0 deletions tests/test_churchtools_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,25 @@ 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:
"""
test_group_id = 103
test_parent_group_id = 104
ret = self.api.add_parent_group(
group_id=test_group_id,
parent_group_id=test_parent_group_id
)
self.assertTrue(ret)

ret = self.api.remove_parent_group(
group_id=test_group_id,
parent_group_id=test_parent_group_id
)
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 257b06c

Please sign in to comment.