forked from openlp/openlp
Fix the tests I broke
This commit is contained in:
parent
35fd553024
commit
4fae7f829d
@ -49,7 +49,7 @@ class TestHttpServer(TestCase):
|
||||
"""
|
||||
# GIVEN: A new httpserver
|
||||
# WHEN: I start the server
|
||||
Registry().set_flag('no_web_server', True)
|
||||
Registry().set_flag('no_web_server', False)
|
||||
HttpServer()
|
||||
|
||||
# THEN: the api environment should have been created
|
||||
@ -64,7 +64,7 @@ class TestHttpServer(TestCase):
|
||||
"""
|
||||
# GIVEN: A new httpserver
|
||||
# WHEN: I start the server
|
||||
Registry().set_flag('no_web_server', False)
|
||||
Registry().set_flag('no_web_server', True)
|
||||
HttpServer()
|
||||
|
||||
# THEN: the api environment should have been created
|
||||
|
@ -70,7 +70,7 @@ class TestWSServer(TestCase, TestMixin):
|
||||
"""
|
||||
# GIVEN: A new httpserver
|
||||
# WHEN: I start the server
|
||||
Registry().set_flag('no_web_server', True)
|
||||
Registry().set_flag('no_web_server', False)
|
||||
WebSocketServer()
|
||||
|
||||
# THEN: the api environment should have been created
|
||||
@ -85,7 +85,7 @@ class TestWSServer(TestCase, TestMixin):
|
||||
"""
|
||||
# GIVEN: A new httpserver and the server is not required
|
||||
# WHEN: I start the server
|
||||
Registry().set_flag('no_web_server', False)
|
||||
Registry().set_flag('no_web_server', True)
|
||||
WebSocketServer()
|
||||
|
||||
# THEN: the api environment should have been created
|
||||
|
@ -36,14 +36,15 @@ def test_parse_options_basic():
|
||||
"""
|
||||
# GIVEN: a a set of system arguments.
|
||||
sys.argv[1:] = []
|
||||
|
||||
# WHEN: We we parse them to expand to options
|
||||
args = parse_options(None)
|
||||
args = parse_options()
|
||||
|
||||
# THEN: the following fields will have been extracted.
|
||||
assert args.dev_version is False, 'The dev_version flag should be False'
|
||||
assert args.loglevel == 'warning', 'The log level should be set to warning'
|
||||
assert args.no_error_form is False, 'The no_error_form should be set to False'
|
||||
assert args.portable is False, 'The portable flag should be set to false'
|
||||
assert args.style is None, 'There are no style flags to be processed'
|
||||
assert args.rargs == [], 'The service file should be blank'
|
||||
|
||||
|
||||
@ -53,14 +54,15 @@ def test_parse_options_debug():
|
||||
"""
|
||||
# GIVEN: a a set of system arguments.
|
||||
sys.argv[1:] = ['-l debug']
|
||||
|
||||
# WHEN: We we parse them to expand to options
|
||||
args = parse_options(None)
|
||||
args = parse_options()
|
||||
|
||||
# THEN: the following fields will have been extracted.
|
||||
assert args.dev_version is False, 'The dev_version flag should be False'
|
||||
assert args.loglevel == ' debug', 'The log level should be set to debug'
|
||||
assert args.no_error_form is False, 'The no_error_form should be set to False'
|
||||
assert args.portable is False, 'The portable flag should be set to false'
|
||||
assert args.style is None, 'There are no style flags to be processed'
|
||||
assert args.rargs == [], 'The service file should be blank'
|
||||
|
||||
|
||||
@ -70,14 +72,15 @@ def test_parse_options_debug_and_portable():
|
||||
"""
|
||||
# GIVEN: a a set of system arguments.
|
||||
sys.argv[1:] = ['--portable']
|
||||
|
||||
# WHEN: We we parse them to expand to options
|
||||
args = parse_options(None)
|
||||
args = parse_options()
|
||||
|
||||
# THEN: the following fields will have been extracted.
|
||||
assert args.dev_version is False, 'The dev_version flag should be False'
|
||||
assert args.loglevel == 'warning', 'The log level should be set to warning'
|
||||
assert args.no_error_form is False, 'The no_error_form should be set to False'
|
||||
assert args.portable is True, 'The portable flag should be set to true'
|
||||
assert args.style is None, 'There are no style flags to be processed'
|
||||
assert args.rargs == [], 'The service file should be blank'
|
||||
|
||||
|
||||
@ -87,14 +90,15 @@ def test_parse_options_all_no_file():
|
||||
"""
|
||||
# GIVEN: a a set of system arguments.
|
||||
sys.argv[1:] = ['-l debug', '-d']
|
||||
|
||||
# WHEN: We we parse them to expand to options
|
||||
args = parse_options(None)
|
||||
args = parse_options()
|
||||
|
||||
# THEN: the following fields will have been extracted.
|
||||
assert args.dev_version is True, 'The dev_version flag should be True'
|
||||
assert args.loglevel == ' debug', 'The log level should be set to debug'
|
||||
assert args.no_error_form is False, 'The no_error_form should be set to False'
|
||||
assert args.portable is False, 'The portable flag should be set to false'
|
||||
assert args.style is None, 'There are no style flags to be processed'
|
||||
assert args.rargs == [], 'The service file should be blank'
|
||||
|
||||
|
||||
@ -104,14 +108,15 @@ def test_parse_options_file():
|
||||
"""
|
||||
# GIVEN: a a set of system arguments.
|
||||
sys.argv[1:] = ['dummy_temp']
|
||||
|
||||
# WHEN: We we parse them to expand to options
|
||||
args = parse_options(None)
|
||||
args = parse_options()
|
||||
|
||||
# THEN: the following fields will have been extracted.
|
||||
assert args.dev_version is False, 'The dev_version flag should be False'
|
||||
assert args.loglevel == 'warning', 'The log level should be set to warning'
|
||||
assert args.no_error_form is False, 'The no_error_form should be set to False'
|
||||
assert args.portable is False, 'The portable flag should be set to false'
|
||||
assert args.style is None, 'There are no style flags to be processed'
|
||||
assert args.rargs == 'dummy_temp', 'The service file should not be blank'
|
||||
|
||||
|
||||
@ -121,14 +126,15 @@ def test_parse_options_file_and_debug():
|
||||
"""
|
||||
# GIVEN: a a set of system arguments.
|
||||
sys.argv[1:] = ['-l debug', 'dummy_temp']
|
||||
|
||||
# WHEN: We we parse them to expand to options
|
||||
args = parse_options(None)
|
||||
args = parse_options()
|
||||
|
||||
# THEN: the following fields will have been extracted.
|
||||
assert args.dev_version is False, 'The dev_version flag should be False'
|
||||
assert args.loglevel == ' debug', 'The log level should be set to debug'
|
||||
assert args.no_error_form is False, 'The no_error_form should be set to False'
|
||||
assert args.portable is False, 'The portable flag should be set to false'
|
||||
assert args.style is None, 'There are no style flags to be processed'
|
||||
assert args.rargs == 'dummy_temp', 'The service file should not be blank'
|
||||
|
||||
|
||||
|
@ -60,9 +60,10 @@ class TestMainWindow(TestCase, TestMixin):
|
||||
# Mock cursor busy/normal methods.
|
||||
self.app.set_busy_cursor = MagicMock()
|
||||
self.app.set_normal_cursor = MagicMock()
|
||||
self.app.process_events = MagicMock()
|
||||
self.app.args = []
|
||||
Registry().register('application', self.app)
|
||||
Registry().set_flag('no_web_server', False)
|
||||
Registry().set_flag('no_web_server', True)
|
||||
self.add_toolbar_action_patcher = patch('openlp.core.ui.mainwindow.create_action')
|
||||
self.mocked_add_toolbar_action = self.add_toolbar_action_patcher.start()
|
||||
self.mocked_add_toolbar_action.side_effect = self._create_mock_action
|
||||
@ -74,8 +75,8 @@ class TestMainWindow(TestCase, TestMixin):
|
||||
"""
|
||||
Delete all the C++ objects and stop all the patchers
|
||||
"""
|
||||
self.add_toolbar_action_patcher.stop()
|
||||
del self.main_window
|
||||
self.add_toolbar_action_patcher.stop()
|
||||
|
||||
def test_cmd_line_file(self):
|
||||
"""
|
||||
@ -92,17 +93,17 @@ class TestMainWindow(TestCase, TestMixin):
|
||||
# THEN the service from the arguments is loaded
|
||||
mocked_load_file.assert_called_with(service)
|
||||
|
||||
def test_cmd_line_arg(self):
|
||||
@patch('openlp.core.ui.servicemanager.ServiceManager.load_file')
|
||||
def test_cmd_line_arg(self, mocked_load_file):
|
||||
"""
|
||||
Test that passing a non service file does nothing.
|
||||
"""
|
||||
# GIVEN a non service file as an argument to openlp
|
||||
service = os.path.join('openlp.py')
|
||||
self.main_window.arguments = [service]
|
||||
with patch('openlp.core.ui.servicemanager.ServiceManager.load_file') as mocked_load_file:
|
||||
|
||||
# WHEN the argument is processed
|
||||
self.main_window.open_cmd_line_files("")
|
||||
self.main_window.open_cmd_line_files(service)
|
||||
|
||||
# THEN the file should not be opened
|
||||
assert mocked_load_file.called is False, 'load_file should not have been called'
|
||||
|
@ -44,21 +44,21 @@ class TestMainWindow(TestCase, TestMixin):
|
||||
self.app.set_normal_cursor = MagicMock()
|
||||
self.app.args = []
|
||||
Registry().register('application', self.app)
|
||||
Registry().set_flag('no_web_server', False)
|
||||
Registry().set_flag('no_web_server', True)
|
||||
# Mock classes and methods used by mainwindow.
|
||||
with patch('openlp.core.ui.mainwindow.SettingsForm') as mocked_settings_form, \
|
||||
patch('openlp.core.ui.mainwindow.ImageManager') as mocked_image_manager, \
|
||||
patch('openlp.core.ui.mainwindow.LiveController') as mocked_live_controller, \
|
||||
patch('openlp.core.ui.mainwindow.PreviewController') as mocked_preview_controller, \
|
||||
patch('openlp.core.ui.mainwindow.OpenLPDockWidget') as mocked_dock_widget, \
|
||||
patch('openlp.core.ui.mainwindow.QtWidgets.QToolBox') as mocked_q_tool_box_class, \
|
||||
patch('openlp.core.ui.mainwindow.QtWidgets.QMainWindow.addDockWidget') as mocked_add_dock_method, \
|
||||
patch('openlp.core.ui.mainwindow.ServiceManager') as mocked_service_manager, \
|
||||
patch('openlp.core.ui.mainwindow.ThemeManager') as mocked_theme_manager, \
|
||||
patch('openlp.core.ui.mainwindow.ProjectorManager') as mocked_projector_manager, \
|
||||
patch('openlp.core.ui.mainwindow.Renderer') as mocked_renderer, \
|
||||
patch('openlp.core.ui.mainwindow.websockets.WebSocketServer') as mocked_websocketserver, \
|
||||
patch('openlp.core.ui.mainwindow.server.HttpServer') as mocked_httpserver:
|
||||
with patch('openlp.core.ui.mainwindow.SettingsForm'), \
|
||||
patch('openlp.core.ui.mainwindow.ImageManager'), \
|
||||
patch('openlp.core.ui.mainwindow.LiveController'), \
|
||||
patch('openlp.core.ui.mainwindow.PreviewController'), \
|
||||
patch('openlp.core.ui.mainwindow.OpenLPDockWidget'), \
|
||||
patch('openlp.core.ui.mainwindow.QtWidgets.QToolBox'), \
|
||||
patch('openlp.core.ui.mainwindow.QtWidgets.QMainWindow.addDockWidget'), \
|
||||
patch('openlp.core.ui.mainwindow.ServiceManager'), \
|
||||
patch('openlp.core.ui.mainwindow.ThemeManager'), \
|
||||
patch('openlp.core.ui.mainwindow.ProjectorManager'), \
|
||||
patch('openlp.core.ui.mainwindow.Renderer'), \
|
||||
patch('openlp.core.ui.mainwindow.websockets.WebSocketServer'), \
|
||||
patch('openlp.core.ui.mainwindow.server.HttpServer'):
|
||||
self.main_window = MainWindow()
|
||||
|
||||
def tearDown(self):
|
||||
|
Loading…
Reference in New Issue
Block a user