2013-09-19 21:02:28 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
|
|
|
|
|
|
|
|
###############################################################################
|
|
|
|
# OpenLP - Open Source Lyrics Projection #
|
|
|
|
# --------------------------------------------------------------------------- #
|
2016-12-31 11:01:36 +00:00
|
|
|
# Copyright (c) 2008-2017 OpenLP Developers #
|
2013-09-19 21:02:28 +00:00
|
|
|
# --------------------------------------------------------------------------- #
|
|
|
|
# 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 #
|
|
|
|
###############################################################################
|
2013-04-05 19:37:15 +00:00
|
|
|
"""
|
|
|
|
This module contains tests for the lib submodule of the Remotes plugin.
|
|
|
|
"""
|
|
|
|
import os
|
2013-09-08 16:16:18 +00:00
|
|
|
import re
|
2013-04-05 19:37:15 +00:00
|
|
|
from unittest import TestCase
|
2017-04-24 05:17:55 +00:00
|
|
|
from unittest.mock import patch
|
2013-09-19 21:02:28 +00:00
|
|
|
|
2015-11-07 00:49:40 +00:00
|
|
|
from PyQt5 import QtWidgets
|
|
|
|
|
2013-10-13 20:36:42 +00:00
|
|
|
from openlp.core.common import Settings
|
2013-04-05 19:37:15 +00:00
|
|
|
from openlp.plugins.remotes.lib.remotetab import RemoteTab
|
2017-04-24 05:17:55 +00:00
|
|
|
|
2014-03-14 22:08:44 +00:00
|
|
|
from tests.helpers.testmixin import TestMixin
|
2013-04-05 19:37:15 +00:00
|
|
|
|
|
|
|
__default_settings__ = {
|
2013-08-31 18:17:38 +00:00
|
|
|
'remotes/twelve hour': True,
|
|
|
|
'remotes/port': 4316,
|
|
|
|
'remotes/user id': 'openlp',
|
|
|
|
'remotes/password': 'password',
|
|
|
|
'remotes/authentication enabled': False,
|
2014-08-25 20:04:33 +00:00
|
|
|
'remotes/ip address': '0.0.0.0',
|
2014-08-25 20:31:35 +00:00
|
|
|
'remotes/thumbnails': True
|
2013-04-05 19:37:15 +00:00
|
|
|
}
|
2013-08-31 18:17:38 +00:00
|
|
|
ZERO_URL = '0.0.0.0'
|
|
|
|
TEST_PATH = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..', 'resources'))
|
2013-04-05 19:37:15 +00:00
|
|
|
|
|
|
|
|
2014-03-14 22:08:44 +00:00
|
|
|
class TestRemoteTab(TestCase, TestMixin):
|
2013-04-05 19:37:15 +00:00
|
|
|
"""
|
|
|
|
Test the functions in the :mod:`lib` module.
|
|
|
|
"""
|
|
|
|
def setUp(self):
|
|
|
|
"""
|
|
|
|
Create the UI
|
|
|
|
"""
|
2014-10-22 20:43:05 +00:00
|
|
|
self.setup_application()
|
2014-03-14 22:08:44 +00:00
|
|
|
self.build_settings()
|
2013-04-05 19:37:15 +00:00
|
|
|
Settings().extend_default_settings(__default_settings__)
|
2015-11-07 00:49:40 +00:00
|
|
|
self.parent = QtWidgets.QMainWindow()
|
2013-08-31 18:17:38 +00:00
|
|
|
self.form = RemoteTab(self.parent, 'Remotes', None, None)
|
2013-04-05 19:37:15 +00:00
|
|
|
|
|
|
|
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
|
2014-03-14 22:08:44 +00:00
|
|
|
self.destroy_settings()
|
2013-04-05 19:37:15 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_get_ip_address_default(self):
|
2013-09-08 16:16:18 +00:00
|
|
|
"""
|
|
|
|
Test the get_ip_address function with ZERO_URL
|
|
|
|
"""
|
2013-09-08 16:24:21 +00:00
|
|
|
# WHEN: the default ip address is given
|
|
|
|
ip_address = self.form.get_ip_address(ZERO_URL)
|
|
|
|
# THEN: the default ip address will be returned
|
2013-09-19 21:02:28 +00:00
|
|
|
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')
|
2013-09-08 16:16:18 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_get_ip_address_with_ip(self):
|
2013-09-08 16:16:18 +00:00
|
|
|
"""
|
|
|
|
Test the get_ip_address function with given ip address
|
|
|
|
"""
|
2013-09-08 16:24:21 +00:00
|
|
|
# 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)
|
2013-09-08 16:16:18 +00:00
|
|
|
|
2016-05-31 21:40:13 +00:00
|
|
|
def test_set_basic_urls(self):
|
2013-04-05 19:37:15 +00:00
|
|
|
"""
|
|
|
|
Test the set_urls function with standard defaults
|
|
|
|
"""
|
|
|
|
# GIVEN: A mocked location
|
2013-10-13 20:36:42 +00:00
|
|
|
with patch('openlp.core.common.Settings') as mocked_class, \
|
2016-04-04 21:19:37 +00:00
|
|
|
patch('openlp.core.common.applocation.AppLocation.get_directory') as mocked_get_directory, \
|
2013-10-13 17:23:52 +00:00
|
|
|
patch('openlp.core.common.check_directory_exists') as mocked_check_directory_exists, \
|
2013-10-13 13:51:13 +00:00
|
|
|
patch('openlp.core.common.applocation.os') as mocked_os:
|
2013-04-05 19:37:15 +00:00
|
|
|
# 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
|
2013-08-31 18:17:38 +00:00
|
|
|
mocked_get_directory.return_value = 'test/dir'
|
2013-04-05 19:37:15 +00:00
|
|
|
mocked_check_directory_exists.return_value = True
|
2013-08-31 18:17:38 +00:00
|
|
|
mocked_os.path.normpath.return_value = 'test/dir'
|
2013-04-05 19:37:15 +00:00
|
|
|
|
|
|
|
# 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
|
2013-08-31 18:17:38 +00:00
|
|
|
self.assertEqual(self.form.address_edit.text(), ZERO_URL, 'The default URL should be set on the screen')
|
2013-04-05 19:37:15 +00:00
|
|
|
self.assertEqual(self.form.user_login_group_box.isChecked(), False,
|
2013-08-31 18:17:38 +00:00
|
|
|
'The authentication box should not be enabled')
|
2013-04-05 19:37:15 +00:00
|
|
|
|
2017-03-04 16:51:51 +00:00
|
|
|
def test_set_urls(self):
|
2013-04-05 19:37:15 +00:00
|
|
|
"""
|
2017-03-04 16:51:51 +00:00
|
|
|
Test the set_url function to generate correct url links
|
2013-04-05 19:37:15 +00:00
|
|
|
"""
|
2017-03-04 16:51:51 +00:00
|
|
|
# GIVEN: An ip address
|
|
|
|
self.form.address_edit.setText('192.168.1.1')
|
|
|
|
# WHEN: the urls are generated
|
|
|
|
self.form.set_urls()
|
|
|
|
# THEN: the following links are returned
|
|
|
|
self.assertEqual(self.form.remote_url.text(),
|
|
|
|
"<a href=\"http://192.168.1.1:4316/\">http://192.168.1.1:4316/</a>",
|
|
|
|
'The return value should be a fully formed link')
|
|
|
|
self.assertEqual(self.form.stage_url.text(),
|
|
|
|
"<a href=\"http://192.168.1.1:4316/stage\">http://192.168.1.1:4316/stage</a>",
|
|
|
|
'The return value should be a fully formed stage link')
|
|
|
|
self.assertEqual(self.form.live_url.text(),
|
|
|
|
"<a href=\"http://192.168.1.1:4316/main\">http://192.168.1.1:4316/main</a>",
|
|
|
|
'The return value should be a fully formed main link')
|