diff --git a/churchtools_api/events.py b/churchtools_api/events.py index ff7200f..4d442c7 100644 --- a/churchtools_api/events.py +++ b/churchtools_api/events.py @@ -666,7 +666,9 @@ def get_event_masterdata( Keywords: resultClass: str with name of the masterdata type (not datatype) common - types are 'absenceReasons', 'songCategories', 'services', 'serviceGroups' + types are 'absenceReasons', 'songCategories', 'songSources' + 'services', 'serviceGroups', 'facts' + returnAsDict: if the list with one type should be returned as dict by ID Returns: diff --git a/churchtools_api/songs.py b/churchtools_api/songs.py index 2a39bbf..7c4b212 100644 --- a/churchtools_api/songs.py +++ b/churchtools_api/songs.py @@ -148,23 +148,10 @@ def lookup_song_category_as_id(self, category_name: str) -> int: def get_song_source_map(self) -> dict: """Requesting CT metadata for mapping of song sources. - WARNING - uses undocumented AJAX API. - Returns: a dictionary of {Index:{valuedict}}. """ - # TODO @bensteUEM: implement using REST API once support case 135796 is resolved - # https://github.com/bensteUEM/ChurchToolsAPI/issues/124 - logging.warning( - "Using undocumented AJAX API" - " because function does not exist as REST endpoint" - ) - url = self.domain + "/index.php?q=churchservice/ajax" - headers = {"accept": "application/json"} - data = {"func": "getMasterData"} - response = self.session.post(url=url, headers=headers, data=data) - response_content = json.loads(response.content) - return response_content["data"]["songsource"] + return self.get_event_masterdata(resultClass="songSources", returnAsDict=True) def lookup_song_source_as_id( self, longname: str | None = None, shortname: str | None = None diff --git a/tests/test_churchtools_api_events.py b/tests/test_churchtools_api_events.py index 8f04df0..6b8712d 100644 --- a/tests/test_churchtools_api_events.py +++ b/tests/test_churchtools_api_events.py @@ -225,24 +225,37 @@ def test_get_set_event_admins(self) -> None: assert self.api.set_event_admins_ajax(SAMPLE_EVENT_ID, EXPECTED_ADMIN_IDS) - def test_get_event_masterdata(self) -> None: - """IMPORTANT - This test method and the parameters used depend on target system! - - Tries to get a list of event masterdata and a type of masterdata from CT - The values depend on your system data! - - Test case is valid against ELKW1610.KRZ.TOOLS - """ - result = self.api.get_event_masterdata() - EXPECTED_KEYS = [ + @pytest.mark.parametrize( + ("expected_key"), + [ "absenceReasons", "facts", "songCategories", "songSources", "services", "serviceGroups", - ] - assert set(result) == set(EXPECTED_KEYS) + ], + ) + def test_get_event_masterdata_all(self, expected_key: str) -> None: + """Tries to get a list of event masterdata and a type of masterdata from CT. + + Categories should exist on all systems with CT version 116 or newer + Args: + expected_key: the expected key + """ + result_all = self.api.get_event_masterdata() + result_specific = self.api.get_event_masterdata(resultClass=expected_key) + assert expected_key in result_all + assert len(result_specific) >= 1 + + def test_get_event_masterdata_specific(self) -> None: + """IMPORTANT - This test method and the parameters used depend on target system! + + Tries to get a list of event masterdata and a type of masterdata from CT + The values depend on your system data! - + Test case is valid against ELKW1610.KRZ.TOOLS + """ result = self.api.get_event_masterdata(resultClass="serviceGroups") assert len(result) > 1 assert result[0]["name"] == "Programm" diff --git a/tests/test_churchtools_api_songs.py b/tests/test_churchtools_api_songs.py index c287638..4cd5adb 100644 --- a/tests/test_churchtools_api_songs.py +++ b/tests/test_churchtools_api_songs.py @@ -329,8 +329,6 @@ def test_lookup_song_source_as_id(self, caplog: pytest.LogCaptureFixture) -> Non result = self.api.lookup_song_source_as_id() assert result is None EXPECTED_MESSAGES = [ - "Using undocumented AJAX API" - " because function does not exist as REST endpoint", "missing argument longname or shortname required", ] assert caplog.messages == EXPECTED_MESSAGES