From f1fe916781251dbc384f31454501a522698d5ef3 Mon Sep 17 00:00:00 2001 From: Raoul Snyman Date: Fri, 10 Feb 2023 11:00:21 -0700 Subject: [PATCH] Skip missing thumbnails when loading a service --- openlp/core/lib/serviceitem.py | 5 +++-- tests/openlp_core/lib/test_serviceitem.py | 17 +++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/openlp/core/lib/serviceitem.py b/openlp/core/lib/serviceitem.py index 15ce36312..1e2d91b5f 100644 --- a/openlp/core/lib/serviceitem.py +++ b/openlp/core/lib/serviceitem.py @@ -522,8 +522,9 @@ class ServiceItem(RegistryProperties): if text_image['image']: thumbnail = AppLocation.get_data_path() / text_image['image'] # copy thumbnail from servicemanager path - copy(path / 'thumbnails' / os.path.basename(text_image['image']), - AppLocation.get_section_data_path(self.name) / 'thumbnails') + if thumbnail.exists(): + copy(path / 'thumbnails' / os.path.basename(text_image['image']), + AppLocation.get_section_data_path(self.name) / 'thumbnails') else: text = text_image org_file_path = path / text diff --git a/tests/openlp_core/lib/test_serviceitem.py b/tests/openlp_core/lib/test_serviceitem.py index 630bfa551..075eeae5b 100644 --- a/tests/openlp_core/lib/test_serviceitem.py +++ b/tests/openlp_core/lib/test_serviceitem.py @@ -35,6 +35,7 @@ from openlp.core.common.registry import Registry from openlp.core.lib.formattingtags import FormattingTags from openlp.core.lib.serviceitem import ItemCapabilities, ServiceItem from openlp.core.lib.theme import TransitionSpeed +from openlp.core.ui.icons import UiIcons from tests.utils import convert_file_service_item from tests.utils.constants import RESOURCE_PATH @@ -965,3 +966,19 @@ def test_to_dict_presentation_item(mocked_image_uri, mocked_get_data_path, state 'data': {} } assert result == expected_dict + + +@pytest.mark.parametrize('plugin_name,icon', [('songs', 'music'), ('bibles', 'bible'), + ('presentations', 'presentation'), ('images', 'picture'), + ('media', 'video')]) +def test_add_icon(registry, plugin_name, icon): + """Test that adding an icon works according to the plugin name""" + # GIVEN: A service item + service_item = ServiceItem() + service_item.name = plugin_name + + # WHEN: add_icon() is called + service_item.add_icon() + + # THEN: The icon should be correct + assert service_item.icon.name() == getattr(UiIcons(), icon).name()