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)
32 self.test = testcase.TestCase(case_name=self._case_name)
33 self.test.project = "functest"
34 self.test.start_time = "1"
35 self.test.stop_time = "2"
36 self.test.criteria = "PASS"
37 self.test.details = {"Hello": "World"}
39 def test_run_unimplemented(self):
40 self.assertEqual(self.test.run(),
41 testcase.TestCase.EX_RUN_ERROR)
43 @mock.patch('functest.utils.functest_utils.push_results_to_db',
45 def _test_missing_attribute(self, mock_function=None):
46 self.assertEqual(self.test.push_to_db(),
47 testcase.TestCase.EX_PUSH_TO_DB_ERROR)
48 mock_function.assert_not_called()
50 def test_missing_project_name(self):
51 self.test.project_name = None
52 self._test_missing_attribute()
54 def test_missing_case_name(self):
55 self.test.case_name = None
56 self._test_missing_attribute()
58 def test_missing_criteria(self):
59 self.test.criteria = None
60 self._test_missing_attribute()
62 def test_missing_start_time(self):
63 self.test.start_time = None
64 self._test_missing_attribute()
66 def test_missing_stop_time(self):
67 self.test.stop_time = None
68 self._test_missing_attribute()
70 @mock.patch('functest.utils.functest_utils.push_results_to_db',
72 def test_missing_details(self, mock_function=None):
73 self.test.details = None
74 self.assertEqual(self.test.push_to_db(),
75 testcase.TestCase.EX_OK)
76 mock_function.assert_called_once_with(
77 self.test.project, self._case_name, self.test.start_time,
78 self.test.stop_time, self.test.criteria, self.test.details)
80 @mock.patch('functest.utils.functest_utils.push_results_to_db',
82 def test_push_to_db_failed(self, mock_function=None):
83 self.assertEqual(self.test.push_to_db(),
84 testcase.TestCase.EX_PUSH_TO_DB_ERROR)
85 mock_function.assert_called_once_with(
86 self.test.project, self._case_name, self.test.start_time,
87 self.test.stop_time, self.test.criteria, self.test.details)
89 @mock.patch('functest.utils.functest_utils.push_results_to_db',
91 def test_push_to_db(self, mock_function=None):
92 self.assertEqual(self.test.push_to_db(),
93 testcase.TestCase.EX_OK)
94 mock_function.assert_called_once_with(
95 self.test.project, self._case_name, self.test.start_time,
96 self.test.stop_time, self.test.criteria, self.test.details)
98 def test_check_criteria_missing(self):
99 self.test.criteria = None
100 self.assertEqual(self.test.check_criteria(),
101 testcase.TestCase.EX_TESTCASE_FAILED)
103 def test_check_criteria_failed(self):
104 self.test.criteria = 'FAILED'
105 self.assertEqual(self.test.check_criteria(),
106 testcase.TestCase.EX_TESTCASE_FAILED)
108 def test_check_criteria_pass(self):
109 self.test.criteria = 'PASS'
110 self.assertEqual(self.test.check_criteria(),
111 testcase.TestCase.EX_OK)
114 if __name__ == "__main__":
115 unittest.main(verbosity=2)