diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2016-10-19 16:55:05 +0200 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2016-10-19 16:57:45 +0200 |
commit | 9cab15dfbac796fa1f5122bbea580e84411b73cf (patch) | |
tree | beb4beb535e4962790055164005e6fa4e9df16e1 /unit_tests/core | |
parent | f59bb826d25e80461b891d8b6424d255d2e30a66 (diff) |
Move unit tests in unit_tests
It also renames files and removes exec rights to be conformed with
nose.
Change-Id: Ib93973a7d4b543360372fb1092a58896f687ec84
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'unit_tests/core')
-rw-r--r-- | unit_tests/core/__init__.py | 0 | ||||
-rw-r--r-- | unit_tests/core/test_base.py | 80 |
2 files changed, 80 insertions, 0 deletions
diff --git a/unit_tests/core/__init__.py b/unit_tests/core/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/unit_tests/core/__init__.py diff --git a/unit_tests/core/test_base.py b/unit_tests/core/test_base.py new file mode 100644 index 000000000..fc9c2db60 --- /dev/null +++ b/unit_tests/core/test_base.py @@ -0,0 +1,80 @@ +#!/usr/bin/env python + +import logging +import mock +import unittest + +from functest.core 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) |