Skip to content

Commit 577dbd1

Browse files
committed
increase pagination to 50 per request for some endpoints - Fixes #95
1 parent 57230f3 commit 577dbd1

5 files changed

Lines changed: 14 additions & 13 deletions

File tree

churchtools_api/events.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def get_events(self, **kwargs) -> list[dict]:
4242
headers = {
4343
'accept': 'application/json'
4444
}
45-
params = {}
45+
params = {"limit":50} #increases default pagination size
4646

4747
if 'eventId' in kwargs.keys():
4848
url += '/{}'.format(kwargs['eventId'])
@@ -75,12 +75,12 @@ def get_events(self, **kwargs) -> list[dict]:
7575
if 'include' in kwargs.keys():
7676
params['include'] = kwargs['include']
7777

78-
response = self.session.get(url=url, params=params, headers=headers)
78+
response = self.session.get(url=url, headers=headers, params=params)
7979

8080
if response.status_code == 200:
8181
response_content = json.loads(response.content)
8282
response_data = self.combine_paginated_response_data(
83-
response_content, url=url, headers=headers
83+
response_content, url=url, headers=headers, params=params
8484
)
8585
return [response_data] if isinstance(response_data, dict) else response_data
8686
else:

churchtools_api/persons.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ def get_persons(self, **kwargs):
2424
:rtype: list[dict]
2525
"""
2626
url = self.domain + '/api/persons'
27-
params = {}
27+
params = {"limit":50} #increases default pagination size
2828
if 'ids' in kwargs.keys():
2929
params['ids[]'] = kwargs['ids']
3030

3131
headers = {
3232
'accept': 'application/json'
3333
}
34-
response = self.session.get(url=url, params=params, headers=headers)
34+
response = self.session.get(url=url, headers=headers, params=params)
3535

3636
if response.status_code == 200:
3737
response_content = json.loads(response.content)
@@ -45,7 +45,7 @@ def get_persons(self, **kwargs):
4545
'make sure the user has correct permissions'.format(params))
4646

4747
response_data = self.combine_paginated_response_data(
48-
response_content, url=url, headers=headers
48+
response_content, url=url, headers=headers, params=params
4949
)
5050
response_data = [response_data] if isinstance(response_data, dict) else response_data
5151

churchtools_api/resources.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def get_bookings(self, **kwargs) -> list[dict]:
6262
"""
6363
url = self.domain + "/api/bookings"
6464
headers = {"accept": "application/json"}
65-
params = {}
65+
params = {"limit":50} #increases default pagination size
6666

6767
# at least one of the following arguments is required
6868
required_kwargs = ["booking_id", "resource_ids"]
@@ -103,7 +103,7 @@ def get_bookings(self, **kwargs) -> list[dict]:
103103
response_content = json.loads(response.content)
104104

105105
response_data = self.combine_paginated_response_data(
106-
response_content, url=url, headers=headers
106+
response_content, url=url, headers=headers, params=params
107107
)
108108
result_list = (
109109
[response_data] if isinstance(response_data, dict) else response_data

churchtools_api/songs.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,12 +28,13 @@ def get_songs(self, **kwargs) -> list[dict]:
2828
if "song_id" in kwargs.keys():
2929
url = url + "/{}".format(kwargs["song_id"])
3030
headers = {"accept": "application/json"}
31-
response = self.session.get(url=url, headers=headers)
31+
params = {"limit":50} #increases default pagination size
32+
response = self.session.get(url=url, headers=headers, params=params)
3233

3334
if response.status_code == 200:
3435
response_content = json.loads(response.content)
3536
response_data = self.combine_paginated_response_data(
36-
response_content, url=url, headers=headers
37+
response_content, url=url, headers=headers, params=params
3738
)
3839
return [response_data] if isinstance(response_data, dict) else response_data
3940

tests/test_churchtools_api.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,15 +100,15 @@ def test_get_persons(self):
100100
"""
101101
Tries to get all and a single person from the server
102102
Be aware that only ct_users that are visible to the user associated with the login token can be viewed!
103-
On any elkw.KRZ.TOOLS personId 1 'firstName' starts with 'Ben' and more than 10 ct_users exist(13. Jan 2023)
103+
On any elkw.KRZ.TOOLS personId 1 'firstName' starts with 'Ben' and more than 50 ct_users exist(13. Jan 2023)
104104
:return:
105105
"""
106106

107107
personId = 1
108108
result1 = self.api.get_persons()
109109
self.assertIsInstance(result1, list)
110110
self.assertIsInstance(result1[0], dict)
111-
self.assertGreater(len(result1), 10)
111+
self.assertGreater(len(result1), 50)
112112

113113
result2 = self.api.get_persons(ids=[personId])
114114
self.assertIsInstance(result2, list)
@@ -132,7 +132,7 @@ def test_get_songs(self) -> None:
132132
test_song_id = 2034
133133

134134
songs = self.api.get_songs()
135-
self.assertGreater(len(songs), 10)
135+
self.assertGreater(len(songs), 50)
136136

137137
song = self.api.get_songs(song_id=test_song_id)[0]
138138
self.assertEqual(song["id"], 2034)

0 commit comments

Comments
 (0)