This commit is contained in:
Phill Ridout 2017-12-02 21:37:06 +00:00
commit 4014179032
14 changed files with 234 additions and 128 deletions

View File

@ -82,13 +82,14 @@ class HttpServer(RegistryBase, RegistryProperties, LogMixin):
Initialise the http server, and start the http server
"""
super(HttpServer, self).__init__(parent)
self.worker = HttpWorker()
self.thread = QtCore.QThread()
self.worker.moveToThread(self.thread)
self.thread.started.connect(self.worker.run)
self.thread.start()
Registry().register_function('download_website', self.first_time)
Registry().register_function('get_website_version', self.website_version)
if Registry().get_flag('no_web_server'):
self.worker = HttpWorker()
self.thread = QtCore.QThread()
self.worker.moveToThread(self.thread)
self.thread.started.connect(self.worker.run)
self.thread.start()
Registry().register_function('download_website', self.first_time)
Registry().register_function('get_website_version', self.website_version)
Registry().set_flag('website_version', '0.0')
def bootstrap_post_set_up(self):

View File

@ -70,12 +70,13 @@ class WebSocketServer(RegistryProperties, LogMixin):
Initialise and start the WebSockets server
"""
super(WebSocketServer, self).__init__()
self.settings_section = 'api'
self.worker = WebSocketWorker(self)
self.thread = QtCore.QThread()
self.worker.moveToThread(self.thread)
self.thread.started.connect(self.worker.run)
self.thread.start()
if Registry().get_flag('no_web_server'):
self.settings_section = 'api'
self.worker = WebSocketWorker(self)
self.thread = QtCore.QThread()
self.worker.moveToThread(self.thread)
self.thread.started.connect(self.worker.run)
self.thread.start()
def start_server(self):
"""

View File

@ -672,14 +672,16 @@ class ProjectorManager(QtWidgets.QWidget, RegistryBase, UiProjectorManager, LogM
data=projector.model_filter)
count = 1
for item in projector.link.lamp:
if item['On'] is None:
status = translate('OpenLP.ProjectorManager', 'Unavailable')
elif item['On']:
status = translate('OpenLP.ProjectorManager', 'ON')
else:
status = translate('OpenLP.ProjectorManager', 'OFF')
message += '<b>{title} {count}</b> {status} '.format(title=translate('OpenLP.ProjectorManager',
'Lamp'),
count=count,
status=translate('OpenLP.ProjectorManager',
'ON')
if item['On']
else translate('OpenLP.ProjectorManager',
'OFF'))
status=status)
message += '<b>{title}</b>: {hours}<br />'.format(title=translate('OpenLP.ProjectorManager', 'Hours'),
hours=item['Hours'])

View File

@ -402,17 +402,20 @@ class PJLinkCommands(object):
:param data: Lamp(s) status.
"""
lamps = []
data_dict = data.split()
while data_dict:
try:
fill = {'Hours': int(data_dict[0]), 'On': False if data_dict[1] == '0' else True}
except ValueError:
# In case of invalid entry
log.warning('({ip}) process_lamp(): Invalid data "{data}"'.format(ip=self.ip, data=data))
return
lamps.append(fill)
data_dict.pop(0) # Remove lamp hours
data_dict.pop(0) # Remove lamp on/off
lamp_list = data.split()
if len(lamp_list) < 2:
lamps.append({'Hours': int(lamp_list[0]), 'On': None})
else:
while lamp_list:
try:
fill = {'Hours': int(lamp_list[0]), 'On': False if lamp_list[1] == '0' else True}
except ValueError:
# In case of invalid entry
log.warning('({ip}) process_lamp(): Invalid data "{data}"'.format(ip=self.ip, data=data))
return
lamps.append(fill)
lamp_list.pop(0) # Remove lamp hours
lamp_list.pop(0) # Remove lamp on/off
self.lamp = lamps
return

View File

@ -504,9 +504,8 @@ class MainWindow(QtWidgets.QMainWindow, Ui_MainWindow, RegistryProperties):
Settings().set_up_default_values()
self.about_form = AboutForm(self)
MediaController()
if Registry().get_flag('no_web_server'):
websockets.WebSocketServer()
server.HttpServer()
websockets.WebSocketServer()
server.HttpServer()
SettingsForm(self)
self.formatting_tag_form = FormattingTagForm(self)
self.shortcut_form = ShortcutListForm(self)

View File

