diff --git a/openlp/core/api/http/endpoint/core.py b/openlp/core/api/http/endpoint/core.py
index 2f990f73d..8ac1d7e31 100644
--- a/openlp/core/api/http/endpoint/core.py
+++ b/openlp/core/api/http/endpoint/core.py
@@ -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 os
from openlp.core.api.http.endpoint import Endpoint
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
diff --git a/openlp/core/api/http/endpoint/static/main/static/js/main.js b/openlp/core/api/http/endpoint/static/main/static/js/main.js
index b6fa81327..8629c758e 100644
--- a/openlp/core/api/http/endpoint/static/main/static/js/main.js
+++ b/openlp/core/api/http/endpoint/static/main/static/js/main.js
@@ -30,7 +30,7 @@ window.OpenLP = {
pollServer: function () {
if ("WebSocket" in window) {
// 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.onmessage = function (evt) {
var msg = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(evt.data)));
diff --git a/openlp/core/api/http/endpoint/static/stage/static/js/stage.js b/openlp/core/api/http/endpoint/static/stage/static/js/stage.js
index 479181da8..6240d431e 100644
--- a/openlp/core/api/http/endpoint/static/stage/static/js/stage.js
+++ b/openlp/core/api/http/endpoint/static/stage/static/js/stage.js
@@ -149,7 +149,7 @@ window.OpenLP = {
pollServer: function () {
if ("WebSocket" in window) {
// 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.onmessage = function (evt) {
var msg = JSON.parse(String.fromCharCode.apply(null, new Uint8Array(evt.data)));
diff --git a/openlp/core/api/websockets.py b/openlp/core/api/websockets.py
index 68516aa1e..478784225 100644
--- a/openlp/core/api/websockets.py
+++ b/openlp/core/api/websockets.py
@@ -126,15 +126,14 @@ class WebSocketServer(RegistryProperties, OpenLPMixin):
previous_poll = None
previous_main_poll = None
poller = Registry().get('poller')
- # TODO: FIXME: These URLs need to be named better
- if path == '/poll':
+ if path == '/state':
while True:
current_poll = poller.poll()
if current_poll != previous_poll:
yield from request.send(current_poll)
previous_poll = current_poll
yield from asyncio.sleep(0.2)
- elif path == '/main_poll':
+ elif path == '/live_changed':
while True:
main_poll = poller.main_poll()
if main_poll != previous_main_poll:
diff --git a/openlp/plugins/songs/lib/mediaitem.py b/openlp/plugins/songs/lib/mediaitem.py
index f52abb86f..63120c966 100644
--- a/openlp/plugins/songs/lib/mediaitem.py
+++ b/openlp/plugins/songs/lib/mediaitem.py
@@ -603,7 +603,7 @@ class SongMediaItem(MediaManagerItem):
else:
verse_index = VerseType.from_tag(verse[0]['type'])
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.title = song.title
author_list = self.generate_footer(service_item, song)
diff --git a/openlp/plugins/songs/lib/openlyricsxml.py b/openlp/plugins/songs/lib/openlyricsxml.py
index 5adffb300..1359fad29 100644
--- a/openlp/plugins/songs/lib/openlyricsxml.py
+++ b/openlp/plugins/songs/lib/openlyricsxml.py
@@ -270,6 +270,7 @@ class OpenLyrics(object):
if song.songbook_entries:
songbooks = etree.SubElement(properties, 'songbooks')
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)
if songbook_entry.entry:
element.set('entry', songbook_entry.entry)
@@ -458,7 +459,7 @@ class OpenLyrics(object):
self._add_tag_to_formatting(tag, tags_element)
# Replace end tags.
for tag in end_tags:
- text = text.replace('{/{tag}}}'.format(tag=tag), '')
+ text = text.replace('{{/{tag}}}'.format(tag=tag), '')
# Replace \n with
.
text = text.replace('\n', '
')
element = etree.XML('{text}'.format(text=text))
@@ -567,7 +568,7 @@ class OpenLyrics(object):
name = tag.get('name')
if name is None:
continue
- start_tag = '{{{name}}}'.format(name=name[:5])
+ start_tag = '{{/{name}}}'.format(name=name[:5])
# Some tags have only start tag e.g. {br}
end_tag = '{{/{name}}}'.format(name=name[:5]) if hasattr(tag, 'close') else ''
openlp_tag = {
diff --git a/tests/functional/openlp_core_api/test_controller.py b/tests/functional/openlp_core_api/test_controller.py
new file mode 100644
index 000000000..08a164d0f
--- /dev/null
+++ b/tests/functional/openlp_core_api/test_controller.py
@@ -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')
diff --git a/tests/functional/openlp_core_api/test_tab.py b/tests/functional/openlp_core_api/test_tab.py
new file mode 100644
index 000000000..a3ccca6c0
--- /dev/null
+++ b/tests/functional/openlp_core_api/test_tab.py
@@ -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')