summaryrefslogtreecommitdiff
path: root/src/leap/eip/tests/test_checks.py
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/tests/test_checks.py
parenta5366ebc06a1345f9248672e91cf87379d3bcec1 (diff)
improved network checks on the way to a network checker.
Diffstat (limited to 'src/leap/eip/tests/test_checks.py')
-rw-r--r--src/leap/eip/tests/test_checks.py22
1 files changed, 20 insertions, 2 deletions
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()