Merge branch 'issue-1700' into 'master'

Fix #1700 by typecasting the calls to Paths

Closes #1700

See merge request openlp/openlp!682
This commit is contained in:
Raoul Snyman 2023-11-23 03:05:37 +00:00
commit 8ddab1dc16
2 changed files with 27 additions and 2 deletions

View File

@ -466,8 +466,9 @@ class ServiceItem(RegistryProperties):
else:
for slide in self.slides:
# When saving a service that originated from openlp 2.4 thumbnail might not be available
# Also, sometimes this is not a Path object, but a string.
if 'thumbnail' in slide:
image_path = slide['thumbnail'].relative_to(AppLocation().get_data_path())
image_path = Path(slide['thumbnail']).relative_to(AppLocation().get_data_path())
else:
# Check if (by chance) the thumbnails for this image is available on this machine
test_thumb = AppLocation.get_section_data_path(self.name) / 'thumbnails' / stored_filename
@ -483,7 +484,8 @@ class ServiceItem(RegistryProperties):
elif lite_save:
image = slide['image']
else:
image = slide['image'].relative_to(AppLocation().get_data_path())
# Sometimss this is not a Path object, so typecast it
image = Path(slide['image']).relative_to(AppLocation().get_data_path())
service_data.append({'title': slide['title'], 'image': image, 'path': slide['path'],
'display_title': slide['display_title'], 'notes': slide['notes']})
return {'header': service_header, 'data': service_data}

View File

@ -1150,3 +1150,26 @@ def test_add_icon(registry, plugin_name, icon):
# THEN: The icon should be correct
assert service_item.icon.name() == getattr(UiIcons(), icon).name()
def test_get_service_repr_song(registry: Registry):
"""Test the get_service_repr() method with a song"""
# GIVEN: A service item
registry.register('renderer', MagicMock())
service_item = ServiceItem()
service_item.name = 'songs'
service_item.theme = 'Default'
service_item.title = 'Test Song'
service_item.add_from_text('This is the first slide')
service_item.add_from_text('This is the second slide')
service_item._create_slides()
service_item.add_icon()
# WHEN: get_service_repr() is called
rep = service_item.get_service_repr(False)
# THEN: The correct repr should have been made
assert rep['header'].get('name') == 'songs'
assert rep['header'].get('plugin') == 'songs'
assert rep['header'].get('theme') == 'Default'
assert rep['header'].get('title') == 'Test Song'