Skip to content

Commit cc4a1df

Browse files
committed
updated test cases to env and improved logging hints #106
1 parent 04f1001 commit cc4a1df

5 files changed

Lines changed: 44 additions & 35 deletions

File tree

churchtools_api/groups.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ def get_groups(self, **kwargs) -> list[dict]:
2121
Keywords:
2222
group_id: int: optional filter by group id (only to be used on it's own)
2323
24+
Permissions:
25+
requires "view group" for all groups which should be considered
26+
2427
Returns:
2528
list of groups - either all or filtered by keyword
2629
@@ -42,7 +45,7 @@ def get_groups(self, **kwargs) -> list[dict]:
4245
return response_data
4346
else:
4447
logger.warning(
45-
"Something went wrong fetching groups: {}".format(response.status_code)
48+
"%s Something went wrong fetching groups: %s",response.status_code, response.content
4649
)
4750

4851
def get_groups_hierarchies(self):
@@ -121,6 +124,7 @@ def create_group(
121124
122125
Required Permissions:
123126
administer groups
127+
create group of grouptype
124128
125129
Returns:
126130
dict with created group group - similar to get_group
@@ -157,9 +161,7 @@ def create_group(
157161
return response_data
158162
else:
159163
logger.warning(
160-
"Something went wrong with creating group: {}".format(
161-
response.status_code
162-
)
164+
"%s Something went wrong with creating group: %s", response.status_code, response.content
163165
)
164166

165167
def update_group(self, group_id: int, data: dict):
@@ -197,6 +199,9 @@ def delete_group(self, group_id: int) -> bool:
197199
Arguments:
198200
group_id: group_id
199201
202+
Required Permissions
203+
delete group
204+
200205
Returns:
201206
True if successful
202207
"""
@@ -409,6 +414,8 @@ def remove_group_member(self, group_id: int, person_id: int) -> bool:
409414
group_id: int: required group id
410415
person_id: int: required person id
411416
417+
Required Permissions:
418+
edit group memberships of groups
412419
Returns:
413420
True if successful
414421
"""
@@ -419,9 +426,7 @@ def remove_group_member(self, group_id: int, person_id: int) -> bool:
419426
return True
420427
else:
421428
logger.warning(
422-
"Something went wrong removing group member: {}".format(
423-
response.status_code
424-
)
429+
"%s Something went wrong removing group member: %s", response.status_code, response.content
425430
)
426431

427432
def get_group_roles(self, group_id: int) -> list[dict]:
@@ -460,6 +465,9 @@ def add_parent_group(self, group_id: int, parent_group_id: int) -> bool:
460465
group_id: required group id
461466
parent_group_id: required parent group id
462467
468+
Required Permissions:
469+
administer groups
470+
463471
Returns:
464472
True if successful
465473
"""
@@ -472,10 +480,8 @@ def add_parent_group(self, group_id: int, parent_group_id: int) -> bool:
472480
logger.debug("First response of Add Parent Group successful")
473481
return True
474482
else:
475-
logger.warning(
476-
"Something went wrong adding parent group: {}".format(
477-
response.status_code
478-
)
483+
logger.warning(
484+
"%s Something went wrong adding parent group: %s",response.status_code, response.content
479485
)
480486

481487
def remove_parent_group(self, group_id: int, parent_group_id: int) -> bool:

tests/test_churchtools_api.py

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -138,12 +138,12 @@ def test_get_songs(self) -> None:
138138
IMPORTANT - This test method and the parameters used depend on the target system!
139139
the hard coded sample exists on ELKW1610.KRZ.TOOLS
140140
"""
141-
test_song_id = 2034
141+
SAMPLE_SONG_ID = 2034
142142

143143
songs = self.api.get_songs()
144144
self.assertGreater(len(songs), 50)
145145

146-
song = self.api.get_songs(song_id=test_song_id)[0]
146+
song = self.api.get_songs(song_id=SAMPLE_SONG_ID)[0]
147147
self.assertEqual(song["id"], 2034)
148148
self.assertEqual(song["name"], "sample")
149149

@@ -154,13 +154,13 @@ def test_get_song_ajax(self):
154154
IMPORTANT - This test method and the parameters used depend on the target system!
155155
:return:
156156
"""
157-
test_song_id = 408
158-
song = self.api.get_song_ajax(song_id=test_song_id)
157+
SAMPLE_SONG_ID = 2034
158+
song = self.api.get_song_ajax(song_id=SAMPLE_SONG_ID)
159159
self.assertIsInstance(song, dict)
160160
self.assertEqual(len(song), 14)
161161

162-
self.assertEqual(int(song['id']), test_song_id)
163-
self.assertEqual(song['bezeichnung'], 'Test')
162+
self.assertEqual(int(song['id']), SAMPLE_SONG_ID)
163+
self.assertEqual(song['bezeichnung'], 'sample')
164164

165165
def test_get_song_category_map(self):
166166
"""
@@ -654,15 +654,16 @@ def test_get_songs_with_tag(self):
654654
"""
655655
Test method to check if fetching all songs with a specific tag works
656656
songId and tag_id will vary depending on the server used
657-
On ELKW1610.KRZ.TOOLS song ID 408 is the first song with tag 53 "Test"
657+
On ELKW1610.KRZ.TOOLS song ID 408 is tagged with 53 "Test"
658658
:return:
659659
"""
660-
tagId = 53
661-
songId = 408
660+
SAMPLE_TAG_ID = 53
661+
SAMPLE_SONG_ID = 408
662662

663663
self.api.ajax_song_last_update = None
664-
result = self.api.get_songs_by_tag(tagId)
665-
self.assertEqual(songId, result[0]['id'])
664+
result = self.api.get_songs_by_tag(SAMPLE_TAG_ID)
665+
result_ids = [song['id'] for song in result]
666+
self.assertIn(SAMPLE_SONG_ID, result_ids)
666667

667668
def test_file_download(self):
668669
""" Test of file_download and file_download_from_url on https://elkw1610.krz.tools on any song

tests/test_churchtools_api_calendars.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,6 @@ def test_get_calendar_appointments_none(self):
165165
"""
166166
# Appointment Series by ID
167167
result = self.api.get_calendar_appointments(
168-
calendar_ids=[52], from_="2023-12-03", to_="2023-12-04")
168+
calendar_ids=[52], from_="2023-12-01", to_="2023-12-02")
169169

170170
self.assertIsNone(result)

tests/test_churchtools_api_events.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -137,14 +137,14 @@ def test_get_AllEventData_ajax(self):
137137
IMPORTANT - This test method and the parameters used depend on the target system!
138138
139139
Test function to check the get_AllEventData_ajax function for a specific ID
140-
On ELKW1610.KRZ.TOOLS event ID 3396 is an existing Test Event with schedule (1. Jan 2024)
140+
On ELKW1610.KRZ.TOOLS event ID 3348 is an existing Test Event with schedule (29. Sept 2024)
141141
Please be aware that this function is limited to the timeframe configured for cache in CT (by default -90days)
142142
:return:
143143
"""
144-
eventId = 3396
145-
result = self.api.get_AllEventData_ajax(eventId)
144+
SAMPLE_EVENT_ID = 3348
145+
result = self.api.get_AllEventData_ajax(SAMPLE_EVENT_ID)
146146
self.assertIn('id', result.keys())
147-
self.assertEqual(result['id'], str(eventId))
147+
self.assertEqual(result['id'], str(SAMPLE_EVENT_ID))
148148

149149
def test_get_set_event_services_counts(self):
150150
"""
@@ -185,26 +185,26 @@ def test_get_set_event_admins(self):
185185
IMPORTANT - This test method and the parameters used depend on the target system!
186186
187187
Test function to get list of event admins, change it and check again (and reset to original)
188-
On ELKW1610.KRZ.TOOLS event ID 3396 is an existing Test Event with schedule (1. Jan 2024)
188+
On ELKW1610.KRZ.TOOLS event ID 3348 is an existing Event with schedule (29. Sept 2024)
189189
Please be aware that this function is limited to the timeframe configured for cache in CT (by default -90days)
190190
:return:
191191
"""
192-
eventId = 3396
193-
admin_ids_original_test = [9]
192+
SAMPLE_EVENT_ID = 3348
193+
EXPECTED_ADMIN_IDS = [336]
194194

195-
admin_ids_original = self.api.get_event_admins_ajax(eventId)
196-
self.assertEqual(admin_ids_original, admin_ids_original_test)
195+
admin_ids_original = self.api.get_event_admins_ajax(SAMPLE_EVENT_ID)
196+
self.assertEqual(admin_ids_original, EXPECTED_ADMIN_IDS)
197197

198198
admin_ids_change = [0, 1, 2]
199-
result = self.api.set_event_admins_ajax(eventId, admin_ids_change)
199+
result = self.api.set_event_admins_ajax(SAMPLE_EVENT_ID, admin_ids_change)
200200
self.assertTrue(result)
201201

202-
admin_ids_test = self.api.get_event_admins_ajax(eventId)
202+
admin_ids_test = self.api.get_event_admins_ajax(SAMPLE_EVENT_ID)
203203
self.assertEqual(admin_ids_change, admin_ids_test)
204204

205205
self.assertTrue(
206206
self.api.set_event_admins_ajax(
207-
eventId, admin_ids_original_test))
207+
SAMPLE_EVENT_ID, EXPECTED_ADMIN_IDS))
208208

209209
def test_get_event_masterdata(self):
210210
"""

tests/test_churchtools_api_resources.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,8 @@ def test_get_booking_from_to_date(self, caplog):
169169
"_to": datetime(year=2024, month=9, day=30),
170170
}
171171

172+
caplog.set_level(logging.WARNING)
173+
172174
result = self.api.get_bookings(
173175
_from=SAMPLE_DATES["_from"],
174176
_to=SAMPLE_DATES["_to"],

0 commit comments

Comments
 (0)