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
20 logging.disable(logging.CRITICAL)
23 class FeatureTestingBase(unittest.TestCase):
27 _repo = "dir_repo_copper"
28 _cmd = "cd /home/opnfv/repos/foo/tests && bash run.sh && cd -"
29 _output_file = '/home/opnfv/functest/results/bar.log'
31 @mock.patch('time.time', side_effect=[1, 2])
32 def _test_run(self, status, mock_method=None):
33 self.assertEqual(self.feature.run(), status)
34 if status == testcase.TestCase.EX_OK:
35 self.assertEqual(self.feature.criteria, 'PASS')
37 self.assertEqual(self.feature.criteria, 'FAIL')
38 mock_method.assert_has_calls([mock.call(), mock.call()])
39 self.assertEqual(self.feature.start_time, 1)
40 self.assertEqual(self.feature.stop_time, 2)
43 class FeatureTesting(FeatureTestingBase):
46 self.feature = feature.Feature(
47 project_name=self._project_name, case_name=self._case_name,
51 self._test_run(testcase.TestCase.EX_RUN_ERROR)
54 class BashFeatureTesting(FeatureTestingBase):
57 self.feature = feature.BashFeature(
58 project_name=self._project_name, case_name=self._case_name,
61 @mock.patch("functest.utils.functest_utils.execute_command",
63 def test_run_ko(self, mock_method=None):
64 self._test_run(testcase.TestCase.EX_RUN_ERROR)
65 mock_method.assert_called_once_with(
66 self._cmd, output_file=self._output_file)
68 @mock.patch("functest.utils.functest_utils.execute_command",
69 side_effect=Exception)
70 def test_run_exc(self, mock_method=None):
71 self._test_run(testcase.TestCase.EX_RUN_ERROR)
72 mock_method.assert_called_once_with(
73 self._cmd, output_file=self._output_file)
75 @mock.patch("functest.utils.functest_utils.execute_command",
77 def test_run(self, mock_method):
78 self._test_run(testcase.TestCase.EX_OK)
79 mock_method.assert_called_once_with(
80 self._cmd, output_file=self._output_file)
83 if __name__ == "__main__":
84 unittest.main(verbosity=2)