@ -63,9 +63,10 @@ class OpenLPJobs(object):
Branch_Coverage = 'Branch-04b-Test_Coverage'
Branch_Pylint = 'Branch-04c-Code_Analysis2'
Branch_AppVeyor = 'Branch-05-AppVeyor-Tests'
Branch_macOS = 'Branch-07-macOS-Tests'
Jobs = [Branch_Pull, Branch_Functional, Branch_Interface, Branch_PEP, Branch_Coverage, Branch_Pylint,
Branch_AppVeyor]
Branch_AppVeyor, Branch_macOS]
class Colour(object):
@ -115,7 +116,7 @@ class JenkinsTrigger(object):
self.fetch_jobs()
self.server.build_job(OpenLPJobs.Branch_Pull, {'BRANCH_NAME': self.repo_name, 'cause': cause})
def print_output(self):
def print_output(self, can_continue=False):
"""
Print the status information of the build triggered.
"""
@ -126,13 +127,21 @@ class JenkinsTrigger(object):
revno = raw_output.decode().strip()
print('%s (revision %s)' % (get_repo_name(), revno))
failed_builds = []
for job in OpenLPJobs.Jobs:
if not self.__print_build_info(job):
if self.current_build:
print('Stopping after failure, see {}console for more details'.format(self.current_build['url']))
else:
failed_builds.append((self.current_build['fullDisplayName'], self.current_build['url']))
if not can_continue:
print('Stopping after failure')
break
break
print('')
if failed_builds:
print('Failed builds:')
for build_name, url in failed_builds:
print(' - {}: {}console'.format(build_name, url))
else:
print('All builds passed')
def open_browser(self):
"""
@ -227,6 +236,7 @@ def main():
help='Disable coloured output (always disabled on Windows)')
parser.add_argument('-u', '--username', required=True, help='Your Jenkins username')
parser.add_argument('-p', '--password', required=True, help='Your Jenkins password or personal token')
parser.add_argument('-c', '--always-continue', action='store_true', default=False, help='Continue despite failure')
args = parser.parse_args()
if not get_repo_name():
@ -238,7 +248,7 @@ def main():
if args.open_browser:
jenkins_trigger.open_browser()
if not args.disable_output:
jenkins_trigger.print_output()
jenkins_trigger.print_output(can_continue=args.always_continue)
if __name__ == '__main__':

View File

@ -45,12 +45,28 @@ class TestHttpServer(TestCase):
@patch('openlp.core.api.http.server.QtCore.QThread')
def test_server_start(self, mock_qthread, mock_thread):
"""
Test the starting of the Waitress Server
Test the starting of the Waitress Server with the disable flag set off
"""
# GIVEN: A new httpserver
# WHEN: I start the server
Registry().set_flag('no_web_server', True)
HttpServer()
# 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')
@patch('openlp.core.api.http.server.HttpWorker')
@patch('openlp.core.api.http.server.QtCore.QThread')
def test_server_start_not_required(self, mock_qthread, mock_thread):
"""
Test the starting of the Waitress Server with the disable flag set off
"""
# GIVEN: A new httpserver
# WHEN: I start the server
Registry().set_flag('no_web_server', False)
HttpServer()
# THEN: the api environment should have been created
self.assertEquals(0, mock_qthread.call_count, 'The qthread should not have have been called')
self.assertEquals(0, mock_thread.call_count, 'The http thread should not have been called')

View File

@ -66,16 +66,32 @@ class TestWSServer(TestCase, TestMixin):
@patch('openlp.core.api.websockets.QtCore.QThread')
def test_serverstart(self, mock_qthread, mock_worker):
"""
Test the starting of the WebSockets Server
Test the starting of the WebSockets Server with the disabled flag set on
"""
# GIVEN: A new httpserver
# WHEN: I start the server
Registry().set_flag('no_web_server', True)
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_worker.call_count, 'The http thread should have been called once')
@patch('openlp.core.api.websockets.WebSocketWorker')
@patch('openlp.core.api.websockets.QtCore.QThread')
def test_serverstart_not_required(self, mock_qthread, mock_worker):
"""
Test the starting of the WebSockets Server with the disabled flag set off
"""
# GIVEN: A new httpserver and the server is not required
# WHEN: I start the server
Registry().set_flag('no_web_server', False)
WebSocketServer()
# THEN: the api environment should have been created
self.assertEquals(0, mock_qthread.call_count, 'The qthread should not have been called')
self.assertEquals(0, mock_worker.call_count, 'The http thread should not have been called')
def test_main_poll(self):
"""
Test the main_poll function returns the correct JSON

View File

