Merge branch 'fix-1871' into 'master'

Further fix #1871 by adding the Application name as early as possible

Closes #1871

See merge request openlp/openlp!733
This commit is contained in:
Raoul Snyman 2024-03-24 19:59:36 +00:00
commit 34ff2dab8b
2 changed files with 23 additions and 10 deletions

View File

@ -502,9 +502,11 @@ def main():
app = OpenLP() app = OpenLP()
Registry.create() Registry.create()
QtWidgets.QApplication.setOrganizationName('OpenLP') QtWidgets.QApplication.setOrganizationName('OpenLP')
QtWidgets.QApplication.setApplicationName('OpenLP')
QtWidgets.QApplication.setOrganizationDomain('openlp.org') QtWidgets.QApplication.setOrganizationDomain('openlp.org')
if args.portable: if args.portable:
# This has to be done here so that we can load the settings before instantiating the application object # This has to be done here so that we can load the settings before instantiating the application object
QtWidgets.QApplication.setApplicationName('OpenLPPortable')
portable_path, settings = setup_portable_settings(args.portablepath) portable_path, settings = setup_portable_settings(args.portablepath)
else: else:
settings = Settings() settings = Settings()
@ -529,7 +531,6 @@ def main():
font.setPointSizeF(font.pointSizeF() * application.devicePixelRatio()) font.setPointSizeF(font.pointSizeF() * application.devicePixelRatio())
application.setFont(font) application.setFont(font)
if args.portable: if args.portable:
application.setApplicationName('OpenLPPortable')
data_path = portable_path / 'Data' data_path = portable_path / 'Data'
set_up_logging(portable_path / 'Other') set_up_logging(portable_path / 'Other')
set_up_web_engine_cache(portable_path / 'Other' / 'web_cache') set_up_web_engine_cache(portable_path / 'Other' / 'web_cache')
@ -540,7 +541,6 @@ def main():
settings.setValue('advanced/is portable', True) settings.setValue('advanced/is portable', True)
settings.sync() settings.sync()
else: else:
application.setApplicationName('OpenLP')
set_up_logging(AppLocation.get_directory(AppLocation.CacheDir)) set_up_logging(AppLocation.get_directory(AppLocation.CacheDir))
set_up_web_engine_cache(AppLocation.get_directory(AppLocation.CacheDir) / 'web_cache') set_up_web_engine_cache(AppLocation.get_directory(AppLocation.CacheDir) / 'web_cache')
settings.init_default_shortcuts() settings.init_default_shortcuts()

View File

@ -19,15 +19,15 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>. # # along with this program. If not, see <https://www.gnu.org/licenses/>. #
########################################################################## ##########################################################################
import sys import sys
import pytest from argparse import Namespace
from pathlib import Path from pathlib import Path
from tempfile import mkdtemp from tempfile import mkdtemp
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, patch
import pytest
from PyQt5 import QtCore, QtWidgets from PyQt5 import QtCore, QtWidgets
# Mock QtWebEngineWidgets # Mock QtWebEngineWidgets
sys.modules['PyQt5.QtWebEngineWidgets'] = MagicMock() sys.modules['PyQt5.QtWebEngineWidgets'] = MagicMock()
@ -37,14 +37,20 @@ from openlp.core.common.settings import Settings
@pytest.fixture @pytest.fixture
def app_main_env(): def mocked_qapp():
patcher = patch('openlp.core.app.QtWidgets.QApplication')
yield patcher.start()
patcher.stop()
@pytest.fixture
def app_main_env(mocked_qapp):
with patch('openlp.core.app.Settings') as mock_settings, \ with patch('openlp.core.app.Settings') as mock_settings, \
patch('openlp.core.app.Registry') as mock_registry, \ patch('openlp.core.app.Registry') as mock_registry, \
patch('openlp.core.app.AppLocation') as mock_apploc, \ patch('openlp.core.app.AppLocation') as mock_apploc, \
patch('openlp.core.app.LanguageManager'), \ patch('openlp.core.app.LanguageManager'), \
patch('openlp.core.app.qInitResources'), \ patch('openlp.core.app.qInitResources'), \
patch('openlp.core.app.parse_options'), \ patch('openlp.core.app.parse_options') as mocked_parse_options, \
patch('openlp.core.app.QtWidgets.QApplication') as mock_qapp, \
patch('openlp.core.app.QtWidgets.QMessageBox.warning') as mock_warn, \ patch('openlp.core.app.QtWidgets.QMessageBox.warning') as mock_warn, \
patch('openlp.core.app.QtWidgets.QMessageBox.information'), \ patch('openlp.core.app.QtWidgets.QMessageBox.information'), \
patch('openlp.core.app.OpenLP') as mock_openlp, \ patch('openlp.core.app.OpenLP') as mock_openlp, \
@ -58,7 +64,10 @@ def app_main_env():
openlp_server.is_another_instance_running.return_value = False openlp_server.is_another_instance_running.return_value = False
mock_apploc.get_data_path.return_value = Path() mock_apploc.get_data_path.return_value = Path()
mock_apploc.get_directory.return_value = Path() mock_apploc.get_directory.return_value = Path()
mock_qapp.return_value.devicePixelRatio.return_value = 1.0 mocked_parse_options.return_value = Namespace(no_error_form=False, loglevel='warning', portable=False,
portablepath=None, no_web_server=False, display_custom_path=None,
rargs=[])
mocked_qapp.return_value.devicePixelRatio.return_value = 1.0
mock_warn.return_value = True mock_warn.return_value = True
openlp_instance = MagicMock() openlp_instance = MagicMock()
mock_openlp.return_value = openlp_instance mock_openlp.return_value = openlp_instance
@ -311,7 +320,8 @@ def test_backup_on_upgrade(mocked_question, mocked_get_version, qapp, settings):
@patch('openlp.core.app.backup_if_version_changed') @patch('openlp.core.app.backup_if_version_changed')
@patch('openlp.core.app.set_up_web_engine_cache') @patch('openlp.core.app.set_up_web_engine_cache')
@patch('openlp.core.app.set_up_logging') @patch('openlp.core.app.set_up_logging')
def test_main(mock_logging, mock_web_cache, mock_backup, mock_sys, mock_openlp, app_main_env): def test_main(mock_logging: MagicMock, mock_web_cache: MagicMock, mock_backup: MagicMock, mock_sys: MagicMock,
mock_openlp: MagicMock, mocked_qapp: MagicMock, app_main_env: None):
""" """
Test the main method performs primary actions Test the main method performs primary actions
""" """
@ -329,6 +339,9 @@ def test_main(mock_logging, mock_web_cache, mock_backup, mock_sys, mock_openlp,
mock_logging.assert_called_once() mock_logging.assert_called_once()
mock_web_cache.assert_called_once() mock_web_cache.assert_called_once()
mock_sys.exit.assert_called_once() mock_sys.exit.assert_called_once()
mocked_qapp.setOrganizationName.assert_called_once_with('OpenLP')
mocked_qapp.setApplicationName.assert_called_once_with('OpenLP')
mocked_qapp.setOrganizationDomain.assert_called_once_with('openlp.org')
@patch('openlp.core.app.QtWidgets.QMessageBox.warning') @patch('openlp.core.app.QtWidgets.QMessageBox.warning')