forked from openlp/openlp
Fix missing image service load crash
This commit is contained in:
parent
6ff9c2041b
commit
a327b70dc5
@ -507,10 +507,11 @@ class ServiceItem(RegistryProperties):
|
||||
text = text_image['title']
|
||||
file_hash = text_image['file_hash']
|
||||
file_path = path / '{base}{ext}'.format(base=file_hash, ext=os.path.splitext(text)[1])
|
||||
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 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')
|
||||
else:
|
||||
text = text_image
|
||||
org_file_path = path / text
|
||||
@ -532,7 +533,8 @@ class ServiceItem(RegistryProperties):
|
||||
if version >= 3:
|
||||
file_path = text_image['path']
|
||||
file_hash = text_image['file_hash']
|
||||
thumbnail = AppLocation.get_data_path() / text_image['image']
|
||||
if text_image['image']:
|
||||
thumbnail = AppLocation.get_data_path() / text_image['image']
|
||||
else:
|
||||
file_path = Path(text_image['path'])
|
||||
# Check if (by chance) the thumbnails for this image is available on this machine
|
||||
|
@ -137,14 +137,16 @@ def test_service_item_load_image_from_service(state_media, settings):
|
||||
tests a version 3 service file serviceitem (openlp-servicefile-version == 3)
|
||||
"""
|
||||
# GIVEN: A new service item (pre encoded from the json format) and a mocked add icon function
|
||||
image_name = 'BrightDots.png'
|
||||
fake_hash = 'abcd'
|
||||
extracted_file = Path(TEST_PATH) / '{base}{ext}'.format(base=fake_hash, ext=os.path.splitext(image_name)[1])
|
||||
frame_array = {'path': extracted_file, 'title': image_name, 'file_hash': fake_hash,
|
||||
image_name1 = 'BrightDots.png'
|
||||
fake_hash1 = 'abcd'
|
||||
image_name2 = 'DullDots.png'
|
||||
fake_hash2 = 'asdf'
|
||||
extracted_file = Path(TEST_PATH) / '{base}{ext}'.format(base=fake_hash1, ext=os.path.splitext(image_name1)[1])
|
||||
frame_array = {'path': extracted_file, 'title': image_name1, 'file_hash': fake_hash1,
|
||||
'thumbnail': Path("/path/images/thumbnails/abcd.png")}
|
||||
service_item = ServiceItem(None)
|
||||
service_item.add_icon = MagicMock()
|
||||
item = {'serviceitem': {'header': {'name': 'images', 'plugin': 'images', 'theme': -1, 'title': 'BrightDots.png',
|
||||
item = {'serviceitem': {'header': {'name': 'images', 'plugin': 'images', 'theme': -1, 'title': 'My Images',
|
||||
'footer': [], 'type': 2, 'audit': '', 'notes': '', 'from_plugin': False,
|
||||
'capabilities': [3, 1, 5, 6, 17, 21], 'search': '', 'data': '',
|
||||
'xml_version': None, 'auto_play_slides_once': False,
|
||||
@ -152,9 +154,12 @@ def test_service_item_load_image_from_service(state_media, settings):
|
||||
'end_time': 0, 'media_length': 0, 'background_audio': [],
|
||||
'theme_overwritten': False, 'will_auto_start': False, 'processor': None,
|
||||
'metadata': [], 'sha256_file_hash': None, 'stored_filename': None},
|
||||
'data': [{'title': 'BrightDots.png',
|
||||
'image': Path('images/thumbnails/{}.png'.format(fake_hash)),
|
||||
'file_hash': fake_hash}]}}
|
||||
'data': [{'title': image_name1,
|
||||
'image': Path('images/thumbnails/{}.png'.format(fake_hash1)),
|
||||
'file_hash': fake_hash1},
|
||||
{'title': image_name2,
|
||||
'image': None,
|
||||
'file_hash': fake_hash2}]}}
|
||||
|
||||
# WHEN: adding an image from a saved Service and mocked exists
|
||||
with patch('openlp.core.ui.servicemanager.os.path.exists') as mocked_exists,\
|
||||
@ -163,20 +168,22 @@ def test_service_item_load_image_from_service(state_media, settings):
|
||||
patch('openlp.core.lib.serviceitem.sha256_file_hash') as mocked_sha256_file_hash,\
|
||||
patch('openlp.core.lib.serviceitem.copy'),\
|
||||
patch('openlp.core.lib.serviceitem.move'):
|
||||
mocked_sha256_file_hash.return_value = fake_hash
|
||||
mocked_sha256_file_hash.side_effect = [fake_hash1, fake_hash2]
|
||||
mocked_exists.return_value = True
|
||||
mocked_get_section_data_path.return_value = Path('/path/')
|
||||
mocked_get_data_path.return_value = Path('/path/')
|
||||
service_item.set_from_service(item, TEST_PATH, 3)
|
||||
|
||||
# THEN: We should get back a valid service item
|
||||
# THEN: We should get back a valid service item,
|
||||
# and the second item with no preview image should not have crashed the program
|
||||
assert service_item.is_valid is True, 'The new service item should be valid'
|
||||
assert extracted_file == service_item.get_rendered_frame(0), 'The first frame should match the path to the image'
|
||||
assert frame_array == service_item.get_frames()[0], 'The return should match frame array1'
|
||||
assert extracted_file == service_item.get_frame_path(0), \
|
||||
'The frame path should match the full path to the image'
|
||||
assert image_name == service_item.get_frame_title(0), 'The frame title should match the image name'
|
||||
assert image_name == service_item.get_display_title(), 'The display title should match the first image name'
|
||||
assert image_name1 == service_item.get_frame_title(0), 'The frame title should match the image name'
|
||||
assert image_name2 == service_item.get_frame_title(1), 'The 2nd frame title should match the image name'
|
||||
assert 'My Images' == service_item.get_display_title(), 'The display title should match the provided title'
|
||||
assert service_item.is_image() is True, 'This service item should be of an "image" type'
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user