Skip to content

Commit 05fe0b3

Browse files
committed
fix(persons): NULL value for sexId
(#273)
1 parent cc6f9b0 commit 05fe0b3

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

churchtools_api/persons.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ def get_persons_masterdata(
9292
"""Function to get the Masterdata of the persons module.
9393
9494
This information is required to map some IDs to specific items.
95+
Special case treatment for resultClass sexes
96+
first item is copied for "None" references as fallback
9597
9698
Arguments:
9799
resultClass: the name of the masterdata to retrieve. Defaults to All
@@ -111,8 +113,11 @@ def get_persons_masterdata(
111113

112114
if resultClass:
113115
response_data = response_data[resultClass]
116+
if resultClass == "sexes":
117+
response_data.insert(0, {**response_data[0], "id": None})
114118
if returnAsDict:
115119
response_data = {item["id"]: item["name"] for item in response_data}
120+
response_data[None] = response_data[0]
116121

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

tests/test_churchtools_api_persons.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -111,10 +111,25 @@ def test_get_persons_sex_id(self) -> None:
111111
EXPECTED_RESULT = "sex.unknown"
112112
SAMPLE_USER_ID = 513
113113

114-
person = self.api.get_persons(ids=[SAMPLE_USER_ID])
114+
person = self.api.get_persons(ids=[SAMPLE_USER_ID])[0]
115115
gender_map = self.api.get_persons_masterdata(
116116
resultClass="sexes", returnAsDict=True
117117
)
118-
result = gender_map[person[0]["sexId"]]
118+
result = gender_map[person["sexId"]]
119+
120+
assert result == EXPECTED_RESULT
121+
122+
def test_get_persons_sex_id_none(self) -> None:
123+
"""Tests that persons sexId can be converted if NULL.
124+
125+
IMPORTANT - This test method and the parameters used depend on target system!
126+
the hard coded sample exists on ELKW1610.KRZ.TOOLS
127+
"""
128+
EXPECTED_RESULT = "sex.unknown"
129+
130+
gender_map = self.api.get_persons_masterdata(
131+
resultClass="sexes", returnAsDict=True
132+
)
133+
result = gender_map[None]
119134

120135
assert result == EXPECTED_RESULT

0 commit comments

Comments
 (0)