3 # Copyright (c) 2016 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 """Define the classe required to fully cover testcase."""
17 from functest.core import testcase
19 __author__ = "Cedric Ollivier <cedric.ollivier@orange.com>"
22 class TestCaseTesting(unittest.TestCase):
24 """The class testing TestCase."""
25 # pylint: disable=missing-docstring
27 logging.disable(logging.CRITICAL)
30 self.test = testcase.TestCase()
31 self.test.project = "functest"
32 self.test.case_name = "base"
33 self.test.start_time = "1"
34 self.test.stop_time = "2"
35 self.test.criteria = "PASS"
36 self.test.details = {"Hello": "World"}
38 def test_run_unimplemented(self):
39 self.assertEqual(self.test.run(),
40 testcase.TestCase.EX_RUN_ERROR)
42 @mock.patch('functest.utils.functest_utils.push_results_to_db',
44 def _test_missing_attribute(self, mock_function=None):
45 self.assertEqual(self.test.push_to_db(),
46 testcase.TestCase.EX_PUSH_TO_DB_ERROR)
47 mock_function.assert_not_called()
49 def test_missing_case_name(self):
50 self.test.case_name = None
51 self._test_missing_attribute()
53 def test_missing_criteria(self):
54 self.test.criteria = None
55 self._test_missing_attribute()
57 def test_missing_start_time(self):
58 self.test.start_time = None
59 self._test_missing_attribute()
61 def test_missing_stop_time(self):
62 self.test.stop_time = None
63 self._test_missing_attribute()
65 @mock.patch('functest.utils.functest_utils.push_results_to_db',
67 def test_missing_details(self, mock_function=None):
68 self.test.details = None
69 self.assertEqual(self.test.push_to_db(),
70 testcase.TestCase.EX_OK)
71 mock_function.assert_called_once_with(
72 self.test.project, self.test.case_name, self.test.start_time,
73 self.test.stop_time, self.test.criteria, self.test.details)
75 @mock.patch('functest.utils.functest_utils.push_results_to_db',
77 def test_push_to_db_failed(self, mock_function=None):
78 self.assertEqual(self.test.push_to_db(),
79 testcase.TestCase.EX_PUSH_TO_DB_ERROR)
80 mock_function.assert_called_once_with(
81 self.test.project, self.test.case_name, self.test.start_time,
82 self.test.stop_time, self.test.criteria, self.test.details)
84 @mock.patch('functest.utils.functest_utils.push_results_to_db',
86 def test_push_to_db(self, mock_function=None):
87 self.assertEqual(self.test.push_to_db(),
88 testcase.TestCase.EX_OK)
89 mock_function.assert_called_once_with(
90 self.test.project, self.test.case_name, self.test.start_time,
91 self.test.stop_time, self.test.criteria, self.test.details)
93 def test_check_criteria_missing(self):
94 self.test.criteria = None
95 self.assertEqual(self.test.check_criteria(),
96 testcase.TestCase.EX_TESTCASE_FAILED)
98 def test_check_criteria_failed(self):
99 self.test.criteria = 'FAILED'
100 self.assertEqual(self.test.check_criteria(),
101 testcase.TestCase.EX_TESTCASE_FAILED)
103 def test_check_criteria_pass(self):
104 self.test.criteria = 'PASS'
105 self.assertEqual(self.test.check_criteria(),
106 testcase.TestCase.EX_OK)
109 if __name__ == "__main__":
110 unittest.main(verbosity=2)