@ -22,8 +22,10 @@
"""
Package to test the openlp.core.lib.languages package.
"""
from unittest import skipIf
from unittest.mock import MagicMock, patch
from openlp.core.common import is_macosx
from openlp.core.common.i18n import LANGUAGES, Language, UiStrings, get_language, get_locale_key, get_natural_key, \
translate
@ -110,6 +112,7 @@ def test_get_language_invalid_with_none():
assert language is None
@skipIf(is_macosx(), 'This test doesn\'t work on macOS currently')
def test_get_locale_key():
"""
Test the get_locale_key(string) function

View File

@ -0,0 +1,134 @@
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
# Copyright (c) 2008-2015 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 #
###############################################################################
"""
Package to test the openlp.core.projectors.pjlink base package.
"""
from unittest import TestCase
from unittest.mock import patch
from openlp.core.projectors.db import Projector
from openlp.core.projectors.pjlink import PJLink
from tests.resources.projector.data import TEST_PIN, TEST_CONNECT_AUTHENTICATE, TEST_HASH, TEST1_DATA
class TestPJLinkBugs(TestCase):
"""
Tests for the PJLink module bugfixes
"""
def setUp(self):
'''
Initialization
'''
self.pjlink_test = PJLink(Projector(**TEST1_DATA), no_poll=True)
def tearDown(self):
'''
Cleanups
'''
self.pjlink_test = None
def test_bug_1550891_process_clss_nonstandard_reply_1(self):
"""
Bugfix 1550891: CLSS request returns non-standard reply with Optoma/Viewsonic projector
"""
# GIVEN: Test object
pjlink = self.pjlink_test
# WHEN: Process non-standard reply
pjlink.process_clss('Class 1')
# THEN: Projector class should be set with proper value
self.assertEqual(pjlink.pjlink_class, '1',
'Non-standard class reply should have set class=1')
def test_bug_1550891_process_clss_nonstandard_reply_2(self):
"""
Bugfix 1550891: CLSS request returns non-standard reply with BenQ projector
"""
# GIVEN: Test object
pjlink = self.pjlink_test
# WHEN: Process non-standard reply
pjlink.process_clss('Version2')
# THEN: Projector class should be set with proper value
# NOTE: At this time BenQ is Class 1, but we're trying a different value to verify
self.assertEqual(pjlink.pjlink_class, '2',
'Non-standard class reply should have set class=2')
def test_bug_1593882_no_pin_authenticated_connection(self):
"""
Test bug 1593882 no pin and authenticated request exception
"""
# GIVEN: Test object and mocks
mock_socket_timer = patch.object(self.pjlink_test, 'socket_timer').start()
mock_timer = patch.object(self.pjlink_test, 'timer').start()
mock_authentication = patch.object(self.pjlink_test, 'projectorAuthentication').start()
mock_ready_read = patch.object(self.pjlink_test, 'waitForReadyRead').start()
mock_send_command = patch.object(self.pjlink_test, 'send_command').start()
pjlink = self.pjlink_test
pjlink.pin = None
mock_ready_read.return_value = True
# WHEN: call with authentication request and pin not set
pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
# THEN: 'No Authentication' signal should have been sent
mock_authentication.emit.assert_called_with(pjlink.ip)
def test_bug_1593883_pjlink_authentication(self):
"""
Test bugfix 1593883 pjlink authentication
"""
# GIVEN: Test object and data
mock_socket_timer = patch.object(self.pjlink_test, 'socket_timer').start()
mock_timer = patch.object(self.pjlink_test, 'timer').start()
mock_send_command = patch.object(self.pjlink_test, 'write').start()
mock_state = patch.object(self.pjlink_test, 'state').start()
mock_waitForReadyRead = patch.object(self.pjlink_test, 'waitForReadyRead').start()
pjlink = self.pjlink_test
pjlink.pin = TEST_PIN
mock_state.return_value = pjlink.ConnectedState
mock_waitForReadyRead.return_value = True
# WHEN: Athenticated connection is called
pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
# THEN: send_command should have the proper authentication
self.assertEqual("{test}".format(test=mock_send_command.call_args),
"call(b'{hash}%1CLSS ?\\r')".format(hash=TEST_HASH))
def test_bug_1734275_process_lamp_nonstandard_reply(self):
"""
Test bugfix 17342785 non-standard LAMP response
"""
# GIVEN: Test object
pjlink = self.pjlink_test
# WHEN: Process lamp command called with only hours and no lamp power state
pjlink.process_lamp("45")
# THEN: Lamp should show hours as 45 and lamp power as Unavailable
self.assertEqual(len(pjlink.lamp), 1, 'There should only be 1 lamp available')
self.assertEqual(pjlink.lamp[0]['Hours'], 45, 'Lamp hours should have equalled 45')
self.assertIsNone(pjlink.lamp[0]['On'], 'Lamp power should be "None"')

View File

@ -29,7 +29,7 @@ from openlp.core.projectors.constants import E_PARAMETER, ERROR_STRING, S_ON, S_
from openlp.core.projectors.db import Projector
from openlp.core.projectors.pjlink import PJLink
from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUTHENTICATE, TEST_HASH, TEST1_DATA
from tests.resources.projector.data import TEST_PIN, TEST_SALT, TEST_CONNECT_AUTHENTICATE, TEST1_DATA
pjlink_test = PJLink(Projector(**TEST1_DATA), no_poll=True)
@ -79,58 +79,6 @@ class TestPJLinkBase(TestCase):
'change_status should have been called with "{}"'.format(
ERROR_STRING[E_PARAMETER]))
@patch.object(pjlink_test, 'send_command')
@patch.object(pjlink_test, 'waitForReadyRead')
@patch.object(pjlink_test, 'projectorAuthentication')
@patch.object(pjlink_test, 'timer')
@patch.object(pjlink_test, 'socket_timer')
def test_bug_1593882_no_pin_authenticated_connection(self,
mock_socket_timer,
mock_timer,
mock_authentication,
mock_ready_read,
mock_send_command):
"""
Test bug 1593882 no pin and authenticated request exception
"""
# GIVEN: Test object and mocks
pjlink = pjlink_test
pjlink.pin = None
mock_ready_read.return_value = True
# WHEN: call with authentication request and pin not set
pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
# THEN: 'No Authentication' signal should have been sent
mock_authentication.emit.assert_called_with(pjlink.ip)
@patch.object(pjlink_test, 'waitForReadyRead')
@patch.object(pjlink_test, 'state')
@patch.object(pjlink_test, '_send_command')
@patch.object(pjlink_test, 'timer')
@patch.object(pjlink_test, 'socket_timer')
def test_bug_1593883_pjlink_authentication(self,
mock_socket_timer,
mock_timer,
mock_send_command,
mock_state,
mock_waitForReadyRead):
"""
Test bugfix 1593883 pjlink authentication
"""
# GIVEN: Test object and data
pjlink = pjlink_test
pjlink.pin = TEST_PIN
mock_state.return_value = pjlink.ConnectedState
mock_waitForReadyRead.return_value = True
# WHEN: Athenticated connection is called
pjlink.check_login(data=TEST_CONNECT_AUTHENTICATE)
# THEN: send_command should have the proper authentication
self.assertEqual("{test}".format(test=mock_send_command.call_args),
"call(data='{hash}%1CLSS ?\\r')".format(hash=TEST_HASH))
@patch.object(pjlink_test, 'disconnect_from_host')
def test_socket_abort(self, mock_disconnect):
"""

