forked from openlp/openlp
fix test
This commit is contained in:
parent
76af52b2bf
commit
4b0b8b9647
|
@ -36,19 +36,7 @@ class ApiTab(SettingsTab):
|
||||||
self.icon_path = ':/plugins/plugin_remote.png'
|
self.icon_path = ':/plugins/plugin_remote.png'
|
||||||
advanced_translated = translate('OpenLP.AdvancedTab', 'Advanced')
|
advanced_translated = translate('OpenLP.AdvancedTab', 'Advanced')
|
||||||
super(ApiTab, self).__init__(parent, 'remotes', advanced_translated)
|
super(ApiTab, self).__init__(parent, 'remotes', advanced_translated)
|
||||||
if not hasattr(self, 'remote_server_icon'):
|
self.define_main_window_icon()
|
||||||
self.remote_server_icon = QtWidgets.QLabel(self.main_window.status_bar)
|
|
||||||
size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
|
|
||||||
size_policy.setHorizontalStretch(0)
|
|
||||||
size_policy.setVerticalStretch(0)
|
|
||||||
size_policy.setHeightForWidth(self.remote_server_icon.sizePolicy().hasHeightForWidth())
|
|
||||||
self.remote_server_icon.setSizePolicy(size_policy)
|
|
||||||
self.remote_server_icon.setFrameShadow(QtWidgets.QFrame.Plain)
|
|
||||||
self.remote_server_icon.setLineWidth(1)
|
|
||||||
self.remote_server_icon.setScaledContents(True)
|
|
||||||
self.remote_server_icon.setFixedSize(20, 20)
|
|
||||||
self.remote_server_icon.setObjectName('remote_server_icon')
|
|
||||||
self.main_window.status_bar.insertPermanentWidget(2, self.remote_server_icon)
|
|
||||||
self.generate_icon()
|
self.generate_icon()
|
||||||
|
|
||||||
def setupUi(self):
|
def setupUi(self):
|
||||||
|
@ -154,6 +142,24 @@ class ApiTab(SettingsTab):
|
||||||
self.thumbnails_check_box.stateChanged.connect(self.on_thumbnails_check_box_changed)
|
self.thumbnails_check_box.stateChanged.connect(self.on_thumbnails_check_box_changed)
|
||||||
self.address_edit.textChanged.connect(self.set_urls)
|
self.address_edit.textChanged.connect(self.set_urls)
|
||||||
|
|
||||||
|
def define_main_window_icon(self):
|
||||||
|
"""
|
||||||
|
Define an icon on the main window to show the state of the server
|
||||||
|
:return:
|
||||||
|
"""
|
||||||
|
self.remote_server_icon = QtWidgets.QLabel(self.main_window.status_bar)
|
||||||
|
size_policy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
|
||||||
|
size_policy.setHorizontalStretch(0)
|
||||||
|
size_policy.setVerticalStretch(0)
|
||||||
|
size_policy.setHeightForWidth(self.remote_server_icon.sizePolicy().hasHeightForWidth())
|
||||||
|
self.remote_server_icon.setSizePolicy(size_policy)
|
||||||
|
self.remote_server_icon.setFrameShadow(QtWidgets.QFrame.Plain)
|
||||||
|
self.remote_server_icon.setLineWidth(1)
|
||||||
|
self.remote_server_icon.setScaledContents(True)
|
||||||
|
self.remote_server_icon.setFixedSize(20, 20)
|
||||||
|
self.remote_server_icon.setObjectName('remote_server_icon')
|
||||||
|
self.main_window.status_bar.insertPermanentWidget(2, self.remote_server_icon)
|
||||||
|
|
||||||
def retranslateUi(self):
|
def retranslateUi(self):
|
||||||
self.tab_title_visible = translate('RemotePlugin.RemoteTab', 'Remote Interface')
|
self.tab_title_visible = translate('RemotePlugin.RemoteTab', 'Remote Interface')
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,3 @@
|
||||||
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
# with this program; if not, write to the Free Software Foundation, Inc., 59 #
|
||||||
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
# Temple Place, Suite 330, Boston, MA 02111-1307 USA #
|
||||||
###############################################################################
|
###############################################################################
|
||||||
|
|
||||||
from .endpoint import remote_endpoint
|
|
||||||
|
|
||||||
|
|
|
@ -29,17 +29,6 @@ from openlp.plugins.remotes.lib.endpoint import remote_endpoint
|
||||||
|
|
||||||
log = logging.getLogger(__name__)
|
log = logging.getLogger(__name__)
|
||||||
|
|
||||||
__default_settings__ = {
|
|
||||||
'remotes/twelve hour': True,
|
|
||||||
'remotes/port': 4316,
|
|
||||||
'remotes/websocket port': 4317,
|
|
||||||
'remotes/user id': 'openlp',
|
|
||||||
'remotes/password': 'password',
|
|
||||||
'remotes/authentication enabled': False,
|
|
||||||
'remotes/ip address': '0.0.0.0',
|
|
||||||
'remotes/thumbnails': True
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
class RemotesPlugin(Plugin, OpenLPMixin):
|
class RemotesPlugin(Plugin, OpenLPMixin):
|
||||||
log.info('Remote Plugin loaded')
|
log.info('Remote Plugin loaded')
|
||||||
|
@ -48,12 +37,11 @@ class RemotesPlugin(Plugin, OpenLPMixin):
|
||||||
"""
|
"""
|
||||||
remotes constructor
|
remotes constructor
|
||||||
"""
|
"""
|
||||||
super(RemotesPlugin, self).__init__('remotes', __default_settings__)
|
super(RemotesPlugin, self).__init__('remotes')
|
||||||
self.icon_path = ':/plugins/plugin_remote.png'
|
self.icon_path = ':/plugins/plugin_remote.png'
|
||||||
self.icon = build_icon(self.icon_path)
|
self.icon = build_icon(self.icon_path)
|
||||||
self.weight = -1
|
self.weight = -1
|
||||||
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def about():
|
def about():
|
||||||
"""
|
"""
|
||||||
|
|
|
@ -1,55 +0,0 @@
|
||||||
# -*- 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.controller.Poll')
|
|
||||||
@patch('openlp.core.api.controller.WebSocketServer')
|
|
||||||
@patch('openlp.core.api.controller.http.HttpServer')
|
|
||||||
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')
|
|
|
@ -1,116 +0,0 @@
|
||||||
# -*- 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 #
|
|
||||||
###############################################################################
|
|
||||||
"""
|
|
||||||
This module contains tests for the lib submodule of the Remotes plugin.
|
|
||||||
"""
|
|
||||||
import os
|
|
||||||
import re
|
|
||||||
from unittest import TestCase
|
|
||||||
|
|
||||||
from PyQt5 import QtWidgets
|
|
||||||
|
|
||||||
|
|
||||||
from openlp.core.common import Settings
|
|
||||||
from openlp.core.api.apitab import ApiTab
|
|
||||||
from tests.functional import patch
|
|
||||||
from tests.helpers.testmixin import TestMixin
|
|
||||||
|
|
||||||
__default_settings__ = {
|
|
||||||
'remotes/twelve hour': True,
|
|
||||||
'remotes/port': 4316,
|
|
||||||
'remotes/user id': 'openlp',
|
|
||||||
'remotes/password': 'password',
|
|
||||||
'remotes/authentication enabled': False,
|
|
||||||
'remotes/ip address': '0.0.0.0',
|
|
||||||
'remotes/thumbnails': True
|
|
||||||
}
|
|
||||||
ZERO_URL = '0.0.0.0'
|
|
||||||
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
|
|
||||||
|
|
||||||
|
|
||||||
class TestApiTab(TestCase, TestMixin):
|
|
||||||
"""
|
|
||||||
Test the functions in the :mod:`lib` module.
|
|
||||||
"""
|
|
||||||
def setUp(self):
|
|
||||||
"""
|
|
||||||
Create the UI
|
|
||||||
"""
|
|
||||||
self.setup_application()
|
|
||||||
self.build_settings()
|
|
||||||
Settings().extend_default_settings(__default_settings__)
|
|
||||||
self.parent = QtWidgets.QMainWindow()
|
|
||||||
self.form = ApiTab(self.parent)
|
|
||||||
|
|
||||||
def tearDown(self):
|
|
||||||
"""
|
|
||||||
Delete all the C++ objects at the end so that we don't have a segfault
|
|
||||||
"""
|
|
||||||
del self.parent
|
|
||||||
del self.form
|
|
||||||
self.destroy_settings()
|
|
||||||
|
|
||||||
def test_get_ip_address_default(self):
|
|
||||||
"""
|
|
||||||
Test the get_ip_address function with ZERO_URL
|
|
||||||
"""
|
|
||||||
# WHEN: the default ip address is given
|
|
||||||
ip_address = self.form.get_ip_address(ZERO_URL)
|
|
||||||
# THEN: the default ip address will be returned
|
|
||||||
self.assertTrue(re.match('\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip_address),
|
|
||||||
'The return value should be a valid ip address')
|
|
||||||
|
|
||||||
def test_get_ip_address_with_ip(self):
|
|
||||||
"""
|
|
||||||
Test the get_ip_address function with given ip address
|
|
||||||
"""
|
|
||||||
# GIVEN: A mocked location
|
|
||||||
# GIVEN: An ip address
|
|
||||||
given_ip = '192.168.1.1'
|
|
||||||
# WHEN: the default ip address is given
|
|
||||||
ip_address = self.form.get_ip_address(given_ip)
|
|
||||||
# THEN: the default ip address will be returned
|
|
||||||
self.assertEqual(ip_address, given_ip, 'The return value should be %s' % given_ip)
|
|
||||||
|
|
||||||
def test_set_basic_urls(self):
|
|
||||||
"""
|
|
||||||
Test the set_urls function with standard defaults
|
|
||||||
"""
|
|
||||||
# GIVEN: A mocked location
|
|
||||||
with patch('openlp.core.common.Settings') as mocked_class, \
|
|
||||||
patch('openlp.core.common.applocation.AppLocation.get_directory') as mocked_get_directory, \
|
|
||||||
patch('openlp.core.common.check_directory_exists') as mocked_check_directory_exists, \
|
|
||||||
patch('openlp.core.common.applocation.os') as mocked_os:
|
|
||||||
# GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory()
|
|
||||||
mocked_settings = mocked_class.return_value
|
|
||||||
mocked_settings.contains.return_value = False
|
|
||||||
mocked_get_directory.return_value = 'test/dir'
|
|
||||||
mocked_check_directory_exists.return_value = True
|
|
||||||
mocked_os.path.normpath.return_value = 'test/dir'
|
|
||||||
|
|
||||||
# WHEN: when the set_urls is called having reloaded the form.
|
|
||||||
self.form.load()
|
|
||||||
self.form.set_urls()
|
|
||||||
# THEN: the following screen values should be set
|
|
||||||
self.assertEqual(self.form.address_edit.text(), ZERO_URL, 'The default URL should be set on the screen')
|
|
||||||
self.assertEqual(self.form.user_login_group_box.isChecked(), False,
|
|
||||||
'The authentication box should not be enabled')
|
|
Loading…
Reference in New Issue