Merge branch 'issue-1297' into 'master'

Fix issue #1297 by reducing the number by 1024 times

Closes #1297

See merge request openlp/openlp!621
This commit is contained in:
Raoul Snyman 2023-06-06 14:40:08 +00:00
commit 96dbfa47e5
3 changed files with 47 additions and 4 deletions

View File

@ -319,6 +319,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
Sets up the service manager, toolbars, list view, et al.
"""
super().__init__(parent)
self._save_lite = False
self.service_items = []
self.suffixes = set()
self.add_media_suffixes()
@ -805,7 +806,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
compressed_size = 0
for zip_info in zip_file.infolist():
compressed_size += zip_info.compress_size
self.main_window.display_progress_bar(compressed_size)
self.main_window.display_progress_bar(compressed_size // 1024)
# First find the osj-file to find out how to handle the file
for zip_info in zip_file.infolist():
# The json file has been called 'service_data.osj' since OpenLP 3.0
@ -843,7 +844,7 @@ class ServiceManager(QtWidgets.QWidget, RegistryBase, Ui_ServiceManager, LogMixi
is_broken_file = True
self.log_debug(f'Fixing file {fname} => {zip_info.filename}')
zip_file.extract(zip_info, str(self.service_path))
self.main_window.increment_progress_bar(zip_info.compress_size)
self.main_window.increment_progress_bar(zip_info.compress_size // 1024)
# Handle the content
self.new_file()
self.process_service_items(items)

View File

@ -63,7 +63,7 @@ def mocked_qapp():
@pytest.fixture
def registry(autouse=True):
def registry():
"""An instance of the Registry"""
yield Registry.create()
Registry._instances = {}

View File

@ -26,7 +26,7 @@ import threading
from functools import partial
from pathlib import Path
from time import sleep
from unittest.mock import MagicMock, patch
from unittest.mock import Mock, MagicMock, call, patch
from zipfile import BadZipFile
import pytest
@ -2483,3 +2483,45 @@ def test_get_write_file_list(mocked_sha256_file_hash, registry, service_manager:
# THEN the service_items list should be empty
assert len(write_list) == 6
@patch('openlp.core.ui.servicemanager.ServiceItem')
@patch('openlp.core.ui.servicemanager.find_and_set_in_combo_box')
def test_process_service_items(mocked_fns_combo: Mock, MockServiceItem: Mock, service_manager: ServiceManager,
registry: Registry):
"""Test the process_service_items() method"""
# GIVEN: A mocked ServiceItem and a ServiceManager
mocked_service = MagicMock()
mocked_service.service_load.side_effect = lambda x: x
registry.register('test', mocked_service)
mocked_service_item = MagicMock()
# This line below is because Mock has an internal "name" attr that is set via the constructor
# See https://docs.python.org/3/library/unittest.mock.html#mock-names-and-the-name-attribute
mocked_service_item.name = 'test'
MockServiceItem.return_value = mocked_service_item
service_items = [
{
},
{
'openlp_core': {
'lite-service': True,
'service-theme': 'Blue'
}
},
{
}
]
service_manager.theme_combo_box = MagicMock(**{'currentText.return_value': 'Blue'})
service_manager.add_service_item = MagicMock()
# WHEN: process_service_items() is called
service_manager.process_service_items(service_items)
# THEN: The correct calls should have been made
mocked_fns_combo.assert_called_once_with(service_manager.theme_combo_box, 'Blue', set_missing=False)
assert service_manager.service_theme == 'Blue'
assert service_manager._save_lite is True
assert mocked_service_item.set_from_service.call_args_list == [
call({}, service_manager.service_path, service_manager.servicefile_version),
call({}, version=service_manager.servicefile_version)
]