aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests
diff options
context:
space:
mode:
Diffstat (limited to 'functest/tests')
-rw-r--r--functest/tests/unit/core/test_pytest_suite_runner.py76
-rw-r--r--functest/tests/unit/core/test_vnf.py4
-rw-r--r--functest/tests/unit/features/test_barometer.py5
-rw-r--r--functest/tests/unit/openstack/refstack_client/test_refstack_client.py24
-rw-r--r--functest/tests/unit/test_logging.ini27
-rw-r--r--functest/tests/unit/utils/test_decorators.py2
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py3
7 files changed, 80 insertions, 61 deletions
diff --git a/functest/tests/unit/core/test_pytest_suite_runner.py b/functest/tests/unit/core/test_pytest_suite_runner.py
index 07ac7906..f317cdea 100644
--- a/functest/tests/unit/core/test_pytest_suite_runner.py
+++ b/functest/tests/unit/core/test_pytest_suite_runner.py
@@ -20,29 +20,71 @@ class PyTestSuiteRunnerTesting(unittest.TestCase):
def setUp(self):
self.psrunner = pytest_suite_runner.PyTestSuiteRunner()
- self.result = mock.Mock()
- attrs = {'errors': [('test1', 'error_msg1')],
- 'failures': [('test2', 'failure_msg1')]}
- self.result.configure_mock(**attrs)
-
- self.pass_results = mock.Mock()
- attrs = {'errors': None,
- 'failures': None}
- self.pass_results.configure_mock(**attrs)
-
- def test_run(self):
- self.psrunner.case_name = 'test_case_name'
+
+ @mock.patch('unittest.TestLoader')
+ def _test_run(self, mock_class=None, result=mock.Mock(),
+ status=testcase.TestCase.EX_OK):
with mock.patch('functest.core.pytest_suite_runner.'
'unittest.TextTestRunner.run',
- return_value=self.result):
- self.assertEqual(self.psrunner.run(),
- testcase.TestCase.EX_OK)
+ return_value=result):
+ self.assertEqual(self.psrunner.run(), status)
+ mock_class.assert_not_called()
+
+ def test_check_suite_null(self):
+ self.assertEqual(self.psrunner.suite, None)
+
+ def test_run_no_ut(self):
+ mock_result = mock.Mock(testsRun=0, errors=[], failures=[])
+ self._test_run(result=mock_result,
+ status=testcase.TestCase.EX_RUN_ERROR)
+ self.assertEqual(self.psrunner.result, 0)
+ self.assertEqual(self.psrunner.details, {'errors': [], 'failures': []})
+ self.assertEqual(self.psrunner.is_successful(),
+ testcase.TestCase.EX_TESTCASE_FAILED)
+
+ def test_run_result_ko(self):
+ self.psrunner.criteria = 100
+ mock_result = mock.Mock(testsRun=50, errors=[('test1', 'error_msg1')],
+ failures=[('test2', 'failure_msg1')])
+ self._test_run(result=mock_result)
+ self.assertEqual(self.psrunner.result, 96)
+ self.assertEqual(self.psrunner.details,
+ {'errors': [('test1', 'error_msg1')],
+ 'failures': [('test2', 'failure_msg1')]})
+ self.assertEqual(self.psrunner.is_successful(),
+ testcase.TestCase.EX_TESTCASE_FAILED)
+
+ def test_run_result_ok(self):
+ mock_result = mock.Mock(testsRun=50, errors=[],
+ failures=[])
+ self._test_run(result=mock_result)
+ self.assertEqual(self.psrunner.result, 100)
+ self.assertEqual(self.psrunner.details, {'errors': [], 'failures': []})
+ self.assertEqual(self.psrunner.is_successful(),
+ testcase.TestCase.EX_OK)
+
+ @mock.patch('unittest.TestLoader')
+ def test_run_name_exc(self, mock_class=None):
+ mock_obj = mock.Mock(side_effect=ImportError)
+ mock_class.side_effect = mock_obj
+ self.assertEqual(self.psrunner.run(name='foo'),
+ testcase.TestCase.EX_RUN_ERROR)
+ mock_class.assert_called_once_with()
+ mock_obj.assert_called_once_with()
+ @mock.patch('unittest.TestLoader')
+ def test_run_name(self, mock_class=None):
+ mock_result = mock.Mock(testsRun=50, errors=[],
+ failures=[])
+ mock_obj = mock.Mock()
+ mock_class.side_effect = mock_obj
with mock.patch('functest.core.pytest_suite_runner.'
'unittest.TextTestRunner.run',
- return_value=self.pass_results):
- self.assertEqual(self.psrunner.run(),
+ return_value=mock_result):
+ self.assertEqual(self.psrunner.run(name='foo'),
testcase.TestCase.EX_OK)
+ mock_class.assert_called_once_with()
+ mock_obj.assert_called_once_with()
if __name__ == "__main__":
diff --git a/functest/tests/unit/core/test_vnf.py b/functest/tests/unit/core/test_vnf.py
index e322773e..ce859040 100644
--- a/functest/tests/unit/core/test_vnf.py
+++ b/functest/tests/unit/core/test_vnf.py
@@ -146,12 +146,12 @@ class VnfBaseTesting(unittest.TestCase):
def test_deploy_vnf_unimplemented(self):
with self.assertRaises(Exception) as context:
self.test.deploy_vnf()
- self.assertTrue('VNF not deployed' in context.exception)
+ self.assertIn('VNF not deployed', str(context.exception))
def test_test_vnf_unimplemented(self):
with self.assertRaises(Exception) as context:
self.test.test_vnf()()
- self.assertTrue('VNF not tested' in context.exception)
+ self.assertIn('VNF not tested', str(context.exception))
def test_parse_results_ex_ok(self):
self.test.details['test_vnf']['status'] = 'PASS'
diff --git a/functest/tests/unit/features/test_barometer.py b/functest/tests/unit/features/test_barometer.py
index c6512615..8c2585d9 100644
--- a/functest/tests/unit/features/test_barometer.py
+++ b/functest/tests/unit/features/test_barometer.py
@@ -16,9 +16,8 @@ import unittest
import mock
from functest.core import testcase
-sys.modules['baro_tests'] = mock.Mock() # noqa
-# pylint: disable=wrong-import-position
-from functest.opnfv_tests.features import barometer
+with mock.patch('functest.utils.functest_utils.get_parameter_from_yaml'):
+ from functest.opnfv_tests.features import barometer
class BarometerTesting(unittest.TestCase):
diff --git a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
index 58ec5a07..8c149baa 100644
--- a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
+++ b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
@@ -17,10 +17,12 @@ from functest.utils.constants import CONST
class OSRefstackClientTesting(unittest.TestCase):
- _config = os.path.join(CONST.dir_functest_test,
- CONST.refstack_tempest_conf_path)
- _testlist = os.path.join(CONST.dir_functest_test,
- CONST.refstack_defcore_list)
+ _config = os.path.join(
+ CONST.__getattribute__('dir_functest_test'),
+ CONST.__getattribute__('refstack_tempest_conf_path'))
+ _testlist = os.path.join(
+ CONST.__getattribute__('dir_functest_test'),
+ CONST.__getattribute__('refstack_defcore_list'))
def setUp(self):
self.defaultargs = {'config': self._config,
@@ -28,12 +30,13 @@ class OSRefstackClientTesting(unittest.TestCase):
self.refstackclient = refstack_client.RefstackClient()
def test_source_venv(self):
- CONST.dir_refstack_client = 'test_repo_dir'
+ CONST.__setattr__('dir_refstack_client', 'test_repo_dir')
with mock.patch('functest.opnfv_tests.openstack.refstack_client.'
'refstack_client.ft_utils.execute_command') as m:
cmd = ("cd {0};"
". .venv/bin/activate;"
- "cd -;".format(CONST.dir_refstack_client))
+ "cd -;"
+ .format(CONST.__getattribute__('dir_refstack_client')))
self.refstackclient.source_venv()
m.assert_any_call(cmd)
@@ -44,9 +47,10 @@ class OSRefstackClientTesting(unittest.TestCase):
'refstack_client.ft_utils.execute_command') as m:
cmd = ("cd {0};"
"./refstack-client test -c {1} -v --test-list {2};"
- "cd -;".format(CONST.dir_refstack_client,
- config,
- testlist))
+ "cd -;"
+ .format(CONST.__getattribute__('dir_refstack_client'),
+ config,
+ testlist))
self.refstackclient.run_defcore(config, testlist)
m.assert_any_call(cmd)
@@ -62,7 +66,7 @@ class OSRefstackClientTesting(unittest.TestCase):
self.assertEqual(self.refstackclient.main(**kwargs), status)
if len(args) > 0:
args[0].assert_called_once_with(
- refstack_client.RefstackClient.result_dir)
+ refstack_client.RefstackClient.result_dir)
if len(args) > 1:
args
diff --git a/functest/tests/unit/test_logging.ini b/functest/tests/unit/test_logging.ini
deleted file mode 100644
index 492767d1..00000000
--- a/functest/tests/unit/test_logging.ini
+++ /dev/null
@@ -1,27 +0,0 @@
-[loggers]
-keys=root,functest_logger
-
-[logger_root]
-level=DEBUG
-handlers=console
-
-[logger_functest_logger]
-level=DEBUG
-handlers=console
-qualname=functest.utils.functest_logger
-propagate=0
-
-[handlers]
-keys=console
-
-[handler_console]
-class=StreamHandler
-level=INFO
-formatter=standard
-args=(sys.stdout,)
-
-[formatters]
-keys=standard
-
-[formatter_standard]
-format=%(asctime)s - %(name)s - %(levelname)s - %(message)s \ No newline at end of file
diff --git a/functest/tests/unit/utils/test_decorators.py b/functest/tests/unit/utils/test_decorators.py
index 6bd47d25..44448f23 100644
--- a/functest/tests/unit/utils/test_decorators.py
+++ b/functest/tests/unit/utils/test_decorators.py
@@ -63,7 +63,7 @@ class DecoratorsTesting(unittest.TestCase):
'pod_name': self._node_name, 'installer': self._installer_type,
'scenario': self._deploy_scenario, 'version': VERSION,
'details': {}, 'criteria': self._result}
- return json.dumps(data)
+ return json.dumps(data, sort_keys=True)
@mock.patch('{}.get_db_url'.format(functest_utils.__name__),
return_value='http://127.0.0.1')
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index 0fe7e91d..218f7f72 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -55,7 +55,8 @@ class FunctestUtilsTesting(unittest.TestCase):
self.testcase_dict = {'case_name': 'testname',
'criteria': self.criteria}
self.parameter = 'general.openstack.image_name'
- self.config_yaml = 'test_config_yaml-'
+ self.config_yaml = os.path.normpath(os.path.join(os.path.dirname(
+ os.path.abspath(__file__)), '../../../ci/config_functest.yaml'))
self.db_url_env = 'http://foo/testdb'
self.file_yaml = {'general': {'openstack': {'image_name':
'test_image_name'}}}