forked from openlp/openlp
Add another test
This commit is contained in:
parent
88baa041f2
commit
f951dbff9f
@ -64,7 +64,7 @@ class OpenLPHttpServer(RegistryProperties, OpenLPMixin):
|
|||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Initialise the http server, and start the server of the correct type http / https
|
Initialise the http server, and start the http server
|
||||||
"""
|
"""
|
||||||
super(OpenLPHttpServer, self).__init__()
|
super(OpenLPHttpServer, self).__init__()
|
||||||
self.thread = QtCore.QThread()
|
self.thread = QtCore.QThread()
|
||||||
|
@ -39,7 +39,7 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class WSThread(QtCore.QObject):
|
class WSThread(QtCore.QObject):
|
||||||
"""
|
"""
|
||||||
A special Qt thread class to allow the HTTP server to run at the same time as the UI.
|
A special Qt thread class to allow the WebSockets server to run at the same time as the UI.
|
||||||
"""
|
"""
|
||||||
def __init__(self, server):
|
def __init__(self, server):
|
||||||
"""
|
"""
|
||||||
@ -66,7 +66,7 @@ class OpenLPWSServer(RegistryProperties, OpenLPMixin):
|
|||||||
"""
|
"""
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
"""
|
"""
|
||||||
Initialise the http server, and start the server of the correct type http / https
|
Initialise the http server, and start the WebSockets server
|
||||||
"""
|
"""
|
||||||
super(OpenLPWSServer, self).__init__()
|
super(OpenLPWSServer, self).__init__()
|
||||||
self.settings_section = 'remotes'
|
self.settings_section = 'remotes'
|
||||||
@ -115,10 +115,11 @@ class OpenLPWSServer(RegistryProperties, OpenLPMixin):
|
|||||||
def handle_websocket(request, path):
|
def handle_websocket(request, path):
|
||||||
"""
|
"""
|
||||||
Handle web socket requests and return the poll information.
|
Handle web socket requests and return the poll information.
|
||||||
Check ever 0.5 seconds to get the latest postion and send if changed.
|
Check ever 0.2 seconds to get the latest position and send if changed.
|
||||||
Only gets triggered when 1st client attaches
|
Only gets triggered when 1st client attaches
|
||||||
|
|
||||||
:param request: request from client
|
:param request: request from client
|
||||||
:param path: not used - future to register for a different end point
|
:param path: determines the endpoints supported
|
||||||
:return:
|
:return:
|
||||||
"""
|
"""
|
||||||
log.debug("web socket handler registered with client")
|
log.debug("web socket handler registered with client")
|
||||||
|
49
tests/functional/openlp_core_api/test_httpserver.py
Normal file
49
tests/functional/openlp_core_api/test_httpserver.py
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
||||||
|
|
||||||
|
###############################################################################
|
||||||
|
# OpenLP - Open Source Lyrics Projection #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# Copyright (c) 2008-2016 OpenLP Developers #
|
||||||
|
# --------------------------------------------------------------------------- #
|
||||||
|
# This program is free software; you can redistribute it and/or modify it #
|
||||||
|
# under the terms of the GNU General Public License as published by the Free #
|
||||||
|
# Software Foundation; version 2 of the License. #
|
||||||
|
# #
|
||||||
|
# This program is distributed in the hope that it will be useful, but WITHOUT #
|
||||||
|
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or #
|
||||||
|
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for #
|
||||||
|
# more details. #
|
||||||
|
# #
|
||||||
|
# You should have received a copy of the GNU General Public License along #
|
||||||
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
|
###############################################################################
|
||||||
|
"""
|
||||||
|
Functional tests to test the Http Server Class.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from openlp.core.api import OpenLPHttpServer
|
||||||
|
|
||||||
|
from tests.functional import patch
|
||||||
|
|
||||||
|
|
||||||
|
class TestHttpServer(TestCase):
|
||||||
|
"""
|
||||||
|
A test suite to test starting the http server
|
||||||
|
"""
|
||||||
|
@patch('openlp.core.api.httpserver.HttpThread')
|
||||||
|
@patch('openlp.core.api.httpserver.QtCore.QThread')
|
||||||
|
def test_bootstrap(self, mock_qthread, mock_thread):
|
||||||
|
"""
|
||||||
|
Test the starting of the Waitress Server
|
||||||
|
"""
|
||||||
|
# GIVEN: A new httpserver
|
||||||
|
# WHEN: I start the server
|
||||||
|
server = OpenLPHttpServer()
|
||||||
|
|
||||||
|
# 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')
|
Loading…
Reference in New Issue
Block a user