summaryrefslogtreecommitdiff
path: root/src/leap/eip
diff options
context:
space:
mode:
authorantialias <antialias@leap.se>2012-09-24 17:34:25 -0400
committerantialias <antialias@leap.se>2012-09-24 17:34:25 -0400
commitddf5e546916ad94c62b1e42b6f03831f906b2f29 (patch)
tree6b284d81d9632819302a028320785339b45a725d /src/leap/eip
parenta5366ebc06a1345f9248672e91cf87379d3bcec1 (diff)
improved network checks on the way to a network checker.
Diffstat (limited to 'src/leap/eip')
-rw-r--r--src/leap/eip/checks.py15
-rw-r--r--src/leap/eip/exceptions.py2
-rw-r--r--src/leap/eip/tests/test_checks.py22
3 files changed, 29 insertions, 10 deletions
diff --git a/src/leap/eip/checks.py b/src/leap/eip/checks.py
index 9b7b1cee..82940fd3 100644
--- a/src/leap/eip/checks.py
+++ b/src/leap/eip/checks.py
@@ -70,21 +70,20 @@ class LeapNetworkChecker(object):
checker.is_internet_up()
checker.ping_gateway()
- def test_internet_connection(self):
- # XXX we're not passing the error anywhere.
- # XXX we probably should raise an exception here?
- # unless we use this as smoke test
+ def check_internet_connection(self):
try:
# XXX remove this hardcoded random ip
requests.get('http://216.172.161.165')
except (requests.HTTPError, requests.RequestException) as e:
- self.error = e.message
- except requests.ConenctionError as e:
+ raise eipexceptions.NoInternetConnection(e.message)
+ except requests.ConnectionError as e:
+ error = "Unidentified Connection Error"
if e.message == "[Errno 113] No route to host":
if not self.is_internet_up():
- self.error = "No valid internet connection found."
+ error = "No valid internet connection found."
else:
- self.error = "Provider server appears to be down."
+ error = "Provider server appears to be down."
+ raise eipexceptions.NoInternetConnection(error)
def is_internet_up(self):
iface, gateway = self.get_default_interface_gateway()
diff --git a/src/leap/eip/exceptions.py b/src/leap/eip/exceptions.py
index f048621f..f883a173 100644
--- a/src/leap/eip/exceptions.py
+++ b/src/leap/eip/exceptions.py
@@ -136,6 +136,8 @@ class NoConnectionToGateway(EIPClientError):
message = "no connection to gateway"
usermessage = "Looks like there are problems with your internet connection"
+class NoInternetConnection(EIPClientError):
+ message = "No Internet connection found"
#
# Errors that probably we don't need anymore
diff --git a/src/leap/eip/tests/test_checks.py b/src/leap/eip/tests/test_checks.py
index 19b54c04..f412dbec 100644
--- a/src/leap/eip/tests/test_checks.py
+++ b/src/leap/eip/tests/test_checks.py
@@ -52,7 +52,7 @@ class LeapNetworkCheckTest(BaseLeapTest):
def test_checker_should_implement_check_methods(self):
checker = eipchecks.LeapNetworkChecker()
- self.assertTrue(hasattr(checker, "test_internet_connection"),
+ self.assertTrue(hasattr(checker, "check_internet_connection"),
"missing meth")
self.assertTrue(hasattr(checker, "is_internet_up"),
"missing meth")
@@ -64,7 +64,7 @@ class LeapNetworkCheckTest(BaseLeapTest):
mc = Mock()
checker.run_all(checker=mc)
- self.assertTrue(mc.test_internet_connection.called, "not called")
+ self.assertTrue(mc.check_internet_connection.called, "not called")
self.assertTrue(mc.ping_gateway.called, "not called")
self.assertTrue(mc.is_internet_up.called,
"not called")
@@ -86,6 +86,24 @@ class LeapNetworkCheckTest(BaseLeapTest):
mocked_ping.return_value = [11, "", ""]
checker.ping_gateway("4.2.2.2")
+ def test_check_internet_connection_failures(self):
+ checker = eipchecks.LeapNetworkChecker()
+ with patch.object(requests, "get") as mocked_get:
+ mocked_get.side_effect = requests.HTTPError
+ with self.assertRaises(eipexceptions.NoInternetConnection):
+ checker.check_internet_connection()
+
+ with patch.object(requests, "get") as mocked_get:
+ mocked_get.side_effect = requests.RequestException
+ with self.assertRaises(eipexceptions.NoInternetConnection):
+ checker.check_internet_connection()
+
+ #TODO: Mock possible errors that can be raised by is_internet_up
+ with patch.object(requests, "get") as mocked_get:
+ mocked_get.side_effect = requests.ConnectionError
+ with self.assertRaises(eipexceptions.NoInternetConnection):
+ checker.check_internet_connection()
+
@unittest.skipUnless(_uid == 0, "root only")
def test_ping_gateway(self):
checker = eipchecks.LeapNetworkChecker()