Reverted the file permission
[functest-xtesting.git] / functest / tests / unit / utils / test_utils.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2016 Orange and others.
4 #
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
9
10 import logging
11 import mock
12 import unittest
13 import urllib2
14
15 from functest.utils import functest_utils
16
17
18 class FunctestUtilsTesting(unittest.TestCase):
19
20     logging.disable(logging.CRITICAL)
21
22     def setUp(self):
23         self.url = 'http://www.opnfv.org/'
24         self.timeout = 5
25
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)
31
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)
36
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)
42
43
44 if __name__ == "__main__":
45     unittest.main(verbosity=2)