Skip to content

Commit

Permalink
Implement /person/masterdata #110
Browse files Browse the repository at this point in the history
  • Loading branch information
bensteUEM committed Oct 4, 2024
1 parent ae5e2f5 commit 93d417a
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 1 deletion.
30 changes: 30 additions & 0 deletions churchtools_api/persons.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

logger = logging.getLogger(__name__)


class ChurchToolsApiPersons(ChurchToolsApiAbstract):
""" Part definition of ChurchToolsApi which focuses on persons
Expand Down Expand Up @@ -64,3 +65,32 @@ def get_persons(self, **kwargs):
"Persons requested failed: {}".format(
response.status_code))
return None

def get_persons_masterdata(
self, resultClass: str = None, returnAsDict: bool = False, **kwargs
) -> dict[list[dict]]:
"""
Function to get the Masterdata of the persons module
This information is required to map some IDs to specific items
Returns:
dict of lists of masterdata items each with list of dict items used as configuration
"""
url = self.domain + "/api/person/masterdata"

headers = {"accept": "application/json"}
response = self.session.get(url=url, headers=headers)

if response.status_code == 200:
response_content = json.loads(response.content)
response_data = response_content["data"].copy()
logger.debug("Person Masterdata load successful {}".format(response_data))

return response_data
else:
logger.warning(
"%s Something went wrong fetching person metadata: %s",
response.status_code,
response.content,
)
return None
34 changes: 33 additions & 1 deletion tests/test_churchtools_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import os
from pathlib import Path
import unittest
from datetime import datetime, timedelta

from churchtools_api.churchtools_api import ChurchToolsApi

Expand All @@ -19,6 +18,7 @@
log_directory.mkdir(parents=True)
logging.config.dictConfig(config=logging_config)


class TestsChurchToolsApi(unittest.TestCase):
def __init__(self, *args, **kwargs):
super(TestsChurchToolsApi, self).__init__(*args, **kwargs)
Expand Down Expand Up @@ -130,6 +130,38 @@ def test_get_persons(self):
result4 = self.api.get_persons(returnAsDict=False)
self.assertIsInstance(result4, list)

def test_get_persons_masterdata(self) -> None:
"""
Tries to retrieve metadata for persons module
Expected sections equal those that were available on ELKW1610.krz.tools on 4.Oct.2024
"""
EXPECTED_SECTIONS = {
"roles",
"ageGroups",
"targetGroups",
"groupTypes",
"groupCategories",
"groupStatuses",
"departments",
"statuses",
"campuses",
"contactLabels",
"growPaths",
"followUps",
"followUpIntervals",
"groupMeetingTemplates",
"relationshipTypes",
}

result = self.api.get_persons_masterdata()
self.assertIsInstance(result, dict)
self.assertEqual(EXPECTED_SECTIONS, set(result.keys()))

for section in result.values():
self.assertIsInstance(section, list)
for item in section:
self.assertIsInstance(item, dict)

def test_get_songs(self) -> None:
"""
1. Test requests all songs and checks that result has more than 10 elements (hence default pagination works)
Expand Down

0 comments on commit 93d417a

Please sign in to comment.