forked from openlp/openlp
fixes wrong url on the remotes tab
separates determination of the local ip address for easier testing bzr-revno: 2295
This commit is contained in:
commit
00cb7b8adf
@ -198,21 +198,7 @@ class RemoteTab(SettingsTab):
|
|||||||
"""
|
"""
|
||||||
Update the display based on the data input on the screen
|
Update the display based on the data input on the screen
|
||||||
"""
|
"""
|
||||||
ip_address = 'localhost'
|
ip_address = self.get_ip_address(self.address_edit.text())
|
||||||
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()
|
|
||||||
http_url = 'http://%s:%s/' % (ip_address, self.port_spin_box.value())
|
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())
|
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))
|
self.remote_url.setText('<a href="%s">%s</a>' % (http_url, http_url))
|
||||||
@ -226,6 +212,25 @@ class RemoteTab(SettingsTab):
|
|||||||
self.live_url.setText('<a href="%s">%s</a>' % (http_url_temp, http_url_temp))
|
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))
|
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):
|
def load(self):
|
||||||
"""
|
"""
|
||||||
Load the configuration and update the server configuration if necessary
|
Load the configuration and update the server configuration if necessary
|
||||||
|
@ -2,6 +2,7 @@
|
|||||||
This module contains tests for the lib submodule of the Remotes plugin.
|
This module contains tests for the lib submodule of the Remotes plugin.
|
||||||
"""
|
"""
|
||||||
import os
|
import os
|
||||||
|
import re
|
||||||
|
|
||||||
from unittest import TestCase
|
from unittest import TestCase
|
||||||
from tempfile import mkstemp
|
from tempfile import mkstemp
|
||||||
@ -52,6 +53,27 @@ class TestRemoteTab(TestCase):
|
|||||||
del self.form
|
del self.form
|
||||||
os.unlink(self.ini_file)
|
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):
|
def set_basic_urls_test(self):
|
||||||
"""
|
"""
|
||||||
Test the set_urls function with standard defaults
|
Test the set_urls function with standard defaults
|
||||||
|
Loading…
Reference in New Issue
Block a user