Skip to content

Commit 1de0b28

Browse files
committed
feat(groups): implement get_groups params passthrough and pre-test cleanup
1 parent af8a472 commit 1de0b28

2 files changed

Lines changed: 13 additions & 4 deletions

File tree

churchtools_api/groups.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ def get_groups(self, **kwargs: dict) -> list[dict]:
2626
2727
Keywords:
2828
group_id: int: optional filter by group id (only to be used on it's own)
29-
kwargs: keyword arguments passthrough
29+
kwargs: keyword arguments passthrough e.g. query
3030
3131
Keywords:
3232
group_id
@@ -39,11 +39,14 @@ def get_groups(self, **kwargs: dict) -> list[dict]:
3939
4040
"""
4141
url = self.domain + "/api/groups"
42+
params = {}
4243
if "group_id" in kwargs:
4344
url = url + "/{}".format(kwargs["group_id"])
45+
else:
46+
params = {**kwargs}
4447

4548
headers = {"accept": "application/json"}
46-
response = self.session.get(url=url, headers=headers)
49+
response = self.session.get(url=url, headers=headers, params=params)
4750

4851
if response.status_code == requests.codes.ok:
4952
response_content = json.loads(response.content)

tests/test_churchtools_api_groups.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,7 @@ def test_create_and_delete_group(self, caplog: pytest.LogCaptureFixture) -> None
125125
IMPORTANT - This test method and the parameters used depend on target system!
126126
the hard coded sample exists on ELKW1610.KRZ.TOOLS.
127127
128+
0. delete any group which contains sample group name to have clean system setup
128129
1. with minimal parameters.
129130
2. More complex group information
130131
3. Checks if a group can not be created with name of an existing group
@@ -134,9 +135,15 @@ def test_create_and_delete_group(self, caplog: pytest.LogCaptureFixture) -> None
134135
SAMPLE_NEW_GROUP_TYPE = 2
135136
SAMPLE_GROUP_STATUS_ID = 1
136137
SAMPLE_CAMPUS_ID = 0
138+
SAMPLE_GROUP_NAME = "TestGroup"
139+
SAMPLE_GROUP_NAME2 = "TestGroup With Campus And Superior"
140+
141+
# 0. cleanup delete existing groups which contain name sample_group_name
142+
existing_groups = self.api.get_groups(query=SAMPLE_GROUP_NAME)
143+
for group in existing_groups:
144+
self.api.delete_group(group_id=group["id"])
137145

138146
# 1. minimal group
139-
SAMPLE_GROUP_NAME = "TestGroup"
140147

141148
group1 = self.api.create_group(
142149
SAMPLE_GROUP_NAME,
@@ -149,7 +156,6 @@ def test_create_and_delete_group(self, caplog: pytest.LogCaptureFixture) -> None
149156
assert group1["information"]["groupStatusId"] == SAMPLE_GROUP_STATUS_ID
150157

151158
# 2. more complex group
152-
SAMPLE_GROUP_NAME2 = "TestGroup With Campus And Superior"
153159
group2 = self.api.create_group(
154160
SAMPLE_GROUP_NAME2,
155161
group_status_id=SAMPLE_GROUP_STATUS_ID,

0 commit comments

Comments
 (0)