openlp/tests/functional/openlp_core/api/test_tab.py

122 lines
4.9 KiB
Python
Raw Normal View History

2016-07-10 06:25:25 +00:00
# -*- coding: utf-8 -*-
# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4
###############################################################################
# OpenLP - Open Source Lyrics Projection #
# --------------------------------------------------------------------------- #
2019-02-14 15:09:09 +00:00
# Copyright (c) 2008-2019 OpenLP Developers #
2016-07-10 06:25:25 +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 #
###############################################################################
"""
This module contains tests for the lib submodule of the Remotes plugin.
"""
import re
from unittest import TestCase
from PyQt5 import QtWidgets
2017-12-28 08:22:55 +00:00
from openlp.core.api.tab import ApiTab
from openlp.core.common import get_local_ip4
2017-10-07 07:05:07 +00:00
from openlp.core.common.registry import Registry
from openlp.core.common.settings import Settings
2016-07-10 06:25:25 +00:00
from tests.helpers.testmixin import TestMixin
2018-10-02 04:39:42 +00:00
2016-07-10 06:25:25 +00:00
__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',
2017-08-12 19:39:08 +00:00
'api/thumbnails': True,
'remotes/download version': '0000_00_00'
2016-07-10 06:25:25 +00:00
}
ZERO_URL = '0.0.0.0'
class TestApiTab(TestCase, TestMixin):
"""
Test the functions in the :mod:`lib` module.
"""
2018-06-26 19:44:54 +00:00
def setUp(self):
2016-07-10 06:25:25 +00:00
"""
Create the UI
"""
self.setup_application()
self.build_settings()
Settings().extend_default_settings(__default_settings__)
self.parent = QtWidgets.QMainWindow()
2017-08-12 20:03:17 +00:00
Registry().create()
2017-08-12 19:56:02 +00:00
Registry().set_flag('website_version', '00-00-0000')
2017-08-12 20:03:17 +00:00
self.form = ApiTab(self.parent)
self.my_ip4_list = get_local_ip4()
2016-07-10 06:25:25 +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
self.destroy_settings()
def test_get_ip_address_default(self):
"""
Test the get_ip_address function with ZERO_URL
"""
# GIVEN: list of local IP addresses for this machine
ip4_list = []
for ip4 in iter(self.my_ip4_list):
ip4_list.append(self.my_ip4_list.get(ip4)['ip'])
2016-07-10 06:25:25 +00:00
# WHEN: the default ip address is given
ip_address = self.form.get_ip_address(ZERO_URL)
2018-02-11 11:42:13 +00:00
2016-07-10 06:25:25 +00:00
# THEN: the default ip address will be returned
2018-07-02 20:38:47 +00:00
assert re.match(r'\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}', ip_address), \
2017-12-09 15:21:59 +00:00
'The return value should be a valid ip address'
assert ip_address in ip4_list, 'The return address should be in the list of local IP addresses'
2016-07-10 06:25:25 +00:00
def test_get_ip_address_with_ip(self):
"""
Test the get_ip_address function with given ip address
"""
# GIVEN: An ip address
given_ip = '192.168.1.1'
2018-02-11 11:42:13 +00:00
2016-07-10 06:25:25 +00:00
# WHEN: the default ip address is given
ip_address = self.form.get_ip_address(given_ip)
2018-02-11 11:42:13 +00:00
2016-07-10 06:25:25 +00:00
# THEN: the default ip address will be returned
2017-12-09 15:21:59 +00:00
assert ip_address == given_ip, 'The return value should be %s' % given_ip
2016-07-10 06:25:25 +00:00
2017-03-04 19:24:44 +00:00
def test_set_urls(self):
"""
Test the set_url function to generate correct url links
"""
# 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
2017-12-09 15:21:59 +00:00
assert 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'
assert 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'
assert 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'