Merge branch 'issue-1601' into 'master'

Allow loading the same presentation file multiple times from 2.4.x service file. Fixes bug #1601.

See merge request openlp/openlp!638
This commit is contained in:
Tomas Groth 2023-07-28 12:58:47 +00:00
commit 49190fe6b3
2 changed files with 66 additions and 1 deletions

View File

@ -614,7 +614,9 @@ class ServiceItem(RegistryProperties):
self.sha256_file_hash = sha256_file_hash(file_path)
new_file = path / '{hash}{ext}'.format(hash=self.sha256_file_hash,
ext=os.path.splitext(self.title)[1])
move(file_path, new_file)
# while copying instead of moving can lead to longer load times for older files, if we move we
# cannot load service files with duplicated files.
copy(file_path, new_file)
else:
file_path = Path(service_item['serviceitem']['data'][0]['path']) / self.title
self.sha256_file_hash = sha256_file_hash(file_path)

View File

@ -24,6 +24,7 @@ Package to test the openlp.core.lib package.
import json
import os
import pytest
import tempfile
from pathlib import Path
from unittest.mock import Mock, MagicMock, patch
@ -415,6 +416,68 @@ def test_service_item_load_optical_media_from_service(state_media):
assert service_item.media_length == 17.694, 'Media length should be 17.694'
def test_service_item_load_duplicate_presentation_from_24x_service(state_media, settings):
"""
Test the Service Item - simulate loading the same presentation file from a 2.4.x service file twice
"""
presentation_service_time_246 = \
{'serviceitem':
{'data': [{'display_title': 'test1 ',
'image': 'C:\\OpenLPPortable-246\\Data\\presentations\\thumbnails\\prøve.odp\\slide1.png',
'notes': '\n',
'path': 'C:/Documents',
'title': 'prøve.odp'},
{'display_title': 'Thats all ',
'image': 'C:\\OpenLPPortable-246\\Data\\presentations\\thumbnails\\prøve.odp\\slide2.png',
'notes': '\n',
'path': 'C:/Documents',
'title': 'prøve.odp'}],
'header': {'audit': '',
'auto_play_slides_loop': False,
'auto_play_slides_once': False,
'background_audio': [],
'capabilities': [17, 10, 19, 20, 21],
'data': '',
'end_time': 0,
'footer': [],
'from_plugin': False,
'icon': ':/plugins/plugin_presentations.png',
'media_length': 0,
'name': 'presentations',
'notes': '',
'plugin': 'presentations',
'processor': 'Impress',
'search': '',
'start_time': 0,
'theme': None,
'theme_overwritten': False,
'timed_slide_interval': 0,
'title': 'prøve.odp',
'type': 3,
'will_auto_start': False,
'xml_version': None}}}
# GIVEN: 2 new service items and a mocked add icon and add_from_command function
service_item1 = ServiceItem(None)
service_item1.add_icon = MagicMock()
service_item2 = ServiceItem(None)
service_item2.add_icon = MagicMock()
# create a temp folder with a dummy presentation file
with tempfile.TemporaryDirectory(ignore_cleanup_errors=True) as tmp_folder:
open(tmp_folder + '/prøve.odp', 'a').close()
# WHEN: We add a custom from a saved service, twice
service_item1.set_from_service(presentation_service_time_246, Path(tmp_folder))
service_item2.set_from_service(presentation_service_time_246, Path(tmp_folder))
# THEN: Loading should have succeeded and service items should be valid
assert service_item1.is_valid is True, 'The new service item should be valid'
assert service_item2.is_valid is True, 'The new service item should be valid'
assert len(service_item1.slides) == 2, 'The service item should have 2 slides'
assert len(service_item2.slides) == 2, 'The service item should have 2 slides'
@patch('openlp.core.lib.serviceitem.sha256_file_hash')
def test_service_item_load_song_and_audio_from_service(mock_sha256_file_hash, state_media, settings, service_item_env):
"""