Merge branch 'tidy_ups' into 'master'

Add some more tests

See merge request openlp/openlp!402
This commit is contained in:
Raoul Snyman 2022-02-04 16:38:00 +00:00
commit bc872e0e87
2 changed files with 24 additions and 4 deletions

View File

@ -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}")

View File

@ -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