summaryrefslogtreecommitdiff
path: root/src/leap/base
diff options
context:
space:
mode:
authorantialias <antialias@leap.se>2012-11-30 16:28:07 -0500
committerkali <kali@leap.se>2012-12-07 02:18:21 +0900
commit79dc31303f1e2a5449a03b1a6a4bdf291cae52e7 (patch)
tree705c96c5ad1c0fed6a33be94d9d5317fb01fce37 /src/leap/base
parentfa59d347e82e3ddfb758658e15bf8a2d8e3d83b1 (diff)
in leap.base.checks.check_internet_connection modified the order
in which errors are checked and improved test coverage.
Diffstat (limited to 'src/leap/base')
-rw-r--r--src/leap/base/checks.py11
-rw-r--r--src/leap/base/tests/test_checks.py16
2 files changed, 23 insertions, 4 deletions
diff --git a/src/leap/base/checks.py b/src/leap/base/checks.py
index 23446f4a..dc2602c2 100644
--- a/src/leap/base/checks.py
+++ b/src/leap/base/checks.py
@@ -39,9 +39,6 @@ class LeapNetworkChecker(object):
# XXX remove this hardcoded random ip
# ping leap.se or eip provider instead...?
requests.get('http://216.172.161.165')
-
- except (requests.HTTPError, requests.RequestException) as e:
- raise exceptions.NoInternetConnection(e.message)
except requests.ConnectionError as e:
error = "Unidentified Connection Error"
if e.message == "[Errno 113] No route to host":
@@ -51,11 +48,17 @@ class LeapNetworkChecker(object):
error = "Provider server appears to be down."
logger.error(error)
raise exceptions.NoInternetConnection(error)
+ except (requests.HTTPError, requests.RequestException) as e:
+ raise exceptions.NoInternetConnection(e.message)
logger.debug('Network appears to be up.')
def is_internet_up(self):
iface, gateway = self.get_default_interface_gateway()
- self.ping_gateway(self.provider_gateway)
+ try:
+ self.ping_gateway(self.provider_gateway)
+ except exceptions.NoConnectionToGateway:
+ return False
+ return True
def check_tunnel_default_interface(self):
"""
diff --git a/src/leap/base/tests/test_checks.py b/src/leap/base/tests/test_checks.py
index 8d573b1e..272e7053 100644
--- a/src/leap/base/tests/test_checks.py
+++ b/src/leap/base/tests/test_checks.py
@@ -118,6 +118,22 @@ class LeapNetworkCheckTest(BaseLeapTest):
with self.assertRaises(exceptions.NoInternetConnection):
checker.check_internet_connection()
+ with patch.object(requests, "get") as mocked_get:
+ mocked_get.side_effect = \
+ requests.ConnectionError("[Errno 113] No route to host")
+ with self.assertRaises(exceptions.NoInternetConnection):
+ with patch.object(checker, "ping_gateway") as mock_ping:
+ mock_ping.return_value = True
+ checker.check_internet_connection()
+
+ with patch.object(requests, "get") as mocked_get:
+ mocked_get.side_effect = \
+ requests.ConnectionError("[Errno 113] No route to host")
+ with self.assertRaises(exceptions.NoInternetConnection):
+ with patch.object(checker, "ping_gateway") as mock_ping:
+ mock_ping.side_effect = exceptions.NoConnectionToGateway
+ checker.check_internet_connection()
+
@unittest.skipUnless(_uid == 0, "root only")
def test_ping_gateway(self):
checker = checks.LeapNetworkChecker()