forked from openlp/openlp
Test apicontroiler
This commit is contained in:
parent
7558395b54
commit
6a81063fe7
@ -51,7 +51,7 @@ def register_endpoint(end_point):
|
|||||||
from .endpoint import Endpoint
|
from .endpoint import Endpoint
|
||||||
from .apitab import ApiTab
|
from .apitab import ApiTab
|
||||||
from .poll import OpenLPPoll
|
from .poll import OpenLPPoll
|
||||||
from .wsserver import OpenWSServer
|
from .wsserver import OpenLPWSServer
|
||||||
from .httpserver import OpenLPHttpServer
|
from .httpserver import OpenLPHttpServer
|
||||||
from .apicontroller import ApiController
|
from .apicontroller import ApiController
|
||||||
|
|
||||||
|
@ -21,7 +21,7 @@
|
|||||||
###############################################################################
|
###############################################################################
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
from openlp.core.api import OpenWSServer, OpenLPPoll, OpenLPHttpServer
|
from openlp.core.api import OpenLPWSServer, OpenLPPoll, OpenLPHttpServer
|
||||||
from openlp.core.common import OpenLPMixin, Registry, RegistryMixin, RegistryProperties
|
from openlp.core.common import OpenLPMixin, Registry, RegistryMixin, RegistryProperties
|
||||||
|
|
||||||
# These are here to load the endpoints
|
# These are here to load the endpoints
|
||||||
@ -33,15 +33,9 @@ log = logging.getLogger(__name__)
|
|||||||
|
|
||||||
class ApiController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
class ApiController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
||||||
"""
|
"""
|
||||||
The implementation of the Media Controller. The Media Controller adds an own class for every Player.
|
The APIController handles the starting of the API middleware.
|
||||||
Currently these are QtWebkit, Phonon and Vlc. display_controllers are an array of controllers keyed on the
|
The HTTP and Websocket servers are started
|
||||||
slidecontroller or plugin which built them.
|
The core endpoints are generated (just by their declaration).
|
||||||
|
|
||||||
ControllerType is the class containing the key values.
|
|
||||||
|
|
||||||
media_players are an array of media players keyed on player name.
|
|
||||||
|
|
||||||
current_media_players is an array of player instances keyed on ControllerType.
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
def __init__(self, parent=None):
|
def __init__(self, parent=None):
|
||||||
@ -49,13 +43,12 @@ class ApiController(RegistryMixin, OpenLPMixin, RegistryProperties):
|
|||||||
Constructor
|
Constructor
|
||||||
"""
|
"""
|
||||||
super(ApiController, self).__init__(parent)
|
super(ApiController, self).__init__(parent)
|
||||||
print("apic")
|
|
||||||
|
|
||||||
def bootstrap_post_set_up(self):
|
def bootstrap_post_set_up(self):
|
||||||
"""
|
"""
|
||||||
process the bootstrap post setup request
|
Register the poll return service and start the servers.
|
||||||
"""
|
"""
|
||||||
self.poll = OpenLPPoll()
|
self.poll = OpenLPPoll()
|
||||||
Registry().register('OpenLPPoll', self.poll)
|
Registry().register('OpenLPPoll', self.poll)
|
||||||
self.wsserver = OpenWSServer()
|
self.wsserver = OpenLPWSServer()
|
||||||
self.httpserver = OpenLPHttpServer()
|
self.httpserver = OpenLPHttpServer()
|
||||||
|
@ -60,7 +60,7 @@ class WSThread(QtCore.QObject):
|
|||||||
self.ws_server.stop = True
|
self.ws_server.stop = True
|
||||||
|
|
||||||
|
|
||||||
class OpenWSServer(RegistryProperties, OpenLPMixin):
|
class OpenLPWSServer(RegistryProperties, OpenLPMixin):
|
||||||
"""
|
"""
|
||||||
Wrapper round a server instance
|
Wrapper round a server instance
|
||||||
"""
|
"""
|
||||||
@ -68,7 +68,7 @@ class OpenWSServer(RegistryProperties, OpenLPMixin):
|
|||||||
"""
|
"""
|
||||||
Initialise the http server, and start the server of the correct type http / https
|
Initialise the http server, and start the server of the correct type http / https
|
||||||
"""
|
"""
|
||||||
super(OpenWSServer, self).__init__()
|
super(OpenLPWSServer, self).__init__()
|
||||||
self.settings_section = 'remotes'
|
self.settings_section = 'remotes'
|
||||||
self.thread = QtCore.QThread()
|
self.thread = QtCore.QThread()
|
||||||
self.worker = WSThread(self)
|
self.worker = WSThread(self)
|
||||||
|
55
tests/functional/openlp_core_api/test_apicontroller.py
Normal file
55
tests/functional/openlp_core_api/test_apicontroller.py
Normal file
@ -0,0 +1,55 @@
|
|||||||
|
# -*- 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 API Error Class.
|
||||||
|
"""
|
||||||
|
|
||||||
|
from unittest import TestCase
|
||||||
|
|
||||||
|
from openlp.core.api import ApiController
|
||||||
|
from openlp.core.common import Registry
|
||||||
|
|
||||||
|
from tests.functional import patch
|
||||||
|
|
||||||
|
|
||||||
|
class TestApiController(TestCase):
|
||||||
|
"""
|
||||||
|
A test suite to test out the Error in the API code
|
||||||
|
"""
|
||||||
|
@patch('openlp.core.api.apicontroller.OpenLPPoll')
|
||||||
|
@patch('openlp.core.api.apicontroller.OpenLPWSServer')
|
||||||
|
@patch('openlp.core.api.apicontroller.OpenLPHttpServer')
|
||||||
|
def test_bootstrap(self, mock_http, mock_ws, mock_poll):
|
||||||
|
"""
|
||||||
|
Test the Not Found error displays the correct information
|
||||||
|
"""
|
||||||
|
# GIVEN: A controller
|
||||||
|
Registry.create()
|
||||||
|
apicontroller = ApiController()
|
||||||
|
|
||||||
|
# WHEN: I call the bootstrap
|
||||||
|
apicontroller.bootstrap_post_set_up()
|
||||||
|
|
||||||
|
# THEN: the api environment should have been created
|
||||||
|
self.assertEquals(1, mock_http.call_count, 'The Http server should have been called once')
|
||||||
|
self.assertEquals(1, mock_ws.call_count, 'The WS server should have been called once')
|
||||||
|
self.assertEquals(1, mock_poll.call_count, 'The OpenLPPoll should have been called once')
|
@ -36,9 +36,12 @@ class TestApiError(TestCase):
|
|||||||
"""
|
"""
|
||||||
Test the Not Found error displays the correct information
|
Test the Not Found error displays the correct information
|
||||||
"""
|
"""
|
||||||
|
# GIVEN:
|
||||||
|
# WHEN: I raise an exception
|
||||||
with self.assertRaises(Exception) as context:
|
with self.assertRaises(Exception) as context:
|
||||||
raise NotFound()
|
raise NotFound()
|
||||||
|
|
||||||
|
# THEN: we get an error and a status
|
||||||
self.assertEquals('Not Found', context.exception.message, 'A Not Found exception should be thrown')
|
self.assertEquals('Not Found', context.exception.message, 'A Not Found exception should be thrown')
|
||||||
self.assertEquals(404, context.exception.status, 'A 404 status should be thrown')
|
self.assertEquals(404, context.exception.status, 'A 404 status should be thrown')
|
||||||
|
|
||||||
@ -46,8 +49,11 @@ class TestApiError(TestCase):
|
|||||||
"""
|
"""
|
||||||
Test the server error displays the correct information
|
Test the server error displays the correct information
|
||||||
"""
|
"""
|
||||||
|
# GIVEN:
|
||||||
|
# WHEN: I raise an exception
|
||||||
with self.assertRaises(Exception) as context:
|
with self.assertRaises(Exception) as context:
|
||||||
raise ServerError()
|
raise ServerError()
|
||||||
|
|
||||||
|
# THEN: we get an error and a status
|
||||||
self.assertEquals('Server Error', context.exception.message, 'A Not Found exception should be thrown')
|
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')
|
@ -26,7 +26,7 @@ import os
|
|||||||
import urllib.request
|
import urllib.request
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
|
|
||||||
from openlp.core.api.api import OpenLPPoll
|
from openlp.core.api.poll import OpenLPPoll
|
||||||
from openlp.core.common import Settings, Registry
|
from openlp.core.common import Settings, Registry
|
||||||
from openlp.core.ui import ServiceManager
|
from openlp.core.ui import ServiceManager
|
||||||
from openlp.plugins.remotes.lib.httpserver import HttpRouter
|
from openlp.plugins.remotes.lib.httpserver import HttpRouter
|
||||||
|
Loading…
Reference in New Issue
Block a user