summaryrefslogtreecommitdiffstats
path: root/core/TestCasesBaseTesting.py
diff options
context:
space:
mode:
authorJose Lausuch <jose.lausuch@ericsson.com>2016-10-18 13:58:53 +0000
committerGerrit Code Review <gerrit@opnfv.org>2016-10-18 13:58:54 +0000
commit8015f7e1b4da654b88ab52f7226e311a19dbbc4f (patch)
tree93a6818a917c3fa81ea00e1db582559422c6945a /core/TestCasesBaseTesting.py
parent873250561e60238db973d64f0d3bb61cb844d4a6 (diff)
parented47f47c4e08fb45dcdf6addee0eb6272dc13628 (diff)
Merge "Add a parent class for test cases."
Diffstat (limited to 'core/TestCasesBaseTesting.py')
-rwxr-xr-xcore/TestCasesBaseTesting.py80
1 files changed, 80 insertions, 0 deletions
diff --git a/core/TestCasesBaseTesting.py b/core/TestCasesBaseTesting.py
new file mode 100755
index 000000000..9658e8dc4
--- /dev/null
+++ b/core/TestCasesBaseTesting.py
@@ -0,0 +1,80 @@
+#!/usr/bin/env python
+
+import logging
+import mock
+import unittest
+
+import TestCasesBase
+
+
+class TestCasesBaseTesting(unittest.TestCase):
+
+ logging.disable(logging.CRITICAL)
+
+ def setUp(self):
+ self.test = TestCasesBase.TestCasesBase()
+ self.test.project = "functest"
+ self.test.case_name = "base"
+ self.test.start_time = "1"
+ self.test.stop_time = "2"
+ self.test.criteria = "100"
+ self.test.details = {"Hello": "World"}
+
+ def test_run_unimplemented(self):
+ self.assertEqual(self.test.run(),
+ TestCasesBase.TestCasesBase.EX_RUN_ERROR)
+
+ @mock.patch('functest.utils.functest_utils.push_results_to_db',
+ return_value=False)
+ def _test_missing_attribute(self, mock_function):
+ self.assertEqual(self.test.push_to_db(),
+ TestCasesBase.TestCasesBase.EX_PUSH_TO_DB_ERROR)
+ mock_function.assert_not_called()
+
+ def test_missing_case_name(self):
+ self.test.case_name = None
+ self._test_missing_attribute()
+
+ def test_missing_criteria(self):
+ self.test.criteria = None
+ self._test_missing_attribute()
+
+ def test_missing_start_time(self):
+ self.test.start_time = None
+ self._test_missing_attribute()
+
+ def test_missing_stop_time(self):
+ self.test.stop_time = None
+ self._test_missing_attribute()
+
+ @mock.patch('functest.utils.functest_utils.push_results_to_db',
+ return_value=True)
+ def test_missing_details(self, mock_function):
+ self.test.details = None
+ self.assertEqual(self.test.push_to_db(),
+ TestCasesBase.TestCasesBase.EX_OK)
+ mock_function.assert_called_once_with(
+ self.test.project, self.test.case_name, self.test.start_time,
+ self.test.stop_time, self.test.criteria, self.test.details)
+
+ @mock.patch('functest.utils.functest_utils.push_results_to_db',
+ return_value=False)
+ def test_push_to_db_failed(self, mock_function):
+ self.assertEqual(self.test.push_to_db(),
+ TestCasesBase.TestCasesBase.EX_PUSH_TO_DB_ERROR)
+ mock_function.assert_called_once_with(
+ self.test.project, self.test.case_name, self.test.start_time,
+ self.test.stop_time, self.test.criteria, self.test.details)
+
+ @mock.patch('functest.utils.functest_utils.push_results_to_db',
+ return_value=True)
+ def test_push_to_db(self, mock_function):
+ self.assertEqual(self.test.push_to_db(),
+ TestCasesBase.TestCasesBase.EX_OK)
+ mock_function.assert_called_once_with(
+ self.test.project, self.test.case_name, self.test.start_time,
+ self.test.stop_time, self.test.criteria, self.test.details)
+
+
+if __name__ == "__main__":
+ unittest.main(verbosity=2)