Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions churchtools_api/persons.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ def get_persons_masterdata(
"""Function to get the Masterdata of the persons module.

This information is required to map some IDs to specific items.
Special case treatment for resultClass sexes
first item is copied for "None" references as fallback

Arguments:
resultClass: the name of the masterdata to retrieve. Defaults to All
Expand All @@ -111,8 +113,11 @@ def get_persons_masterdata(

if resultClass:
response_data = response_data[resultClass]
if resultClass == "sexes":
response_data.insert(0, {**response_data[0], "id": None})
if returnAsDict:
response_data = {item["id"]: item["name"] for item in response_data}
response_data[None] = response_data[0]

logger.debug("Person Masterdata load successful len=%s", len(response_data))

Expand Down
19 changes: 17 additions & 2 deletions tests/test_churchtools_api_persons.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,25 @@ def test_get_persons_sex_id(self) -> None:
EXPECTED_RESULT = "sex.unknown"
SAMPLE_USER_ID = 513

person = self.api.get_persons(ids=[SAMPLE_USER_ID])
person = self.api.get_persons(ids=[SAMPLE_USER_ID])[0]
gender_map = self.api.get_persons_masterdata(
resultClass="sexes", returnAsDict=True
)
result = gender_map[person[0]["sexId"]]
result = gender_map[person["sexId"]]

assert result == EXPECTED_RESULT

def test_get_persons_sex_id_none(self) -> None:
"""Tests that persons sexId can be converted if NULL.

IMPORTANT - This test method and the parameters used depend on target system!
the hard coded sample exists on ELKW1610.KRZ.TOOLS
"""
EXPECTED_RESULT = "sex.unknown"

gender_map = self.api.get_persons_masterdata(
resultClass="sexes", returnAsDict=True
)
result = gender_map[None]

assert result == EXPECTED_RESULT
Loading