mirror of
https://gitlab.com/openlp/openlp.git
synced 2024-09-27 18:37:35 +00:00
Starting web services later to fix #1210
This commit is contained in:
parent
7dd2c98467
commit
0500f3b799
@ -78,9 +78,6 @@ class HttpServer(RegistryBase, RegistryProperties, LogMixin):
|
|||||||
"""
|
"""
|
||||||
super(HttpServer, self).__init__(parent)
|
super(HttpServer, self).__init__(parent)
|
||||||
Registry().register('authentication_token', token_hex())
|
Registry().register('authentication_token', token_hex())
|
||||||
if not Registry().get_flag('no_web_server'):
|
|
||||||
worker = HttpWorker()
|
|
||||||
run_thread(worker, 'http_server')
|
|
||||||
|
|
||||||
def bootstrap_post_set_up(self):
|
def bootstrap_post_set_up(self):
|
||||||
"""
|
"""
|
||||||
@ -89,3 +86,6 @@ class HttpServer(RegistryBase, RegistryProperties, LogMixin):
|
|||||||
create_paths(AppLocation.get_section_data_path('remotes'))
|
create_paths(AppLocation.get_section_data_path('remotes'))
|
||||||
self.poller = Poller()
|
self.poller = Poller()
|
||||||
Registry().register('poller', self.poller)
|
Registry().register('poller', self.poller)
|
||||||
|
if not Registry().get_flag('no_web_server'):
|
||||||
|
worker = HttpWorker()
|
||||||
|
run_thread(worker, 'http_server')
|
||||||
|
@ -33,7 +33,7 @@ import time
|
|||||||
from websockets import serve
|
from websockets import serve
|
||||||
|
|
||||||
from openlp.core.common.mixins import LogMixin, RegistryProperties
|
from openlp.core.common.mixins import LogMixin, RegistryProperties
|
||||||
from openlp.core.common.registry import Registry
|
from openlp.core.common.registry import Registry, RegistryBase
|
||||||
from openlp.core.threading import ThreadWorker, run_thread
|
from openlp.core.threading import ThreadWorker, run_thread
|
||||||
from openlp.core.api.websocketspoll import WebSocketPoller
|
from openlp.core.api.websocketspoll import WebSocketPoller
|
||||||
|
|
||||||
@ -165,7 +165,7 @@ class WebSocketWorker(ThreadWorker, RegistryProperties, LogMixin):
|
|||||||
self.event_loop.call_soon_threadsafe(queue.put_nowait, state)
|
self.event_loop.call_soon_threadsafe(queue.put_nowait, state)
|
||||||
|
|
||||||
|
|
||||||
class WebSocketServer(RegistryProperties, QtCore.QObject, LogMixin):
|
class WebSocketServer(RegistryBase, RegistryProperties, QtCore.QObject, LogMixin):
|
||||||
"""
|
"""
|
||||||
Wrapper round a server instance
|
Wrapper round a server instance
|
||||||
"""
|
"""
|
||||||
@ -176,6 +176,9 @@ class WebSocketServer(RegistryProperties, QtCore.QObject, LogMixin):
|
|||||||
super(WebSocketServer, self).__init__()
|
super(WebSocketServer, self).__init__()
|
||||||
self.worker = None
|
self.worker = None
|
||||||
|
|
||||||
|
def bootstrap_post_set_up(self):
|
||||||
|
self.start()
|
||||||
|
|
||||||
def start(self):
|
def start(self):
|
||||||
"""
|
"""
|
||||||
Starts the WebSockets server
|
Starts the WebSockets server
|
||||||
|
@ -480,9 +480,6 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
|
|||||||
self.copy_data = False
|
self.copy_data = False
|
||||||
self.settings.set_up_default_values()
|
self.settings.set_up_default_values()
|
||||||
self.about_form = AboutForm(self)
|
self.about_form = AboutForm(self)
|
||||||
self.ws_server = WebSocketServer()
|
|
||||||
self.ws_server.start()
|
|
||||||
self.http_server = HttpServer(self)
|
|
||||||
SettingsForm(self)
|
SettingsForm(self)
|
||||||
self.formatting_tag_form = FormattingTagForm(self)
|
self.formatting_tag_form = FormattingTagForm(self)
|
||||||
self.shortcut_form = ShortcutListForm(self)
|
self.shortcut_form = ShortcutListForm(self)
|
||||||
@ -526,6 +523,9 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, LogMixin, RegistryPropert
|
|||||||
Registry().register_function('bootstrap_post_set_up', self.bootstrap_post_set_up)
|
Registry().register_function('bootstrap_post_set_up', self.bootstrap_post_set_up)
|
||||||
# Reset the cursor
|
# Reset the cursor
|
||||||
self.application.set_normal_cursor()
|
self.application.set_normal_cursor()
|
||||||
|
# Starting up web services
|
||||||
|
self.http_server = HttpServer(self)
|
||||||
|
self.ws_server = WebSocketServer()
|
||||||
|
|
||||||
def _wait_for_threads(self):
|
def _wait_for_threads(self):
|
||||||
"""
|
"""
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
"""
|
"""
|
||||||
Functional tests to test the Http Server Class.
|
Functional tests to test the Http Server Class.
|
||||||
"""
|
"""
|
||||||
|
from pathlib import Path
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from openlp.core.api.http.server import HttpServer
|
from openlp.core.api.http.server import HttpServer
|
||||||
@ -29,14 +30,17 @@ from openlp.core.common.registry import Registry
|
|||||||
|
|
||||||
@patch('openlp.core.api.http.server.HttpWorker')
|
@patch('openlp.core.api.http.server.HttpWorker')
|
||||||
@patch('openlp.core.api.http.server.run_thread')
|
@patch('openlp.core.api.http.server.run_thread')
|
||||||
def test_server_start(mocked_run_thread, MockHttpWorker, registry):
|
@patch('openlp.core.api.deploy.AppLocation.get_section_data_path')
|
||||||
|
def test_server_start(mocked_get_section_data_path, mocked_run_thread, MockHttpWorker, registry):
|
||||||
"""
|
"""
|
||||||
Test the starting of the Waitress Server with the disable flag set off
|
Test the starting of the Waitress Server with the disable flag set off
|
||||||
"""
|
"""
|
||||||
# GIVEN: A new httpserver
|
# GIVEN: A new httpserver and mocked get_section_data_path
|
||||||
|
mocked_get_section_data_path.return_value = Path('.')
|
||||||
# WHEN: I start the server
|
# WHEN: I start the server
|
||||||
Registry().set_flag('no_web_server', False)
|
Registry().set_flag('no_web_server', False)
|
||||||
HttpServer()
|
server = HttpServer()
|
||||||
|
server.bootstrap_post_set_up()
|
||||||
|
|
||||||
# THEN: the api environment should have been created
|
# THEN: the api environment should have been created
|
||||||
assert mocked_run_thread.call_count == 1, 'The qthread should have been called once'
|
assert mocked_run_thread.call_count == 1, 'The qthread should have been called once'
|
||||||
@ -45,14 +49,18 @@ def test_server_start(mocked_run_thread, MockHttpWorker, registry):
|
|||||||
|
|
||||||
@patch('openlp.core.api.http.server.HttpWorker')
|
@patch('openlp.core.api.http.server.HttpWorker')
|
||||||
@patch('openlp.core.api.http.server.run_thread')
|
@patch('openlp.core.api.http.server.run_thread')
|
||||||
def test_server_start_not_required(mocked_run_thread, MockHttpWorker, registry):
|
@patch('openlp.core.api.deploy.AppLocation.get_section_data_path')
|
||||||
|
def test_server_start_not_required(mocked_get_section_data_path, mocked_run_thread, MockHttpWorker, registry):
|
||||||
"""
|
"""
|
||||||
Test the starting of the Waitress Server with the disable flag set off
|
Test the starting of the Waitress Server with the disable flag set off
|
||||||
"""
|
"""
|
||||||
# GIVEN: A new httpserver
|
# GIVEN: A new httpserver and mocked get_section_data_path
|
||||||
|
mocked_get_section_data_path.return_value = Path('.')
|
||||||
|
|
||||||
# WHEN: I start the server
|
# WHEN: I start the server
|
||||||
Registry().set_flag('no_web_server', True)
|
Registry().set_flag('no_web_server', True)
|
||||||
HttpServer()
|
server = HttpServer()
|
||||||
|
server.bootstrap_post_set_up()
|
||||||
|
|
||||||
# THEN: the api environment should have been created
|
# THEN: the api environment should have been created
|
||||||
assert mocked_run_thread.call_count == 0, 'The qthread should not have have been called'
|
assert mocked_run_thread.call_count == 0, 'The qthread should not have have been called'
|
||||||
|
@ -349,10 +349,10 @@ def test_mainwindow_configuration(main_window):
|
|||||||
# WHEN: you check the started functions
|
# WHEN: you check the started functions
|
||||||
|
|
||||||
# THEN: the following registry functions should have been registered
|
# THEN: the following registry functions should have been registered
|
||||||
expected_service_list = ['settings', 'settings_thread', 'application', 'main_window', 'http_server',
|
expected_service_list = ['settings', 'settings_thread', 'application', 'main_window', 'settings_form',
|
||||||
'authentication_token', 'settings_form', 'service_manager', 'theme_manager',
|
'service_manager', 'theme_manager', 'projector_manager', 'http_server',
|
||||||
'projector_manager']
|
'authentication_token', 'web_socket_server']
|
||||||
expected_functions_list = ['bootstrap_initialise', 'bootstrap_post_set_up', 'bootstrap_completion',
|
expected_functions_list = ['bootstrap_post_set_up', 'bootstrap_initialise', 'bootstrap_completion',
|
||||||
'config_screen_changed', 'theme_change_global']
|
'config_screen_changed', 'theme_change_global']
|
||||||
assert list(Registry().service_list.keys()) == expected_service_list, \
|
assert list(Registry().service_list.keys()) == expected_service_list, \
|
||||||
'The service list should have been {}'.format(Registry().service_list.keys())
|
'The service list should have been {}'.format(Registry().service_list.keys())
|
||||||
|
Loading…
Reference in New Issue
Block a user