forked from openlp/openlp
remotetab.py: separate get ip address for metter testing
test_remotetab.py:tests for get_ip_address
This commit is contained in:
parent
5406a44d59
commit
2aeaa24871
@ -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.toString()
|
|
||||||
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,20 @@ 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):
|
||||||
|
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):
|
def load(self):
|
||||||
"""
|
"""
|
||||||
Load the configuration and update the server configuration if necessary
|
Load the configuration and update the server configuration if necessary
|
||||||
|
@ -2,7 +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
|
||||||
from mock import patch
|
from mock import patch
|
||||||
@ -52,6 +52,37 @@ 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
|
||||||
|
"""
|
||||||
|
# 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):
|
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