3 # Copyright (c) 2016 Orange and others.
5 # All rights reserved. This program and the accompanying materials
6 # are made available under the terms of the Apache License, Version 2.0
7 # which accompanies this distribution, and is available at
8 # http://www.apache.org/licenses/LICENSE-2.0
15 from functest.utils import functest_utils
18 class FunctestUtilsTesting(unittest.TestCase):
20 logging.disable(logging.CRITICAL)
23 self.url = 'http://www.opnfv.org/'
26 @mock.patch('urllib2.urlopen',
27 side_effect=urllib2.URLError('no host given'))
28 def test_check_internet_connectivity_failed(self, mock_method):
29 self.assertFalse(functest_utils.check_internet_connectivity())
30 mock_method.assert_called_once_with(self.url, timeout=self.timeout)
32 @mock.patch('urllib2.urlopen')
33 def test_check_internet_connectivity_default(self, mock_method):
34 self.assertTrue(functest_utils.check_internet_connectivity())
35 mock_method.assert_called_once_with(self.url, timeout=self.timeout)
37 @mock.patch('urllib2.urlopen')
38 def test_check_internet_connectivity_debian(self, mock_method):
39 self.url = "https://www.debian.org/"
40 self.assertTrue(functest_utils.check_internet_connectivity(self.url))
41 mock_method.assert_called_once_with(self.url, timeout=self.timeout)
44 if __name__ == "__main__":
45 unittest.main(verbosity=2)