Skip to content

Commit 8507e9b

Browse files
committed
fix(songs): workaround for support case with song arrangements - (#144)
fix(songs): corrected dtypes (#144)
1 parent ecd58c3 commit 8507e9b

3 files changed

Lines changed: 55 additions & 18 deletions

File tree

churchtools_api/songs.py

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -304,7 +304,7 @@ def delete_song(self, song_id: int) -> bool:
304304

305305
return True
306306

307-
def contains_song_tag(self, song_id: int, song_tag_name: int) -> bool:
307+
def contains_song_tag(self, song_id: int, song_tag_name: str) -> bool:
308308
"""Helper which checks if a specific song_tag_id is present on a song.
309309
310310
Arguments:
@@ -317,13 +317,12 @@ def contains_song_tag(self, song_id: int, song_tag_name: int) -> bool:
317317
tags = self.get_tag(domain_type="song", domain_id=song_id, rtype="name_dict")
318318
return song_tag_name in tags
319319

320-
def get_songs_by_tag(self, song_tag_name: int) -> list[dict]:
320+
def get_songs_by_tag(self, song_tag_name: str) -> list[dict]:
321321
"""Helper which returns all songs that contain have a specific tag.
322322
323323
Arguments:
324-
song_tag_name: ChurchTools site specific song_tag_id which should be used
325-
OR
326-
song_tag_id
324+
song_tag_name: name of a song tag that is used
325+
in respective ChurchTools instace
327326
328327
Returns:
329328
list of songs
@@ -367,7 +366,7 @@ def get_song_arrangement(
367366
return next(
368367
arrangement
369368
for arrangement in song["arrangements"]
370-
if song["arrangements"][0]["isDefault"]
369+
if arrangement["isDefault"]
371370
)
372371

373372
def create_song_arrangement(self, song_id: int, arrangement_name: str) -> int:
@@ -426,6 +425,14 @@ def edit_song_arrangement(
426425
duration: (int) lenght in full seconds.
427426
note: (str) more detailed explanation text.
428427
428+
Not useable Keywords due to bug
429+
#TODO@bensteUEM: only some parameters can be applied
430+
# CT support case 147728
431+
# https://github.com/bensteUEM/ChurchToolsAPI/issues/144
432+
source_name: (int|str) id of the source as defined in masterdata.
433+
Alternatively also accepts shortname.
434+
source_reference: (str) source reference number.
435+
429436
Returns:
430437
if changes were applied successful
431438
"""
@@ -434,16 +441,35 @@ def edit_song_arrangement(
434441
existing_arrangement = self.get_song_arrangement(
435442
song_id=song_id, arrangement_id=arrangement_id
436443
)
437-
438-
if isinstance(kwargs.get("source_id"), int):
439-
source_id = kwargs.get("source_id")
440-
elif isinstance(kwargs.get("source_id"), str):
441-
source_id = self.lookup_song_source_as_id(shortname=kwargs.get("source_id"))
444+
# TODO@bensteUEM: only some parameters can be applied
445+
# CT support case 147728
446+
# https://github.com/bensteUEM/ChurchToolsAPI/issues/144
447+
"""
448+
if isinstance(kwargs.get("source_name"), int):
449+
source_name = kwargs.get("source_name")
450+
elif isinstance(kwargs.get("source_name"), str):
451+
source_name = self.lookup_song_source_as_id(
452+
shortname=kwargs.get("source_name")
453+
)
442454
else:
443-
source_id = self.lookup_song_source_as_id(
455+
source_name = self.lookup_song_source_as_id(
444456
shortname=existing_arrangement["sourceName"]
445457
)
446-
458+
"""
459+
if kwargs.get("source_name") or kwargs.get("source_reference"):
460+
logger.warning(
461+
"CT support cas 147728 source_name and reference are "
462+
"not updateabel via REST API"
463+
)
464+
# TODO@bensteUEM: only some parameters can be applied
465+
# CT support case 147728
466+
# https://github.com/bensteUEM/ChurchToolsAPI/issues/144
467+
"""
468+
"sourceName": source_name,
469+
"sourceReference": kwargs.get(
470+
"source_reference", existing_arrangement["sourceReference"]
471+
),
472+
"""
447473
data = {
448474
"name": kwargs.get("name", existing_arrangement["name"]),
449475
"key": kwargs.get("key", existing_arrangement["key"]),

churchtools_api/tags.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,8 @@ def remove_tag(self, domain_type: str, domain_id: str, tag_name: str) -> bool:
115115
return True
116116

117117
def get_tag(
118-
self, domain_type: str, domain_id: str, rtype: str = "original"
119-
) -> list[dict]:
118+
self, domain_type: str, domain_id: int, rtype: str = "original"
119+
) -> list[dict] | None:
120120
"""Retrieves the readable tags of one single object.
121121
122122
Args:

tests/test_churchtools_api_songs.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,12 +326,19 @@ def test_create_edit_delete_song_arrangement(self) -> None:
326326
)
327327
assert created_arrangement["name"] == SAMPLE_ARRANGEMENT_NAME
328328

329-
SAMPLE_SOURCE = {"12": "T"}
329+
# SAMPLE_SOURCE = {"12": "T"} #noqa: ERA001
330330

331331
# edit source as text and changed params
332332
SAMPLE_ARRANGEMENT_NAME2 = "TEST_BEZEICHNUNG"
333333
SAMPLE_PARAMS = {
334334
"name": SAMPLE_ARRANGEMENT_NAME2,
335+
# TODO@bensteUEM: only some parameters can be applied
336+
# CT support case 147728
337+
# https://github.com/bensteUEM/ChurchToolsAPI/issues/144
338+
# "sourceName": next(
339+
# iter(SAMPLE_SOURCE.values()) # noqa: ERA001
340+
# ), # using shortname on purpse
341+
# "sourceReference": "source_ref", # noqa: ERA001
335342
"key": "F",
336343
"tempo": 50,
337344
"beat": "beat",
@@ -350,8 +357,13 @@ def test_create_edit_delete_song_arrangement(self) -> None:
350357
created_arrangement[expected_key] == expected_value
351358
for expected_key, expected_value in SAMPLE_PARAMS.items()
352359
)
360+
# TODO@bensteUEM: only some parameters can be applied
361+
# CT support case 147728
362+
# https://github.com/bensteUEM/ChurchToolsAPI/issues/144
363+
# assert created_arrangement["sourceName"] == next(iter(SAMPLE_SOURCE.values())) # noqa: ERA001 E501
353364

354365
# edit2 - source as key id
366+
"""
355367
SAMPLE_PARAMS_SHORT = {
356368
"source_id": int(next(iter(SAMPLE_SOURCE.keys()))),
357369
}
@@ -363,8 +375,7 @@ def test_create_edit_delete_song_arrangement(self) -> None:
363375
song_id=SAMPLE_SONG_ID, arrangement_id=arrangement_id
364376
)
365377
assert created_arrangement["sourceName"] == next(iter(SAMPLE_SOURCE.values()))
366-
assert created_arrangement["duration"] == SAMPLE_PARAMS["duration"]
367-
378+
"""
368379
# delete
369380
was_deleted = self.api.delete_song_arrangement(
370381
song_id=SAMPLE_SONG_ID, arrangement_id=arrangement_id

0 commit comments

Comments
 (0)