forked from openlp/openlp
More fixes
This commit is contained in:
parent
da32a56c0c
commit
70288c8ae1
@ -1,9 +1,30 @@
|
|||||||
|
# -*- 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 #
|
||||||
|
###############################################################################
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
|
||||||
from openlp.core.api.http.endpoint import Endpoint
|
from openlp.core.api.http.endpoint import Endpoint
|
||||||
from openlp.core.api.http import register_endpoint, requires_auth, ROOT_DIR
|
from openlp.core.api.http import register_endpoint, requires_auth, ROOT_DIR
|
||||||
from openlp.core.common import Registry, AppLocation, UiStrings, translate
|
from openlp.core.common import Registry, UiStrings, translate
|
||||||
from openlp.core.lib import image_to_byte, PluginStatus, StringContent
|
from openlp.core.lib import image_to_byte, PluginStatus, StringContent
|
||||||
|
|
||||||
|
|
||||||
|
@ -30,7 +30,7 @@ window.OpenLP = {
|
|||||||
pollServer: function () {
|
pollServer: function () {
|
||||||
if ("WebSocket" in window) {
|
if ("WebSocket" in window) {
|
||||||
// Let us open a web socket
|
// Let us open a web socket
|
||||||
var ws = new WebSocket('ws://' + location.hostname + ':4317/main_poll');
|
var ws = new WebSocket('ws://' + location.hostname + ':4317/live_changed');
|
||||||
ws.binaryType = 'arraybuffer';
|
ws.binaryType = 'arraybuffer';
|
||||||
ws.onmessage = function (evt) {
|
ws.onmessage = function (evt) {
|
||||||
var msg = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(evt.data)));
|
var msg = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(evt.data)));
|
||||||
|
@ -149,7 +149,7 @@ window.OpenLP = {
|
|||||||
pollServer: function () {
|
pollServer: function () {
|
||||||
if ("WebSocket" in window) {
|
if ("WebSocket" in window) {
|
||||||
// Let us open a web socket
|
// Let us open a web socket
|
||||||
var ws = new WebSocket('ws://' + location.hostname + ':4317/poll');
|
var ws = new WebSocket('ws://' + location.hostname + ':4317/state');
|
||||||
ws.binaryType = 'arraybuffer';
|
ws.binaryType = 'arraybuffer';
|
||||||
ws.onmessage = function (evt) {
|
ws.onmessage = function (evt) {
|
||||||
var msg = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(evt.data)));
|
var msg = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(evt.data)));
|
||||||
|
@ -126,15 +126,14 @@ class WebSocketServer(RegistryProperties, OpenLPMixin):
|
|||||||
previous_poll = None
|
previous_poll = None
|
||||||
previous_main_poll = None
|
previous_main_poll = None
|
||||||
poller = Registry().get('poller')
|
poller = Registry().get('poller')
|
||||||
# TODO: FIXME: These URLs need to be named better
|
if path == '/state':
|
||||||
if path == '/poll':
|
|
||||||
while True:
|
while True:
|
||||||
current_poll = poller.poll()
|
current_poll = poller.poll()
|
||||||
if current_poll != previous_poll:
|
if current_poll != previous_poll:
|
||||||
yield from request.send(current_poll)
|
yield from request.send(current_poll)
|
||||||
previous_poll = current_poll
|
previous_poll = current_poll
|
||||||
yield from asyncio.sleep(0.2)
|
yield from asyncio.sleep(0.2)
|
||||||
elif path == '/main_poll':
|
elif path == '/live_changed':
|
||||||
while True:
|
while True:
|
||||||
main_poll = poller.main_poll()
|
main_poll = poller.main_poll()
|
||||||
if main_poll != previous_main_poll:
|
if main_poll != previous_main_poll:
|
||||||
|
@ -603,7 +603,7 @@ class SongMediaItem(MediaManagerItem):
|
|||||||
else:
|
else:
|
||||||
verse_index = VerseType.from_tag(verse[0]['type'])
|
verse_index = VerseType.from_tag(verse[0]['type'])
|
||||||
verse_tag = VerseType.translated_tags[verse_index]
|
verse_tag = VerseType.translated_tags[verse_index]
|
||||||
verse_def = '{tag}{label}'.format(tzg=verse_tag, text=verse[0]['label'])
|
verse_def = '{tag}{label}'.format(tag=verse_tag, label=verse[0]['label'])
|
||||||
service_item.add_from_text(verse[1], verse_def)
|
service_item.add_from_text(verse[1], verse_def)
|
||||||
service_item.title = song.title
|
service_item.title = song.title
|
||||||
author_list = self.generate_footer(service_item, song)
|
author_list = self.generate_footer(service_item, song)
|
||||||
|
@ -270,6 +270,7 @@ class OpenLyrics(object):
|
|||||||
if song.songbook_entries:
|
if song.songbook_entries:
|
||||||
songbooks = etree.SubElement(properties, 'songbooks')
|
songbooks = etree.SubElement(properties, 'songbooks')
|
||||||
for songbook_entry in song.songbook_entries:
|
for songbook_entry in song.songbook_entries:
|
||||||
|
# TODO IS THIS RIGHT AS IT FAILS WITH AN ERROR SHOULD IT BE AFTER THE IF TEST
|
||||||
element = self._add_text_to_element('songbook', songbooks, None, songbook_entry.songbook.name)
|
element = self._add_text_to_element('songbook', songbooks, None, songbook_entry.songbook.name)
|
||||||
if songbook_entry.entry:
|
if songbook_entry.entry:
|
||||||
element.set('entry', songbook_entry.entry)
|
element.set('entry', songbook_entry.entry)
|
||||||
@ -458,7 +459,7 @@ class OpenLyrics(object):
|
|||||||
self._add_tag_to_formatting(tag, tags_element)
|
self._add_tag_to_formatting(tag, tags_element)
|
||||||
# Replace end tags.
|
# Replace end tags.
|
||||||
for tag in end_tags:
|
for tag in end_tags:
|
||||||
text = text.replace('{/{tag}}}'.format(tag=tag), '</tag>')
|
text = text.replace('{{/{tag}}}'.format(tag=tag), '</tag>')
|
||||||
# Replace \n with <br/>.
|
# Replace \n with <br/>.
|
||||||
text = text.replace('\n', '<br/>')
|
text = text.replace('\n', '<br/>')
|
||||||
element = etree.XML('<lines>{text}</lines>'.format(text=text))
|
element = etree.XML('<lines>{text}</lines>'.format(text=text))
|
||||||
@ -567,7 +568,7 @@ class OpenLyrics(object):
|
|||||||
name = tag.get('name')
|
name = tag.get('name')
|
||||||
if name is None:
|
if name is None:
|
||||||
continue
|
continue
|
||||||
start_tag = '{{{name}}}'.format(name=name[:5])
|
start_tag = '{{/{name}}}'.format(name=name[:5])
|
||||||
# Some tags have only start tag e.g. {br}
|
# Some tags have only start tag e.g. {br}
|
||||||
end_tag = '{{/{name}}}'.format(name=name[:5]) if hasattr(tag, 'close') else ''
|
end_tag = '{{/{name}}}'.format(name=name[:5]) if hasattr(tag, 'close') else ''
|
||||||
openlp_tag = {
|
openlp_tag = {
|
||||||
|
55
tests/functional/openlp_core_api/test_controller.py
Normal file
55
tests/functional/openlp_core_api/test_controller.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 TestController(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')
|
118
tests/functional/openlp_core_api/test_tab.py
Normal file
118
tests/functional/openlp_core_api/test_tab.py
Normal file
@ -0,0 +1,118 @@
|
|||||||
|
# -*- 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.tab import ApiTab
|
||||||
|
from tests.functional import patch
|
||||||
|
from tests.helpers.testmixin import TestMixin
|
||||||
|
|
||||||
|
__default_settings__ = {
|
||||||
|
'api/twelve hour': True,
|
||||||
|
'api/port': 4316,
|
||||||
|
'api/user id': 'openlp',
|
||||||
|
'api/password': 'password',
|
||||||
|
'api/authentication enabled': False,
|
||||||
|
'api/ip address': '0.0.0.0',
|
||||||
|
'api/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.
|
||||||
|
"""
|
||||||
|
@patch('openlp.core.api.tab.ApiTab.define_main_window_icon')
|
||||||
|
@patch('openlp.core.api.tab.ApiTab.generate_icon')
|
||||||
|
def setUp(self, mocked_main_window, mocked_icon):
|
||||||
|
"""
|
||||||
|
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
Block a user