From 5406a44d5977f45647bd02f01e736793b62acdef Mon Sep 17 00:00:00 2001 From: Oliver Wieland Date: Sun, 8 Sep 2013 11:29:36 +0200 Subject: [PATCH 1/7] fixes wrong url on the remotes tab --- openlp/plugins/remotes/lib/remotetab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/remotes/lib/remotetab.py b/openlp/plugins/remotes/lib/remotetab.py index 338abc4a0..b9c71f338 100644 --- a/openlp/plugins/remotes/lib/remotetab.py +++ b/openlp/plugins/remotes/lib/remotetab.py @@ -209,7 +209,7 @@ class RemoteTab(SettingsTab): for address in interface.addressEntries(): ip = address.ip() if ip.protocol() == 0 and ip != QtNetwork.QHostAddress.LocalHost: - ip_address = ip + ip_address = ip.toString() break else: ip_address = self.address_edit.text() From 2aeaa24871416c0df9772ba8f245c6add38ff977 Mon Sep 17 00:00:00 2001 From: Oliver Wieland Date: Sun, 8 Sep 2013 18:16:18 +0200 Subject: [PATCH 2/7] remotetab.py: separate get ip address for metter testing test_remotetab.py:tests for get_ip_address --- openlp/plugins/remotes/lib/remotetab.py | 30 ++++++++--------- .../openlp_plugins/remotes/test_remotetab.py | 33 ++++++++++++++++++- 2 files changed, 47 insertions(+), 16 deletions(-) diff --git a/openlp/plugins/remotes/lib/remotetab.py b/openlp/plugins/remotes/lib/remotetab.py index b9c71f338..b84faf7bd 100644 --- a/openlp/plugins/remotes/lib/remotetab.py +++ b/openlp/plugins/remotes/lib/remotetab.py @@ -198,21 +198,7 @@ class RemoteTab(SettingsTab): """ Update the display based on the data input on the screen """ - ip_address = 'localhost' - if self.address_edit.text() == ZERO_URL: - interfaces = QtNetwork.QNetworkInterface.allInterfaces() - for interface in interfaces: - if not interface.isValid(): - continue - if not (interface.flags() & (QtNetwork.QNetworkInterface.IsUp | QtNetwork.QNetworkInterface.IsRunning)): - continue - for address in interface.addressEntries(): - ip = address.ip() - if ip.protocol() == 0 and ip != QtNetwork.QHostAddress.LocalHost: - ip_address = ip.toString() - break - else: - ip_address = self.address_edit.text() + ip_address = self.get_ip_address(self.address_edit.text()) http_url = 'http://%s:%s/' % (ip_address, self.port_spin_box.value()) https_url = 'https://%s:%s/' % (ip_address, self.https_port_spin_box.value()) self.remote_url.setText('%s' % (http_url, http_url)) @@ -226,6 +212,20 @@ class RemoteTab(SettingsTab): self.live_url.setText('%s' % (http_url_temp, http_url_temp)) self.live_https_url.setText('%s' % (https_url_temp, https_url_temp)) + def get_ip_address(self, ip): + if ip == ZERO_URL: + interfaces = QtNetwork.QNetworkInterface.allInterfaces() + for interface in interfaces: + if not interface.isValid(): + continue + if not (interface.flags() & (QtNetwork.QNetworkInterface.IsUp | QtNetwork.QNetworkInterface.IsRunning)): + continue + for address in interface.addressEntries(): + ip = address.ip() + if ip.protocol() == 0 and ip != QtNetwork.QHostAddress.LocalHost: + return ip.toString() + return ip + def load(self): """ Load the configuration and update the server configuration if necessary diff --git a/tests/functional/openlp_plugins/remotes/test_remotetab.py b/tests/functional/openlp_plugins/remotes/test_remotetab.py index 9ff795e73..81b67dbea 100644 --- a/tests/functional/openlp_plugins/remotes/test_remotetab.py +++ b/tests/functional/openlp_plugins/remotes/test_remotetab.py @@ -2,7 +2,7 @@ This module contains tests for the lib submodule of the Remotes plugin. """ import os - +import re from unittest import TestCase from tempfile import mkstemp from mock import patch @@ -52,6 +52,37 @@ class TestRemoteTab(TestCase): del self.form os.unlink(self.ini_file) + def get_ip_address_default_test(self): + """ + Test the get_ip_address function with ZERO_URL + """ + # GIVEN: A mocked location + with patch('openlp.core.utils.applocation.Settings') as mocked_class, \ + patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ + patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \ + patch('openlp.core.utils.applocation.os') as mocked_os: + # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() + # 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 get_ip_address_with_ip_test(self): + """ + Test the get_ip_address function with given ip address + """ + # GIVEN: A mocked location + with patch('openlp.core.utils.applocation.Settings') as mocked_class, \ + patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ + patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \ + patch('openlp.core.utils.applocation.os') as mocked_os: + # 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 set_basic_urls_test(self): """ Test the set_urls function with standard defaults From 7d4701030492143e6bc94629ddbd30ff226cf39b Mon Sep 17 00:00:00 2001 From: Oliver Wieland Date: Sun, 8 Sep 2013 18:24:21 +0200 Subject: [PATCH 3/7] cleaning tests --- .../openlp_plugins/remotes/test_remotetab.py | 30 +++++++------------ 1 file changed, 10 insertions(+), 20 deletions(-) diff --git a/tests/functional/openlp_plugins/remotes/test_remotetab.py b/tests/functional/openlp_plugins/remotes/test_remotetab.py index 81b67dbea..1ee9a3695 100644 --- a/tests/functional/openlp_plugins/remotes/test_remotetab.py +++ b/tests/functional/openlp_plugins/remotes/test_remotetab.py @@ -56,32 +56,22 @@ class TestRemoteTab(TestCase): """ Test the get_ip_address function with ZERO_URL """ - # GIVEN: A mocked location - with patch('openlp.core.utils.applocation.Settings') as mocked_class, \ - patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ - patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \ - patch('openlp.core.utils.applocation.os') as mocked_os: - # GIVEN: A mocked out Settings class and a mocked out AppLocation.get_directory() - # 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') + # 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 get_ip_address_with_ip_test(self): """ Test the get_ip_address function with given ip address """ # GIVEN: A mocked location - with patch('openlp.core.utils.applocation.Settings') as mocked_class, \ - patch('openlp.core.utils.AppLocation.get_directory') as mocked_get_directory, \ - patch('openlp.core.utils.applocation.check_directory_exists') as mocked_check_directory_exists, \ - patch('openlp.core.utils.applocation.os') as mocked_os: - # 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) + # 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 set_basic_urls_test(self): """ From c0d19ec840fed8d666f76be1101b4a1321855063 Mon Sep 17 00:00:00 2001 From: Oliver Wieland Date: Sun, 8 Sep 2013 18:40:48 +0200 Subject: [PATCH 4/7] rename variable --- openlp/plugins/remotes/lib/remotetab.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/openlp/plugins/remotes/lib/remotetab.py b/openlp/plugins/remotes/lib/remotetab.py index b84faf7bd..e30ad3ea8 100644 --- a/openlp/plugins/remotes/lib/remotetab.py +++ b/openlp/plugins/remotes/lib/remotetab.py @@ -212,8 +212,8 @@ class RemoteTab(SettingsTab): self.live_url.setText('%s' % (http_url_temp, http_url_temp)) self.live_https_url.setText('%s' % (https_url_temp, https_url_temp)) - def get_ip_address(self, ip): - if ip == ZERO_URL: + def get_ip_address(self, ip_address): + if ip_address == ZERO_URL: interfaces = QtNetwork.QNetworkInterface.allInterfaces() for interface in interfaces: if not interface.isValid(): @@ -224,7 +224,7 @@ class RemoteTab(SettingsTab): ip = address.ip() if ip.protocol() == 0 and ip != QtNetwork.QHostAddress.LocalHost: return ip.toString() - return ip + return ip_address def load(self): """ From 86c37481ab4a750207e2de58950e4489532f6158 Mon Sep 17 00:00:00 2001 From: Oliver Wieland Date: Sun, 8 Sep 2013 21:24:53 +0200 Subject: [PATCH 5/7] doc string added --- openlp/plugins/remotes/lib/remotetab.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/openlp/plugins/remotes/lib/remotetab.py b/openlp/plugins/remotes/lib/remotetab.py index e30ad3ea8..b1cf4a803 100644 --- a/openlp/plugins/remotes/lib/remotetab.py +++ b/openlp/plugins/remotes/lib/remotetab.py @@ -213,6 +213,11 @@ class RemoteTab(SettingsTab): self.live_https_url.setText('%s' % (https_url_temp, https_url_temp)) def get_ip_address(self, ip_address): + """ + returns the IP address in dependency of the passed address + ip_address == 0.0.0.0: return the IP address of the first valid interface + else: return ip_address + """ if ip_address == ZERO_URL: interfaces = QtNetwork.QNetworkInterface.allInterfaces() for interface in interfaces: From e5849077188110b2c6d1112ad3277aa2a94658d2 Mon Sep 17 00:00:00 2001 From: Oliver Wieland Date: Mon, 9 Sep 2013 18:32:13 +0200 Subject: [PATCH 6/7] replaced constant value with enum --- openlp/plugins/remotes/lib/remotetab.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/openlp/plugins/remotes/lib/remotetab.py b/openlp/plugins/remotes/lib/remotetab.py index b1cf4a803..c06d71ee9 100644 --- a/openlp/plugins/remotes/lib/remotetab.py +++ b/openlp/plugins/remotes/lib/remotetab.py @@ -227,7 +227,7 @@ class RemoteTab(SettingsTab): continue for address in interface.addressEntries(): ip = address.ip() - if ip.protocol() == 0 and ip != QtNetwork.QHostAddress.LocalHost: + if ip.protocol() == QtNetwork.QAbstractSocket.IPv4Protocol and ip != QtNetwork.QHostAddress.LocalHost: return ip.toString() return ip_address From 1106bca319efca63027fcf07afd0d009535cec98 Mon Sep 17 00:00:00 2001 From: Oliver Wieland Date: Tue, 10 Sep 2013 20:18:53 +0200 Subject: [PATCH 7/7] added blank line --- tests/functional/openlp_plugins/remotes/test_remotetab.py | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/functional/openlp_plugins/remotes/test_remotetab.py b/tests/functional/openlp_plugins/remotes/test_remotetab.py index 1ee9a3695..e683699cd 100644 --- a/tests/functional/openlp_plugins/remotes/test_remotetab.py +++ b/tests/functional/openlp_plugins/remotes/test_remotetab.py @@ -3,6 +3,7 @@ This module contains tests for the lib submodule of the Remotes plugin. """ import os import re + from unittest import TestCase from tempfile import mkstemp from mock import patch