3 # Copyright (c) 2017 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
10 # pylint: disable=missing-docstring
17 from functest.core import feature
18 from functest.core import testcase
19 from functest.utils import constants
22 class FeatureInitTesting(unittest.TestCase):
24 logging.disable(logging.CRITICAL)
26 @unittest.skip("JIRA: FUNCTEST-780")
27 def test_init_with_wrong_repo(self):
28 with self.assertRaises(ValueError):
29 feature.Feature(repo='foo')
32 barometer = feature.Feature(repo='dir_repo_barometer')
33 self.assertEqual(barometer.project_name, "functest")
34 self.assertEqual(barometer.case_name, "")
37 constants.CONST.__getattribute__('dir_repo_barometer'))
40 class FeatureTesting(unittest.TestCase):
42 logging.disable(logging.CRITICAL)
45 self.feature = feature.Feature(repo='dir_repo_barometer')
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()
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()
65 @unittest.skip("JIRA: FUNCTEST-781")
66 def test_post_ko(self):
67 # pylint: disable=bad-continuation
68 with mock.patch.object(
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()
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()
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()
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()
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()
107 if __name__ == "__main__":
108 unittest.main(verbosity=2)