From ae5e2f59dead89b65e7e3ec97ab389d7acaae6d9 Mon Sep 17 00:00:00 2001 From: bensteUEM Date: Fri, 4 Oct 2024 19:21:52 +0200 Subject: [PATCH] fix get_groups_members params #112 --- churchtools_api/groups.py | 9 ++++++--- tests/test_churchtools_api.py | 12 ++++++++++++ 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/churchtools_api/groups.py b/churchtools_api/groups.py index 4881ced..7dce788 100644 --- a/churchtools_api/groups.py +++ b/churchtools_api/groups.py @@ -334,7 +334,7 @@ def get_groups_members( """ url = self.domain + "/api/groups/members" headers = {"accept": "application/json"} - params = {} + params = {"ids[]": group_ids, with_deleted: with_deleted} response = self.session.get(url=url, headers=headers, params=params) @@ -342,7 +342,7 @@ def get_groups_members( response_content = json.loads(response.content) response_data = self.combine_paginated_response_data( - response_content, url=url, headers=headers + response_content, url=url, headers=headers, params=params ) result_list = ( [response_data] if isinstance(response_data, dict) else response_data @@ -363,7 +363,10 @@ def get_groups_members( return result_list else: logger.warning( - "%s Something went wrong fetching group members: %s", response.status_code, response.content) + "%s Something went wrong fetching group members: %s", + response.status_code, + response.content, + ) def add_group_member(self, group_id: int, person_id: int, **kwargs) -> dict: """Add a member to a group. diff --git a/tests/test_churchtools_api.py b/tests/test_churchtools_api.py index d4cc474..296307e 100644 --- a/tests/test_churchtools_api.py +++ b/tests/test_churchtools_api.py @@ -405,6 +405,18 @@ def test_get_groups_members(self) -> None: compare_result = [group["groupId"] for group in group_result] self.assertIn(EXPECTED_GROUP_ID, compare_result) + # 3. problematic result group_ids, grouptype_role_ids and person_id + SAMPLE_GROUP_IDS = [99, 68, 93] + SAMPLE_GROUPTYPE_ROLE_IDS = [9, 16] + SAMPLE_PERSON_IDS = [54] + + result = self.api.get_groups_members( + group_ids=SAMPLE_GROUP_IDS, + grouptype_role_ids=SAMPLE_GROUPTYPE_ROLE_IDS, + person_ids=SAMPLE_PERSON_IDS, + ) + assert len(result) == 1 + def test_add_and_remove_group_members(self)->None: """IMPORTANT - This test method and the parameters used depend on the target system! the hard coded sample exists on ELKW1610.KRZ.TOOLS.