Ken Roberts has proposed merging lp:~alisonken1/openlp/pjlink2-t into lp:openlp.
Commit message: PJLink Update T Requested reviews: OpenLP Core (openlp-core) For more details, see: https://code.launchpad.net/~alisonken1/openlp/pjlink2-t/+merge/353593 - Move tests/functional/openlp_core/common/test_networkinterfaces.py to tests/openlp_core/common - Minor cleanups in openlp.core.common.__init__.get_local_ip4() - Add more get_local_ip4 tests - Add missing __init__.py files in projector test directories -------------------------------------------------------------------------------- lp:~alisonken1/openlp/pjlink2-t (revision 2829) https://ci.openlp.io/job/Branch-01-Pull/2568/ [SUCCESS] https://ci.openlp.io/job/Branch-02a-Linux-Tests/2466/ [SUCCESS] https://ci.openlp.io/job/Branch-02b-macOS-Tests/247/ [FAILURE] https://ci.openlp.io/job/Branch-03a-Build-Source/154/ [SUCCESS] https://ci.openlp.io/job/Branch-03b-Build-macOS/139/ [SUCCESS] https://ci.openlp.io/job/Branch-04a-Code-Analysis/1616/ [SUCCESS] https://ci.openlp.io/job/Branch-04b-Test-Coverage/1429/ [SUCCESS] https://ci.openlp.io/job/Branch-05-AppVeyor-Tests/333/ [FAILURE] -- Your team OpenLP Core is requested to review the proposed merge of lp:~alisonken1/openlp/pjlink2-t into lp:openlp.
=== modified file 'openlp/core/common/__init__.py' --- openlp/core/common/__init__.py 2018-08-03 22:32:32 +0000 +++ openlp/core/common/__init__.py 2018-08-22 18:09:46 +0000 @@ -60,7 +60,6 @@ :returns: Dict of interfaces """ - # Get the local IPv4 active address(es) that are NOT localhost (lo or '127.0.0.1') log.debug('Getting local IPv4 interface(es) information') my_ip4 = {} for iface in QNetworkInterface.allInterfaces(): @@ -70,8 +69,6 @@ log.debug('Checking address(es) protocol') for address in iface.addressEntries(): ip = address.ip() - # NOTE: Next line will skip if interface is localhost - keep for now until we decide about it later - # if (ip.protocol() == QAbstractSocket.IPv4Protocol) and (ip != QHostAddress.LocalHost): log.debug('Checking for protocol == IPv4Protocol') if ip.protocol() == QAbstractSocket.IPv4Protocol: log.debug('Getting interface information') @@ -83,12 +80,13 @@ ip.toIPv4Address()).toString() } log.debug('Adding {iface} to active list'.format(iface=iface.name())) + if len(my_ip4) == 0: + log.warning('No active IPv4 network interfaces detected') + return my_ip4 if 'localhost' in my_ip4: log.debug('Renaming windows localhost to lo') my_ip4['lo'] = my_ip4['localhost'] my_ip4.pop('localhost') - if len(my_ip4) == 0: - log.warning('No active IPv4 network interfaces detected') if len(my_ip4) == 1: if 'lo' in my_ip4: # No active interfaces - so leave localhost in there === added directory 'tests/openlp_core/common' === added file 'tests/openlp_core/common/__init__.py' --- tests/openlp_core/common/__init__.py 1970-01-01 00:00:00 +0000 +++ tests/openlp_core/common/__init__.py 2018-08-22 18:09:46 +0000 @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2018 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 # +############################################################################### +""" +:mod tests/openlp_core/common: Tests for openlp.core.common +""" === renamed file 'tests/functional/openlp_core/common/test_network_interfaces.py' => 'tests/openlp_core/common/test_network_interfaces.py' --- tests/functional/openlp_core/common/test_network_interfaces.py 2018-08-03 22:32:32 +0000 +++ tests/openlp_core/common/test_network_interfaces.py 2018-08-22 18:09:46 +0000 @@ -23,21 +23,61 @@ Functional tests to test calls for network interfaces. """ from unittest import TestCase -from unittest.mock import MagicMock, call, patch +from unittest.mock import call, patch +from PyQt5.QtCore import QObject +from PyQt5.QtNetwork import QHostAddress, QNetworkAddressEntry, QNetworkInterface import openlp.core.common from openlp.core.common import get_local_ip4 from tests.helpers.testmixin import TestMixin -lo_address_attrs = {'isValid.return_value': True, - 'flags.return_value': True, - 'InterfaceFlags.return_value': True, - 'name.return_value': 'lo', - 'broadcast.toString.return_value': '127.0.0.255', - 'netmask.toString.return_value': '255.0.0.0', - 'prefixLength.return_value': 8, - 'ip.protocol.return_value': True} + +class FakeIP4InterfaceEntry(QObject): + """ + Class to face an interface for testing purposes + """ + def __init__(self, name='lo'): + self.my_name = name + if name in ['localhost', 'lo']: + self.my_ip = QNetworkAddressEntry() + self.my_ip.setBroadcast(QHostAddress('255.0.0.0')) + self.my_ip.setIp(QHostAddress('127.0.0.2')) + self.my_ip.setPrefixLength(8) + self.fake_data = {'lo': {'ip': '127.0.0.2', + 'broadcast': '255.0.0.0', + 'netmask': '255.0.0.0', + 'prefix': 8, + 'localnet': '127.0.0.0'}} + else: + # Define a fake real address + self.my_ip = QNetworkAddressEntry() + self.my_ip.setBroadcast(QHostAddress('255.255.255.0')) + self.my_ip.setIp(QHostAddress('127.254.0.2')) + self.my_ip.setPrefixLength(24) + self.fake_data = {self.my_name: {'ip': '127.254.0.2', + 'broadcast': '255.255.255.0', + 'netmask': '255.255.255.0', + 'prefix': 24, + 'localnet': '127.254.0.0'}} + + def addressEntries(self): + """ + Return fake IP address + """ + return [self.my_ip] + + def flags(self): + """ + Return a QFlags enum with IsUp and IsRunning + """ + return (QNetworkInterface.IsUp | QNetworkInterface.IsRunning) + + def name(self): + return self.my_name + + def isValid(self): + return True class TestInterfaces(TestCase, TestMixin): @@ -49,9 +89,11 @@ Create an instance and a few example actions. """ self.build_settings() - - self.ip4_lo_address = MagicMock() - self.ip4_lo_address.configure_mock(**lo_address_attrs) + if not hasattr(self, 'fake_lo'): + # Since these shouldn't change, only need to instantiate them the first time + self.fake_lo = FakeIP4InterfaceEntry() + self.fake_localhost = FakeIP4InterfaceEntry(name='localhost') + self.fake_address = FakeIP4InterfaceEntry(name='eth25') def tearDown(self): """ @@ -65,14 +107,118 @@ Test no interfaces available """ # GIVEN: Test environment + call_debug = [call('Getting local IPv4 interface(es) information')] call_warning = [call('No active IPv4 network interfaces detected')] - with patch('openlp.core.common.QNetworkInterface') as mock_newtork_interface: - mock_newtork_interface.allInterfaces.return_value = [] - - # WHEN: get_local_ip4 is called - ifaces = get_local_ip4() - - # THEN: There should not be any interfaces detected - assert not ifaces, 'There should have been no active interfaces' - mock_log.warning.assert_has_calls(call_warning) + # WHEN: get_local_ip4 is called + with patch('openlp.core.common.QNetworkInterface') as mock_network_interface: + mock_network_interface.allInterfaces.return_value = [] + ifaces = get_local_ip4() + + # THEN: There should not be any interfaces detected + mock_log.debug.assert_has_calls(call_debug) + mock_log.warning.assert_has_calls(call_warning) + assert not ifaces, 'There should have been no active interfaces listed' + + @patch.object(openlp.core.common, 'log') + def test_ip4_lo(self, mock_log): + """ + Test get_local_ip4 returns proper dictionary with 'lo' + """ + # GIVEN: Test environment + call_debug = [call('Getting local IPv4 interface(es) information'), + call('Checking for isValid and flags == IsUP | IsRunning'), + call('Checking address(es) protocol'), + call('Checking for protocol == IPv4Protocol'), + call('Getting interface information'), + call('Adding lo to active list')] + call_warning = [call('No active IPv4 interfaces found except localhost')] + + # WHEN: get_local_ip4 is called + with patch('openlp.core.common.QNetworkInterface') as mock_network_interface: + mock_network_interface.allInterfaces.return_value = [self.fake_lo] + ifaces = get_local_ip4() + + # THEN: There should be a fake 'lo' interface + mock_log.debug.assert_has_calls(call_debug) + mock_log.warning.assert_has_calls(call_warning) + assert ifaces == self.fake_lo.fake_data, "There should have been an 'lo' interface listed" + + @patch.object(openlp.core.common, 'log') + def test_ip4_localhost(self, mock_log): + """ + Test get_local_ip4 returns proper dictionary with 'lo' if interface is 'localhost' + """ + # GIVEN: Test environment + call_debug = [call('Getting local IPv4 interface(es) information'), + call('Checking for isValid and flags == IsUP | IsRunning'), + call('Checking address(es) protocol'), + call('Checking for protocol == IPv4Protocol'), + call('Getting interface information'), + call('Adding localhost to active list'), + call('Renaming windows localhost to lo')] + call_warning = [call('No active IPv4 interfaces found except localhost')] + + # WHEN: get_local_ip4 is called + with patch('openlp.core.common.QNetworkInterface') as mock_network_interface: + mock_network_interface.allInterfaces.return_value = [self.fake_localhost] + ifaces = get_local_ip4() + + # THEN: There should be a fake 'lo' interface + mock_log.debug.assert_has_calls(call_debug) + mock_log.warning.assert_has_calls(call_warning) + assert ifaces == self.fake_lo.fake_data, "There should have been an 'lo' interface listed" + + @patch.object(openlp.core.common, 'log') + def test_ip4_eth25(self, mock_log): + """ + Test get_local_ip4 returns proper dictionary with 'eth25' + """ + # GIVEN: Test environment + call_debug = [call('Getting local IPv4 interface(es) information'), + call('Checking for isValid and flags == IsUP | IsRunning'), + call('Checking address(es) protocol'), + call('Checking for protocol == IPv4Protocol'), + call('Getting interface information'), + call('Adding eth25 to active list')] + call_warning = [] + + # WHEN: get_local_ip4 is called + with patch('openlp.core.common.QNetworkInterface') as mock_network_interface: + mock_network_interface.allInterfaces.return_value = [self.fake_address] + ifaces = get_local_ip4() + + # THEN: There should be a fake 'eth25' interface + mock_log.debug.assert_has_calls(call_debug) + mock_log.warning.assert_has_calls(call_warning) + assert ifaces == self.fake_address.fake_data + + @patch.object(openlp.core.common, 'log') + def test_ip4_lo_eth25(self, mock_log): + """ + Test get_local_ip4 returns proper dictionary with 'eth25' + """ + # GIVEN: Test environment + call_debug = [call('Getting local IPv4 interface(es) information'), + call('Checking for isValid and flags == IsUP | IsRunning'), + call('Checking address(es) protocol'), + call('Checking for protocol == IPv4Protocol'), + call('Getting interface information'), + call('Adding lo to active list'), + call('Checking for isValid and flags == IsUP | IsRunning'), + call('Checking address(es) protocol'), + call('Checking for protocol == IPv4Protocol'), + call('Getting interface information'), + call('Adding eth25 to active list'), + call('Found at least one IPv4 interface, removing localhost')] + call_warning = [] + + # WHEN: get_local_ip4 is called + with patch('openlp.core.common.QNetworkInterface') as mock_network_interface: + mock_network_interface.allInterfaces.return_value = [self.fake_lo, self.fake_address] + ifaces = get_local_ip4() + + # THEN: There should be a fake 'eth25' interface + mock_log.debug.assert_has_calls(call_debug) + mock_log.warning.assert_has_calls(call_warning) + assert ifaces == self.fake_address.fake_data, "There should have been only 'eth25' interface listed" === modified file 'tests/openlp_core/projectors/__init__.py' --- tests/openlp_core/projectors/__init__.py 2018-02-11 11:42:13 +0000 +++ tests/openlp_core/projectors/__init__.py 2018-08-22 18:09:46 +0000 @@ -4,7 +4,7 @@ ############################################################################### # OpenLP - Open Source Lyrics Projection # # --------------------------------------------------------------------------- # -# Copyright (c) 2008-2017 OpenLP Developers # +# Copyright (c) 2008-2018 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 # @@ -20,5 +20,5 @@ # Temple Place, Suite 330, Boston, MA 02111-1307 USA # ############################################################################### """ -Module-level functions for the projector test suite +:mod tests/openlp_core/projectors: Tests for projector code """ === added file 'tests/resources/__init__.py' --- tests/resources/__init__.py 1970-01-01 00:00:00 +0000 +++ tests/resources/__init__.py 2018-08-22 18:09:46 +0000 @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2018 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 # +############################################################################### +""" +:mod resources: Resources for OpenLP tests +""" === added file 'tests/resources/projector/__init__.py' --- tests/resources/projector/__init__.py 1970-01-01 00:00:00 +0000 +++ tests/resources/projector/__init__.py 2018-08-22 18:09:46 +0000 @@ -0,0 +1,24 @@ +# -*- coding: utf-8 -*- +# vim: autoindent shiftwidth=4 expandtab textwidth=120 tabstop=4 softtabstop=4 + +############################################################################### +# OpenLP - Open Source Lyrics Projection # +# --------------------------------------------------------------------------- # +# Copyright (c) 2008-2018 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 # +############################################################################### +""" +:mod resources/projector: Resources for projector tests +"""
_______________________________________________ Mailing list: https://launchpad.net/~openlp-core Post to : openlp-core@lists.launchpad.net Unsubscribe : https://launchpad.net/~openlp-core More help : https://help.launchpad.net/ListHelp