← Back to team overview

openlp-core team mailing list archive

[Merge] lp:~oliwee/openlp/urlfix into lp:openlp

 

Oliver Wieland has proposed merging lp:~oliwee/openlp/urlfix into lp:openlp.

Requested reviews:
  Oliver Wieland (oliwee)
  Andreas Preikschat (googol)

For more details, see:
https://code.launchpad.net/~oliwee/openlp/urlfix/+merge/184615

fixes wrong url on the remotes tab
separates  determination of the local ip address for easier testing
-- 
https://code.launchpad.net/~oliwee/openlp/urlfix/+merge/184615
Your team OpenLP Core is subscribed to branch lp:openlp.
=== modified file 'openlp/plugins/remotes/lib/remotetab.py'
--- openlp/plugins/remotes/lib/remotetab.py	2013-08-31 18:17:38 +0000
+++ openlp/plugins/remotes/lib/remotetab.py	2013-09-09 16:34:30 +0000
@@ -198,21 +198,7 @@
         """
         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
-                        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('<a href="%s">%s</a>' % (http_url, http_url))
@@ -226,6 +212,25 @@
         self.live_url.setText('<a href="%s">%s</a>' % (http_url_temp, http_url_temp))
         self.live_https_url.setText('<a href="%s">%s</a>' % (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:
+                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() == QtNetwork.QAbstractSocket.IPv4Protocol and ip != QtNetwork.QHostAddress.LocalHost:
+                        return ip.toString()
+        return ip_address
+
     def load(self):
         """
         Load the configuration and update the server configuration if necessary

=== modified file 'tests/functional/openlp_plugins/remotes/test_remotetab.py'
--- tests/functional/openlp_plugins/remotes/test_remotetab.py	2013-08-31 18:17:38 +0000
+++ tests/functional/openlp_plugins/remotes/test_remotetab.py	2013-09-09 16:34:30 +0000
@@ -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,27 @@
         del self.form
         os.unlink(self.ini_file)
 
+    def get_ip_address_default_test(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 get_ip_address_with_ip_test(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 set_basic_urls_test(self):
         """
         Test the set_urls function with standard defaults


References