Skip to content

Commit

Permalink
feat(#124): sourceName implemented with REST masterdata
Browse files Browse the repository at this point in the history
  • Loading branch information
bensteUEM committed Jan 7, 2025
1 parent 97b5f48 commit 82bd714
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 28 deletions.
4 changes: 3 additions & 1 deletion churchtools_api/events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
15 changes: 1 addition & 14 deletions churchtools_api/songs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
35 changes: 24 additions & 11 deletions tests/test_churchtools_api_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 0 additions & 2 deletions tests/test_churchtools_api_songs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 82bd714

Please sign in to comment.