View File

@ -570,35 +570,6 @@ class TestPJLinkCommands(TestCase):
self.assertEqual(pjlink.pjlink_class, '2',
'Projector should have set class=2')
def test_projector_process_clss_nonstandard_reply_optoma(self):
"""
Bugfix 1550891: CLSS request returns non-standard reply with Optoma projector
"""
# GIVEN: Test object
pjlink = pjlink_test
# WHEN: Process non-standard reply
pjlink.process_clss('Class 1')
# THEN: Projector class should be set with proper value
self.assertEqual(pjlink.pjlink_class, '1',
'Non-standard class reply should have set class=1')
def test_projector_process_clss_nonstandard_reply_benq(self):
"""
Bugfix 1550891: CLSS request returns non-standard reply with BenQ projector
"""
# GIVEN: Test object
pjlink = pjlink_test
# WHEN: Process non-standard reply
pjlink.process_clss('Version2')
# THEN: Projector class should be set with proper value
# NOTE: At this time BenQ is Class 1, but we're trying a different value to verify
self.assertEqual(pjlink.pjlink_class, '2',
'Non-standard class reply should have set class=2')
@patch.object(openlp.core.projectors.pjlink, 'log')
def test_projector_process_clss_invalid_nan(self, mock_log):
"""

View File

@ -155,7 +155,7 @@ class TestMainWindow(TestCase, TestMixin):
# WHEN: you check the started functions
# THEN: the following registry functions should have been registered
assert len(self.registry.service_list) == 12, \
assert len(self.registry.service_list) == 13, \
'The registry should have 12 services, got {}'.format(self.registry.service_list.keys())
assert len(self.registry.functions_list) == 19, \
'The registry should have 19 functions, got {}'.format(self.registry.functions_list.keys())

View File

@ -22,18 +22,20 @@
"""
This module contains tests for the OpenOffice/LibreOffice importer.
"""
from unittest import TestCase, SkipTest
from unittest import TestCase, skipIf
from unittest.mock import MagicMock, patch
from openlp.core.common.registry import Registry
try:
from openlp.plugins.songs.lib.importers.openoffice import OpenOfficeImport
except ImportError:
raise SkipTest('Could not import OpenOfficeImport probably due to unavailability of uno')
from tests.helpers.testmixin import TestMixin
try:
from openlp.plugins.songs.lib.importers.openoffice import OpenOfficeImport
except ImportError:
OpenOfficeImport = None
@skipIf(OpenOfficeImport is None, 'Could not import OpenOfficeImport probably due to unavailability of uno')
class TestOpenOfficeImport(TestCase, TestMixin):
"""
Test the :class:`~openlp.plugins.songs.lib.importer.openoffice.OpenOfficeImport` class