Add unit tests for feature
[functest.git] / functest / tests / unit / core / test_feature.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 unittest
14
15 import mock
16
17 from functest.core import feature
18 from functest.core import testcase
19 from functest.utils import constants
20
21
22 class FeatureInitTesting(unittest.TestCase):
23
24     logging.disable(logging.CRITICAL)
25
26     @unittest.skip("JIRA: FUNCTEST-780")
27     def test_init_with_wrong_repo(self):
28         with self.assertRaises(ValueError):
29             feature.Feature(repo='foo')
30
31     def test_init(self):
32         barometer = feature.Feature(repo='dir_repo_barometer')
33         self.assertEqual(barometer.project_name, "functest")
34         self.assertEqual(barometer.case_name, "")
35         self.assertEqual(
36             barometer.repo,
37             constants.CONST.__getattribute__('dir_repo_barometer'))
38
39
40 class FeatureTesting(unittest.TestCase):
41
42     logging.disable(logging.CRITICAL)
43
44     def setUp(self):
45         self.feature = feature.Feature(repo='dir_repo_barometer')
46
47     @unittest.skip("JIRA: FUNCTEST-781")
48     def test_prepare_ko(self):
49         # pylint: disable=bad-continuation
50         with mock.patch.object(
51                 self.feature, 'prepare',
52                 return_value=testcase.TestCase.EX_RUN_ERROR) as mock_object:
53             self.assertEqual(self.feature.run(),
54                              testcase.TestCase.EX_RUN_ERROR)
55             mock_object.assert_called_once_with()
56
57     @unittest.skip("JIRA: FUNCTEST-781")
58     def test_prepare_exc(self):
59         with mock.patch.object(self.feature, 'prepare',
60                                side_effect=Exception) as mock_object:
61             self.assertEqual(self.feature.run(),
62                              testcase.TestCase.EX_RUN_ERROR)
63             mock_object.assert_called_once_with()
64
65     @unittest.skip("JIRA: FUNCTEST-781")
66     def test_post_ko(self):
67         # pylint: disable=bad-continuation
68         with mock.patch.object(
69                 self.feature, 'post',
70                 return_value=testcase.TestCase.EX_RUN_ERROR) as mock_object:
71             self.assertEqual(self.feature.run(),
72                              testcase.TestCase.EX_RUN_ERROR)
73             mock_object.assert_called_once_with()
74
75     @unittest.skip("JIRA: FUNCTEST-781")
76     def test_post_exc(self):
77         with mock.patch.object(self.feature, 'post',
78                                side_effect=Exception) as mock_object:
79             self.assertEqual(self.feature.run(),
80                              testcase.TestCase.EX_RUN_ERROR)
81             mock_object.assert_called_once_with()
82
83     @unittest.skip("JIRA: FUNCTEST-778")
84     def test_execute_ko(self):
85         with mock.patch.object(self.feature, 'execute',
86                                return_value=1) as mock_object:
87             self.assertEqual(self.feature.run(),
88                              testcase.TestCase.EX_RUN_ERROR)
89             mock_object.assert_called_once_with()
90
91     @unittest.skip("JIRA: FUNCTEST-778")
92     def test_execute_exc(self):
93         with mock.patch.object(self.feature, 'execute',
94                                side_effect=Exception) as mock_object:
95             self.assertEqual(self.feature.run(),
96                              testcase.TestCase.EX_RUN_ERROR)
97             mock_object.assert_called_once_with()
98
99     def test_run(self):
100         with mock.patch.object(self.feature, 'execute',
101                                return_value=0) as mock_object:
102             self.assertEqual(self.feature.run(),
103                              testcase.TestCase.EX_OK)
104             mock_object.assert_called_once_with()
105
106
107 if __name__ == "__main__":
108     unittest.main(verbosity=2)