From 4400e0e132ea656cf84985c45f84d45c7eee5de3 Mon Sep 17 00:00:00 2001 From: Tim Date: Fri, 4 Feb 2022 15:40:12 +0000 Subject: [PATCH] Add some more tests --- openlp/core/ui/mainwindow.py | 2 +- tests/openlp_core/ui/test_mainwindow.py | 26 ++++++++++++++++++++++--- 2 files changed, 24 insertions(+), 4 deletions(-) diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 423ea4097..011bbfbcf 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -1450,4 +1450,4 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert self.log_info("File name found") self.service_manager_contents.load_file(file_path) else: - self.log_error(f"File {file_path} not found for arg {arg}") + self.log_error(f"File {file_path} not found for arg {args}") diff --git a/tests/openlp_core/ui/test_mainwindow.py b/tests/openlp_core/ui/test_mainwindow.py index ed8d5fff4..02804ae7d 100644 --- a/tests/openlp_core/ui/test_mainwindow.py +++ b/tests/openlp_core/ui/test_mainwindow.py @@ -135,12 +135,12 @@ def test_cmd_line_file_encoded(main_window): mocked_load_file.assert_called_with(Path(service_base)) -def test_cmd_line_arg_non_service(main_window): +def test_cmd_line_arg_no_service(main_window): """ - Test that passing a non service file does nothing. + Test that passing no service file, does nothing. """ # GIVEN a non service file as an argument to openlp - args = ['run_openlp.py'] + args = ['--disable-web-security'] # WHEN the argument is processed with patch.object(main_window.service_manager, 'load_file') as mocked_load_file: @@ -187,6 +187,26 @@ def test_cmd_line_filename_with_spaces(MockPath, main_window): mocked_load_file.assert_called_with(mocked_path_is_file) +@patch('openlp.core.ui.mainwindow.Path') +def test_cmd_line_filename_with_spaces_and_security(MockPath, main_window): + """ + Test that passing a service file with spaces loads. + """ + # GIVEN a set of arguments with a file separated by spaces + mocked_path_is_file = MagicMock(**{'is_file.return_value': True, 'suffix': '.osz'}) + MockPath.return_value.resolve.side_effect = [FileNotFoundError, FileNotFoundError, + FileNotFoundError, mocked_path_is_file] + args = ['--disable-web-security', 'Service', '2022-02-06.osz'] + + # WHEN the argument is processed + with patch.object(main_window.service_manager, 'load_file') as mocked_load_file: + main_window.open_cmd_line_files(args) + + # THEN the file should be looked for + assert MockPath.return_value.resolve.call_count == 4 + mocked_load_file.assert_called_with(mocked_path_is_file) + + def test_main_window_title(main_window): """ Test that running a new instance of OpenLP set the window title correctly