Skip to content

Commit

Permalink
Resolves #18 - fix pagination for absence and attencence lists
Browse files Browse the repository at this point in the history
  • Loading branch information
syphar committed Mar 29, 2021
1 parent 8e92839 commit caccf0b
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 9 deletions.
4 changes: 2 additions & 2 deletions src/personio_py/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ def request_paginated(
if params is None:
params = {}
params['limit'] = limit
params['offset'] = 0
params['offset'] = 1
# continue making requests until no more data is returned
data_acc = []
while True:
Expand All @@ -172,7 +172,7 @@ def request_paginated(
if response['metadata']['current_page'] == response['metadata']['total_pages']:
break
else:
params['offset'] += len(resp_data)
params['offset'] += 1
else:
break
# return the accumulated data
Expand Down
4 changes: 2 additions & 2 deletions tests/test_mock_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ def test_auth_rotation_fail():
def test_get_attendance():
# mock the get absences endpoint (with different array offsets)
responses.add(
responses.GET, re.compile('https://api.personio.de/v1/company/attendances?.*offset=0.*'),
responses.GET, re.compile('https://api.personio.de/v1/company/attendances?.*offset=1.*'),
status=200, json=json_dict_attendance_rms, adding_headers={'Authorization': 'Bearer foo'})
responses.add(
responses.GET, re.compile('https://api.personio.de/v1/company/attendances?.*offset=3.*'),
responses.GET, re.compile('https://api.personio.de/v1/company/attendances?.*offset=2.*'),
status=200, json=json_dict_empty_response, adding_headers={'Authorization': 'Bearer bar'})
# configure personio & get absences for alan
personio = mock_personio()
Expand Down
10 changes: 5 additions & 5 deletions tests/test_mock_api_absences.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,27 +159,27 @@ def mock_absence_types():
def mock_absences():
# mock the get absences endpoint (with different array offsets)
responses.add(
responses.GET, re.compile('https://api.personio.de/v1/company/time-offs?.*offset=0.*'),
responses.GET, re.compile('https://api.personio.de/v1/company/time-offs?.*offset=1.*'),
status=200, json=json_dict_absence_alan, adding_headers={'Authorization': 'Bearer foo'})
responses.add(
responses.GET, re.compile('https://api.personio.de/v1/company/time-offs?.*offset=3.*'),
responses.GET, re.compile('https://api.personio.de/v1/company/time-offs?.*offset=2.*'),
status=200, json=json_dict_empty_response, adding_headers={'Authorization': 'Bearer bar'})


def mock_single_absences():
# mock the get absences endpoint (with different array offsets)
responses.add(
responses.GET, re.compile('https://api.personio.de/v1/company/time-offs?.*offset=0.*'),
responses.GET, re.compile('https://api.personio.de/v1/company/time-offs?.*offset=1.*'),
status=200, json=json_dict_absence_alan_first, adding_headers={'Authorization': 'Bearer foo'})
responses.add(
responses.GET, re.compile('https://api.personio.de/v1/company/time-offs?.*offset=1.*'),
responses.GET, re.compile('https://api.personio.de/v1/company/time-offs?.*offset=2.*'),
status=200, json=json_dict_empty_response, adding_headers={'Authorization': 'Bearer bar'})


def mock_no_absences():
# mock the get absences endpoint
responses.add(
responses.GET, re.compile('https://api.personio.de/v1/company/time-offs?.*offset=0.*'),
responses.GET, re.compile('https://api.personio.de/v1/company/time-offs?.*offset=1.*'),
status=200, json=json_dict_empty_response, adding_headers={'Authorization': 'Bearer bar'})


Expand Down

0 comments on commit caccf0b

Please sign in to comment.