diff --git a/openlp/core/api/http/server.py b/openlp/core/api/http/server.py index 782940f2d..b17888ddb 100644 --- a/openlp/core/api/http/server.py +++ b/openlp/core/api/http/server.py @@ -82,13 +82,14 @@ class HttpServer(RegistryBase, RegistryProperties, LogMixin): Initialise the http server, and start the http server """ super(HttpServer, self).__init__(parent) - self.worker = HttpWorker() - self.thread = QtCore.QThread() - self.worker.moveToThread(self.thread) - self.thread.started.connect(self.worker.run) - self.thread.start() - Registry().register_function('download_website', self.first_time) - Registry().register_function('get_website_version', self.website_version) + if Registry().get_flag('no_web_server'): + self.worker = HttpWorker() + self.thread = QtCore.QThread() + self.worker.moveToThread(self.thread) + self.thread.started.connect(self.worker.run) + self.thread.start() + Registry().register_function('download_website', self.first_time) + Registry().register_function('get_website_version', self.website_version) Registry().set_flag('website_version', '0.0') def bootstrap_post_set_up(self): diff --git a/openlp/core/api/websockets.py b/openlp/core/api/websockets.py index 90dca8208..3417eb74d 100644 --- a/openlp/core/api/websockets.py +++ b/openlp/core/api/websockets.py @@ -70,12 +70,13 @@ class WebSocketServer(RegistryProperties, LogMixin): Initialise and start the WebSockets server """ super(WebSocketServer, self).__init__() - self.settings_section = 'api' - self.worker = WebSocketWorker(self) - self.thread = QtCore.QThread() - self.worker.moveToThread(self.thread) - self.thread.started.connect(self.worker.run) - self.thread.start() + if Registry().get_flag('no_web_server'): + self.settings_section = 'api' + self.worker = WebSocketWorker(self) + self.thread = QtCore.QThread() + self.worker.moveToThread(self.thread) + self.thread.started.connect(self.worker.run) + self.thread.start() def start_server(self): """ diff --git a/openlp/core/ui/mainwindow.py b/openlp/core/ui/mainwindow.py index 312e9d445..ee07cbd69 100644 --- a/openlp/core/ui/mainwindow.py +++ b/openlp/core/ui/mainwindow.py @@ -504,9 +504,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, RegistryProperties): Settings().set_up_default_values() self.about_form = AboutForm(self) MediaController() - if Registry().get_flag('no_web_server'): - websockets.WebSocketServer() - server.HttpServer() + websockets.WebSocketServer() + server.HttpServer() SettingsForm(self) self.formatting_tag_form = FormattingTagForm(self) self.shortcut_form = ShortcutListForm(self) diff --git a/tests/functional/openlp_core/api/http/test_http.py b/tests/functional/openlp_core/api/http/test_http.py index d9002b2ec..ed584c1b9 100644 --- a/tests/functional/openlp_core/api/http/test_http.py +++ b/tests/functional/openlp_core/api/http/test_http.py @@ -45,12 +45,28 @@ class TestHttpServer(TestCase): @patch('openlp.core.api.http.server.QtCore.QThread') def test_server_start(self, mock_qthread, mock_thread): """ - Test the starting of the Waitress Server + Test the starting of the Waitress Server with the disable flag set off """ # GIVEN: A new httpserver # WHEN: I start the server + Registry().set_flag('no_web_server', True) HttpServer() # THEN: the api environment should have been created self.assertEquals(1, mock_qthread.call_count, 'The qthread should have been called once') self.assertEquals(1, mock_thread.call_count, 'The http thread should have been called once') + + @patch('openlp.core.api.http.server.HttpWorker') + @patch('openlp.core.api.http.server.QtCore.QThread') + def test_server_start_not_required(self, mock_qthread, mock_thread): + """ + Test the starting of the Waitress Server with the disable flag set off + """ + # GIVEN: A new httpserver + # WHEN: I start the server + Registry().set_flag('no_web_server', False) + HttpServer() + + # THEN: the api environment should have been created + self.assertEquals(0, mock_qthread.call_count, 'The qthread should not have have been called') + self.assertEquals(0, mock_thread.call_count, 'The http thread should not have been called') diff --git a/tests/functional/openlp_core/api/test_websockets.py b/tests/functional/openlp_core/api/test_websockets.py index 99abcdbc0..f400c50a5 100644 --- a/tests/functional/openlp_core/api/test_websockets.py +++ b/tests/functional/openlp_core/api/test_websockets.py @@ -66,16 +66,32 @@ class TestWSServer(TestCase, TestMixin): @patch('openlp.core.api.websockets.QtCore.QThread') def test_serverstart(self, mock_qthread, mock_worker): """ - Test the starting of the WebSockets Server + Test the starting of the WebSockets Server with the disabled flag set on """ # GIVEN: A new httpserver # WHEN: I start the server + Registry().set_flag('no_web_server', True) WebSocketServer() # THEN: the api environment should have been created self.assertEquals(1, mock_qthread.call_count, 'The qthread should have been called once') self.assertEquals(1, mock_worker.call_count, 'The http thread should have been called once') + @patch('openlp.core.api.websockets.WebSocketWorker') + @patch('openlp.core.api.websockets.QtCore.QThread') + def test_serverstart_not_required(self, mock_qthread, mock_worker): + """ + Test the starting of the WebSockets Server with the disabled flag set off + """ + # GIVEN: A new httpserver and the server is not required + # WHEN: I start the server + Registry().set_flag('no_web_server', False) + WebSocketServer() + + # THEN: the api environment should have been created + self.assertEquals(0, mock_qthread.call_count, 'The qthread should not have been called') + self.assertEquals(0, mock_worker.call_count, 'The http thread should not have been called') + def test_main_poll(self): """ Test the main_poll function returns the correct JSON diff --git a/tests/functional/openlp_core/ui/test_mainwindow.py b/tests/functional/openlp_core/ui/test_mainwindow.py index 5e1a69cbc..4a0404eab 100644 --- a/tests/functional/openlp_core/ui/test_mainwindow.py +++ b/tests/functional/openlp_core/ui/test_mainwindow.py @@ -155,7 +155,7 @@ class TestMainWindow(TestCase, TestMixin): # WHEN: you check the started functions # THEN: the following registry functions should have been registered - assert len(self.registry.service_list) == 12, \ + assert len(self.registry.service_list) == 13, \ 'The registry should have 12 services, got {}'.format(self.registry.service_list.keys()) assert len(self.registry.functions_list) == 19, \ 'The registry should have 19 functions, got {}'.format(self.registry.functions_list.keys())