Add unit tests for doctor
[functest.git] / functest / tests / unit / features / test_barometer.py
1 #!/usr/bin/env python
2
3 # Copyright (c) 2017 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 # pylint: disable=missing-docstring
11
12 import logging
13 import sys
14 import unittest
15
16 import mock
17
18 from functest.core import testcase
19 sys.modules['baro_tests'] = mock.Mock()  # noqa
20 # pylint: disable=wrong-import-position
21 from functest.opnfv_tests.features import barometer
22 from functest.utils import constants
23
24
25 class BarometerTesting(unittest.TestCase):
26
27     logging.disable(logging.CRITICAL)
28
29     def setUp(self):
30         self.barometer = barometer.BarometerCollectd()
31
32     def test_init(self):
33         self.assertEqual(self.barometer.project_name, "barometer")
34         self.assertEqual(self.barometer.case_name, "barometercollectd")
35         self.assertEqual(
36             self.barometer.repo,
37             constants.CONST.__getattribute__('dir_repo_barometer'))
38
39     @unittest.skip("JIRA: FUNCTEST-777")
40     def test_execute_ko(self):
41         # It must be skipped to allow merging
42         sys.modules['baro_tests'].collectd.main = mock.Mock(return_value=1)
43         self.assertEqual(self.barometer.execute(),
44                          testcase.TestCase.EX_RUN_ERROR)
45
46     @unittest.skip("JIRA: FUNCTEST-777")
47     def test_execute(self):
48         # It must be skipped to allow merging
49         sys.modules['baro_tests'].collectd.main = mock.Mock(return_value=0)
50         self.assertEqual(self.barometer.execute(), testcase.TestCase.EX_OK)
51
52
53 if __name__ == "__main__":
54     unittest.main(verbosity=2)