aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCédric Ollivier <cedric.ollivier@orange.com>2016-10-10 17:24:55 +0200
committerCédric Ollivier <cedric.ollivier@orange.com>2016-10-17 09:14:01 +0200
commited47f47c4e08fb45dcdf6addee0eb6272dc13628 (patch)
tree057dfc22fa5ca6565a4b09a9a91d6747ffefdb62
parent288da283a86007af01c2e71296f8230f6fce07e5 (diff)
Add a parent class for test cases.
It adds TestCasesBase on which test cases can be based. It also adds the related unit tests. JIRA: FUNCTEST-353 Change-Id: Ib2aeb24ce9d43e6384e8b38bf57ee78dd726345a Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
-rw-r--r--core/TestCasesBase.py46
-rwxr-xr-xcore/TestCasesBaseTesting.py80
-rw-r--r--core/__init__.py0
-rw-r--r--docker/Dockerfile1
4 files changed, 127 insertions, 0 deletions
diff --git a/core/TestCasesBase.py b/core/TestCasesBase.py
new file mode 100644
index 000000000..8e68fa68a
--- /dev/null
+++ b/core/TestCasesBase.py
@@ -0,0 +1,46 @@
+#!/usr/bin/env python
+
+import os
+
+import functest.utils.functest_logger as ft_logger
+import functest.utils.functest_utils as ft_utils
+
+
+class TestCasesBase(object):
+
+ EX_OK = os.EX_OK
+ EX_RUN_ERROR = os.EX_SOFTWARE
+ EX_PUSH_TO_DB_ERROR = os.EX_SOFTWARE - 1
+
+ logger = ft_logger.Logger(__name__).getLogger()
+
+ project = "functest"
+
+ def __init__(self):
+ self.details = {}
+ self.case_name = ""
+ self.criteria = ""
+ self.start_time = ""
+ self.stop_time = ""
+
+ def run(self, **kwargs):
+ self.logger.error("Run must be implemented")
+ return TestCasesBase.EX_RUN_ERROR
+
+ def push_to_db(self):
+ try:
+ assert self.case_name
+ assert self.criteria
+ assert self.start_time
+ assert self.stop_time
+ if ft_utils.push_results_to_db(
+ TestCasesBase.project, self.case_name, self.start_time,
+ self.stop_time, self.criteria, self.details):
+ self.logger.info("The results were successfully pushed to DB")
+ return TestCasesBase.EX_OK
+ else:
+ self.logger.error("The results cannot be pushed to DB")
+ return TestCasesBase.EX_PUSH_TO_DB_ERROR
+ except Exception:
+ self.logger.exception("The results cannot be pushed to DB")
+ return TestCasesBase.EX_PUSH_TO_DB_ERROR
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)
diff --git a/core/__init__.py b/core/__init__.py
new file mode 100644
index 000000000..e69de29bb
--- /dev/null
+++ b/core/__init__.py
diff --git a/docker/Dockerfile b/docker/Dockerfile
index 2d325eaaf..9ff0f4f62 100644
--- a/docker/Dockerfile
+++ b/docker/Dockerfile
@@ -53,6 +53,7 @@ git \
gcc \
wget \
python-dev \
+python-mock \
python-pip \
bundler \
postgresql \