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 _project_name = "functest"
33 self.test = testcase.TestCase(case_name=self._case_name,
34 project_name=self._project_name)
35 self.test.start_time = "1"
36 self.test.stop_time = "2"
37 self.test.result = "PASS"
38 self.test.details = {"Hello": "World"}
40 def test_run_unimplemented(self):
41 self.assertEqual(self.test.run(),
42 testcase.TestCase.EX_RUN_ERROR)
44 @mock.patch('functest.utils.functest_utils.push_results_to_db',
46 def _test_missing_attribute(self, mock_function=None):
47 self.assertEqual(self.test.push_to_db(),
48 testcase.TestCase.EX_PUSH_TO_DB_ERROR)
49 mock_function.assert_not_called()
51 def test_missing_project_name(self):
52 self.test.project_name = None
53 self._test_missing_attribute()
55 def test_missing_case_name(self):
56 self.test.case_name = None
57 self._test_missing_attribute()
59 def test_missing_criteria(self):
60 self.test.result = None
61 self._test_missing_attribute()
63 def test_missing_start_time(self):
64 self.test.start_time = None
65 self._test_missing_attribute()
67 def test_missing_stop_time(self):
68 self.test.stop_time = None
69 self._test_missing_attribute()
71 @mock.patch('functest.utils.functest_utils.push_results_to_db',
73 def test_missing_details(self, mock_function=None):
74 self.test.details = None
75 self.assertEqual(self.test.push_to_db(),
76 testcase.TestCase.EX_OK)
77 mock_function.assert_called_once_with(
78 self._project_name, self._case_name, self.test.start_time,
79 self.test.stop_time, self.test.result, self.test.details)
81 @mock.patch('functest.utils.functest_utils.push_results_to_db',
83 def test_push_to_db_failed(self, mock_function=None):
84 self.assertEqual(self.test.push_to_db(),
85 testcase.TestCase.EX_PUSH_TO_DB_ERROR)
86 mock_function.assert_called_once_with(
87 self._project_name, self._case_name, self.test.start_time,
88 self.test.stop_time, self.test.result, self.test.details)
90 @mock.patch('functest.utils.functest_utils.push_results_to_db',
92 def test_push_to_db(self, mock_function=None):
93 self.assertEqual(self.test.push_to_db(),
94 testcase.TestCase.EX_OK)
95 mock_function.assert_called_once_with(
96 self._project_name, self._case_name, self.test.start_time,
97 self.test.stop_time, self.test.result, self.test.details)
99 def test_check_result_missing(self):
100 self.test.result = None
101 self.assertEqual(self.test.check_result(),
102 testcase.TestCase.EX_TESTCASE_FAILED)
104 def test_check_result_failed(self):
105 self.test.result = 'FAILED'
106 self.assertEqual(self.test.check_result(),
107 testcase.TestCase.EX_TESTCASE_FAILED)
109 def test_check_result_pass(self):
110 self.test.result = 'PASS'
111 self.assertEqual(self.test.check_result(),
112 testcase.TestCase.EX_OK)
115 if __name__ == "__main__":
116 unittest.main(verbosity=2)