forked from at-gmbh/personio-py
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move attendances mock tests / test data to new files to keep tests re…
…adable once more tests are added
- Loading branch information
Philip Flohr
committed
Nov 30, 2020
1 parent
18bc524
commit 9de540f
Showing
4 changed files
with
88 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import responses | ||
import re | ||
|
||
from datetime import timedelta, date | ||
|
||
from tests.mock_data import json_dict_empty_response | ||
from tests.test_mock_api import compare_labeled_attributes, mock_personio | ||
from tests.test_mock_api_attendances_data import * | ||
|
||
|
||
@responses.activate | ||
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.*'), | ||
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.*'), | ||
status=200, json=json_dict_empty_response, adding_headers={'Authorization': 'Bearer bar'}) | ||
# configure personio & get absences for alan | ||
personio = mock_personio() | ||
attendances = personio.get_attendances(2116366) | ||
# validate | ||
assert len(attendances) == 3 | ||
selection = [a for a in attendances if "release" in a.comment.lower()] | ||
assert len(selection) == 1 | ||
release = selection[0] | ||
assert "free software" in release.comment | ||
assert release.date == date(1985, 3, 20) | ||
assert release.start_time == timedelta(seconds=11*60*60) | ||
assert release.end_time == timedelta(seconds=12.5*60*60) | ||
assert release.break_duration == 60 | ||
assert release.employee_id == 2116366 | ||
# validate serialization | ||
source_dict = json_dict_attendance_rms['data'][0] | ||
target_dict = release.to_dict() | ||
compare_labeled_attributes(source_dict, target_dict) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import json | ||
|
||
json_string_attendance_rms = """ | ||
{ | ||
"success": true, | ||
"data": [{ | ||
"id": 33479712, | ||
"type": "AttendancePeriod", | ||
"attributes": { | ||
"employee": 2116366, | ||
"date": "1985-03-20", | ||
"start_time": "11:00", | ||
"end_time": "12:30", | ||
"break": 60, | ||
"comment": "release day! GNU Emacs Version 13 is available as free software now *yay*", | ||
"is_holiday": false, | ||
"is_on_time_off": false | ||
} | ||
}, { | ||
"id": 33479612, | ||
"type": "AttendancePeriod", | ||
"attributes": { | ||
"employee": 2116366, | ||
"date": "1985-03-19", | ||
"start_time": "10:30", | ||
"end_time": "22:00", | ||
"break": 120, | ||
"comment": "just a couple more parentheses...", | ||
"is_holiday": false, | ||
"is_on_time_off": false | ||
} | ||
}, { | ||
"id": 33479602, | ||
"type": "AttendancePeriod", | ||
"attributes": { | ||
"employee": 2116366, | ||
"date": "1985-03-18", | ||
"start_time": "10:00", | ||
"end_time": "20:00", | ||
"break": 90, | ||
"comment": "working on GNU Emacs", | ||
"is_holiday": false, | ||
"is_on_time_off": false | ||
} | ||
} | ||
] | ||
} | ||
""" | ||
json_dict_attendance_rms = json.loads(json_string_attendance_rms) |