This commit is contained in:
Tim Bentley 2016-06-14 21:56:50 +01:00
parent ed28ad2ebc
commit f8ca67b67e
8 changed files with 18 additions and 18 deletions

View File

@ -47,7 +47,7 @@ def register_endpoint(end_point):
from .endpoint import Endpoint
from .apitab import ApiTab
from .websockets import WsServer, Poll
from .websockets import WebSocketServer, Poll
from .http import HttpServer
from .apicontroller import ApiController

View File

@ -21,7 +21,7 @@
###############################################################################
import logging
from openlp.core.api import WsServer, Poll, HttpServer
from openlp.core.api import WebSocketServer, Poll, HttpServer
from openlp.core.common import OpenLPMixin, Registry, RegistryMixin, RegistryProperties
# These are here to load the endpoints
@ -50,5 +50,5 @@ class ApiController(RegistryMixin, OpenLPMixin, RegistryProperties):
"""
self.poll = Poll()
Registry().register('api_poll', self.poll)
self.wsserver = WsServer()
self.httpserver = HttpServer()
self.websocket_server = WebSocketServer()
self.http_server = HttpServer()

View File

@ -114,6 +114,7 @@ def main_image(request):
# return json.dumps({'results': result}).encode()
pass
@stage_endpoint.route(r'^/(\w+)/thumbnails([^/]+)?/(.*)$')
def main_image(request):
"""

View File

@ -63,5 +63,3 @@ class ServerError(HttpError):
Make this a 500
"""
super(ServerError, self).__init__(500, 'Server Error')

View File

@ -168,4 +168,4 @@ class WSGIApplication(object):
return self.wsgi_app(environ, start_response)
application = WSGIApplication('api')
application = WSGIApplication('api')

View File

@ -38,7 +38,7 @@ from openlp.core.common import Settings, RegistryProperties, OpenLPMixin, Regist
log = logging.getLogger(__name__)
class WSThread(QtCore.QObject):
class WebSocketWorker(QtCore.QObject):
"""
A special Qt thread class to allow the WebSockets server to run at the same time as the UI.
"""
@ -61,7 +61,7 @@ class WSThread(QtCore.QObject):
self.ws_server.stop = True
class WsServer(RegistryProperties, OpenLPMixin):
class WebSocketServer(RegistryProperties, OpenLPMixin):
"""
Wrapper round a server instance
"""
@ -69,10 +69,10 @@ class WsServer(RegistryProperties, OpenLPMixin):
"""
Initialise the http server, and start the WebSockets server
"""
super(WsServer, self).__init__()
super(WebSocketServer, self).__init__()
self.settings_section = 'remotes'
self.thread = QtCore.QThread()
self.worker = WSThread(self)
self.worker = WebSocketWorker(self)
self.worker.moveToThread(self.thread)
self.thread.started.connect(self.worker.start)
self.thread.start()
@ -150,6 +150,8 @@ class WsServer(RegistryProperties, OpenLPMixin):
self.http_thread.stop()
self.httpd = None
log.debug('Stopped the server.')
class Poll(RegistryProperties):
"""
Access by the web layer to get status type information from the application

View File

@ -56,4 +56,4 @@ class TestApiError(TestCase):
# THEN: we get an error and a status
self.assertEquals('Server Error', context.exception.message, 'A Not Found exception should be thrown')
self.assertEquals(500, context.exception.status, 'A 500 status should be thrown')
self.assertEquals(500, context.exception.status, 'A 500 status should be thrown')

View File

@ -26,7 +26,7 @@ import json
from unittest import TestCase
from openlp.core.common import Registry, Settings
from openlp.core.api import Poll, WsServer
from openlp.core.api import Poll, WebSocketServer
from tests.functional import MagicMock, patch
from tests.helpers.testmixin import TestMixin
@ -60,20 +60,19 @@ class TestWSServer(TestCase, TestMixin):
"""
self.destroy_settings()
@patch('openlp.core.api.websockets.WSThread')
@patch('openlp.core.api.websockets.WebSocketWorker')
@patch('openlp.core.api.websockets.QtCore.QThread')
def test_serverstart(self, mock_qthread, mock_thread):
def test_serverstart(self, mock_qthread, mock_worker):
"""
Test the starting of the WebSockets Server
"""
# GIVEN: A new httpserver
# WHEN: I start the server
server = WsServer()
server = 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_thread.call_count, 'The http thread should have been called once')
self.assertEquals(1, mock_worker.call_count, 'The http thread should have been called once')
def test_main_poll(self):
"""