aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'functest/tests/unit')
-rw-r--r--functest/tests/unit/ci/test_run_tests.py171
-rw-r--r--functest/tests/unit/ci/test_tier_builder.py3
-rw-r--r--functest/tests/unit/openstack/refstack_client/test_refstack_client.py6
-rw-r--r--functest/tests/unit/openstack/tempest/test_conf_utils.py5
-rw-r--r--functest/tests/unit/utils/test_functest_utils.py42
-rw-r--r--functest/tests/unit/utils/test_openstack_utils.py15
6 files changed, 106 insertions, 136 deletions
diff --git a/functest/tests/unit/ci/test_run_tests.py b/functest/tests/unit/ci/test_run_tests.py
index fb8cb391..7495c40e 100644
--- a/functest/tests/unit/ci/test_run_tests.py
+++ b/functest/tests/unit/ci/test_run_tests.py
@@ -54,11 +54,6 @@ class RunTestsTesting(unittest.TestCase):
self.run_tests_parser = run_tests.RunTestsParser()
- @mock.patch('functest.ci.run_tests.logger.info')
- def test_print_separator(self, mock_logger_info):
- self.runner.print_separator(self.sep)
- mock_logger_info.assert_called_once_with(self.sep * 44)
-
@mock.patch('functest.ci.run_tests.logger.error')
def test_source_rc_file_missing_file(self, mock_logger_error):
with mock.patch('functest.ci.run_tests.os.path.isfile',
@@ -120,8 +115,7 @@ class RunTestsTesting(unittest.TestCase):
args = {'get_name.return_value': 'test_name',
'needs_clean.return_value': False}
mock_test.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.Runner.print_separator'),\
- mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
+ with mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
mock.patch('functest.ci.run_tests.Runner.get_run_dict',
return_value=None), \
self.assertRaises(Exception) as context:
@@ -129,7 +123,6 @@ class RunTestsTesting(unittest.TestCase):
msg = "Cannot import the class for the test case."
self.assertTrue(msg in context)
- @mock.patch('functest.ci.run_tests.Runner.print_separator')
@mock.patch('functest.ci.run_tests.Runner.source_rc_file')
@mock.patch('importlib.import_module', name="module",
return_value=mock.Mock(test_class=mock.Mock(
@@ -145,123 +138,107 @@ class RunTestsTesting(unittest.TestCase):
with mock.patch('functest.ci.run_tests.Runner.get_run_dict',
return_value=test_run_dict):
self.runner.clean_flag = True
- self.runner.run_test(mock_test, 'tier_name')
+ self.runner.run_test(mock_test)
self.assertEqual(self.runner.overall_result,
run_tests.Result.EX_OK)
- @mock.patch('functest.ci.run_tests.logger.info')
- def test_run_tier_default(self, mock_logger_info):
- with mock.patch('functest.ci.run_tests.Runner.print_separator'), \
- mock.patch(
- 'functest.ci.run_tests.Runner.run_test',
- return_value=TestCase.EX_OK) as mock_method:
- self.runner.run_tier(self.tier)
- mock_method.assert_any_call(mock.ANY, 'test_tier')
- self.assertTrue(mock_logger_info.called)
+ @mock.patch('functest.ci.run_tests.Runner.run_test',
+ return_value=TestCase.EX_OK)
+ def test_run_tier_default(self, *mock_methods):
+ self.assertEqual(self.runner.run_tier(self.tier),
+ run_tests.Result.EX_OK)
+ mock_methods[0].assert_called_with(mock.ANY)
@mock.patch('functest.ci.run_tests.logger.info')
def test_run_tier_missing_test(self, mock_logger_info):
- with mock.patch('functest.ci.run_tests.Runner.print_separator'):
- self.tier.get_tests.return_value = None
- self.assertEqual(self.runner.run_tier(self.tier), 0)
- self.assertTrue(mock_logger_info.called)
+ self.tier.get_tests.return_value = None
+ self.assertEqual(self.runner.run_tier(self.tier),
+ run_tests.Result.EX_ERROR)
+ self.assertTrue(mock_logger_info.called)
@mock.patch('functest.ci.run_tests.logger.info')
- def test_run_all_default(self, mock_logger_info):
- with mock.patch(
- 'functest.ci.run_tests.Runner.run_tier') as mock_method:
- CONST.__setattr__('CI_LOOP', 'test_ci_loop')
- self.runner.run_all(self.tiers)
- mock_method.assert_any_call(self.tier)
- self.assertTrue(mock_logger_info.called)
+ @mock.patch('functest.ci.run_tests.Runner.run_tier')
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_run_all_default(self, *mock_methods):
+ CONST.__setattr__('CI_LOOP', 'test_ci_loop')
+ self.runner.run_all()
+ mock_methods[1].assert_not_called()
+ self.assertTrue(mock_methods[2].called)
@mock.patch('functest.ci.run_tests.logger.info')
- def test_run_all_missing_tier(self, mock_logger_info):
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_run_all_missing_tier(self, *mock_methods):
CONST.__setattr__('CI_LOOP', 'loop_re_not_available')
- self.runner.run_all(self.tiers)
- self.assertTrue(mock_logger_info.called)
+ self.runner.run_all()
+ self.assertTrue(mock_methods[1].called)
- def test_main_failed(self):
+ @mock.patch('functest.ci.run_tests.Runner.source_rc_file',
+ side_effect=Exception)
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_main_failed(self, *mock_methods):
kwargs = {'test': 'test_name', 'noclean': True, 'report': True}
- mock_obj = mock.Mock()
args = {'get_tier.return_value': False,
'get_test.return_value': False}
- mock_obj.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder'), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file',
- side_effect=Exception):
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_ERROR)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder',
- return_value=mock_obj), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file',
- side_effect=Exception):
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_ERROR)
-
- def test_main_tier(self, *args):
+ self.runner._tiers = mock.Mock()
+ self.runner._tiers.configure_mock(**args)
+ self.assertEqual(self.runner.main(**kwargs),
+ run_tests.Result.EX_ERROR)
+ mock_methods[1].assert_called_once_with()
+
+ @mock.patch('functest.ci.run_tests.Runner.source_rc_file')
+ @mock.patch('functest.ci.run_tests.Runner.run_test',
+ return_value=TestCase.EX_OK)
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_main_tier(self, *mock_methods):
mock_tier = mock.Mock()
- args = {'get_name.return_value': 'tier_name'}
+ args = {'get_name.return_value': 'tier_name',
+ 'get_tests.return_value': ['test_name']}
mock_tier.configure_mock(**args)
kwargs = {'test': 'tier_name', 'noclean': True, 'report': True}
- mock_obj = mock.Mock()
args = {'get_tier.return_value': mock_tier,
'get_test.return_value': None}
- mock_obj.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder',
- return_value=mock_obj), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
- mock.patch('functest.ci.run_tests.Runner.run_tier') as m:
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_OK)
- self.assertTrue(m.called)
-
- def test_main_test(self, *args):
+ self.runner._tiers = mock.Mock()
+ self.runner._tiers.configure_mock(**args)
+ self.assertEqual(self.runner.main(**kwargs),
+ run_tests.Result.EX_OK)
+ mock_methods[1].assert_called_once_with('test_name')
+
+ @mock.patch('functest.ci.run_tests.Runner.source_rc_file')
+ @mock.patch('functest.ci.run_tests.Runner.run_test',
+ return_value=TestCase.EX_OK)
+ def test_main_test(self, *mock_methods):
kwargs = {'test': 'test_name', 'noclean': True, 'report': True}
- mock_test = mock.Mock()
- args = {'get_name.return_value': 'test_name',
- 'needs_clean.return_value': True}
- mock_test.configure_mock(**args)
- mock_obj = mock.Mock()
args = {'get_tier.return_value': None,
- 'get_test.return_value': mock_test}
- mock_obj.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder',
- return_value=mock_obj), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
- mock.patch('functest.ci.run_tests.Runner.run_test',
- return_value=TestCase.EX_OK) as m:
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_OK)
- self.assertTrue(m.called)
-
- def test_main_all_tier(self, *args):
+ 'get_test.return_value': 'test_name'}
+ self.runner._tiers = mock.Mock()
+ self.runner._tiers.configure_mock(**args)
+ self.assertEqual(self.runner.main(**kwargs),
+ run_tests.Result.EX_OK)
+ mock_methods[0].assert_called_once_with('test_name')
+
+ @mock.patch('functest.ci.run_tests.Runner.source_rc_file')
+ @mock.patch('functest.ci.run_tests.Runner.run_all')
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_main_all_tier(self, *mock_methods):
kwargs = {'test': 'all', 'noclean': True, 'report': True}
- mock_obj = mock.Mock()
args = {'get_tier.return_value': None,
'get_test.return_value': None}
- mock_obj.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder',
- return_value=mock_obj), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
- mock.patch('functest.ci.run_tests.Runner.run_all') as m:
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_OK)
- self.assertTrue(m.called)
-
- def test_main_any_tier_test_ko(self, *args):
+ self.runner._tiers = mock.Mock()
+ self.runner._tiers.configure_mock(**args)
+ self.assertEqual(self.runner.main(**kwargs),
+ run_tests.Result.EX_OK)
+ mock_methods[1].assert_called_once_with()
+
+ @mock.patch('functest.ci.run_tests.Runner.source_rc_file')
+ @mock.patch('functest.ci.run_tests.Runner.summary')
+ def test_main_any_tier_test_ko(self, *mock_methods):
kwargs = {'test': 'any', 'noclean': True, 'report': True}
- mock_obj = mock.Mock()
args = {'get_tier.return_value': None,
'get_test.return_value': None}
- mock_obj.configure_mock(**args)
- with mock.patch('functest.ci.run_tests.tb.TierBuilder',
- return_value=mock_obj), \
- mock.patch('functest.ci.run_tests.Runner.source_rc_file'), \
- mock.patch('functest.ci.run_tests.logger.debug') as m:
- self.assertEqual(self.runner.main(**kwargs),
- run_tests.Result.EX_ERROR)
- self.assertTrue(m.called)
+ self.runner._tiers = mock.Mock()
+ self.runner._tiers.configure_mock(**args)
+ self.assertEqual(self.runner.main(**kwargs),
+ run_tests.Result.EX_ERROR)
if __name__ == "__main__":
diff --git a/functest/tests/unit/ci/test_tier_builder.py b/functest/tests/unit/ci/test_tier_builder.py
index ab75e15b..700c6e91 100644
--- a/functest/tests/unit/ci/test_tier_builder.py
+++ b/functest/tests/unit/ci/test_tier_builder.py
@@ -24,7 +24,8 @@ class TierBuilderTesting(unittest.TestCase):
'case_name': 'test_name',
'criteria': 'test_criteria',
'blocking': 'test_blocking',
- 'description': 'test_desc'}
+ 'description': 'test_desc',
+ 'project_name': 'project_name'}
self.dic_tier = {'name': 'test_tier',
'order': 'test_order',
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 e4e3364d..c5601075 100644
--- a/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
+++ b/functest/tests/unit/openstack/refstack_client/test_refstack_client.py
@@ -79,9 +79,9 @@ class OSRefstackClientTesting(unittest.TestCase):
''')
self.details = {"tests": 3,
"failures": 1,
- "success": [' tempest.api.compute [18.464988s]'],
- "errors": [' tempest.api.volume [0.230334s]'],
- "skipped": [' tempest.api.network [1.265828s]']}
+ "success": ['tempest.api.compute [18.464988s]'],
+ "errors": ['tempest.api.volume [0.230334s]'],
+ "skipped": ['tempest.api.network [1.265828s]']}
with mock.patch('__builtin__.open',
mock.mock_open(read_data=log_file)):
self.refstackclient.parse_refstack_result()
diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py
index 79ef9915..a807ae46 100644
--- a/functest/tests/unit/openstack/tempest/test_conf_utils.py
+++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py
@@ -262,10 +262,9 @@ class OSTempestConfUtilsTesting(unittest.TestCase):
mock.patch('__builtin__.open', mock.mock_open()), \
mock.patch('functest.opnfv_tests.openstack.tempest.'
'conf_utils.backup_tempest_config'), \
- mock.patch('functest.utils.functest_utils.yaml.safe_load') \
- as mock_yaml:
+ mock.patch('functest.utils.functest_utils.yaml.safe_load',
+ return_value={'validation': {'ssh_timeout': 300}}):
CONST.__setattr__('OS_ENDPOINT_TYPE', None)
- mock_yaml.return_value = mock.Mock()
conf_utils.\
configure_tempest_update_params('test_conf_file',
IMAGE_ID=image_id,
diff --git a/functest/tests/unit/utils/test_functest_utils.py b/functest/tests/unit/utils/test_functest_utils.py
index 98c7d6e9..b4cc5b73 100644
--- a/functest/tests/unit/utils/test_functest_utils.py
+++ b/functest/tests/unit/utils/test_functest_utils.py
@@ -133,24 +133,20 @@ class FunctestUtilsTesting(unittest.TestCase):
self.assertEqual(functest_utils.get_scenario(),
self.scenario)
- @mock.patch('functest.utils.functest_utils.get_build_tag')
- def test_get_version_daily_job(self, mock_get_build_tag):
- mock_get_build_tag.return_value = self.build_tag
+ def test_get_version_daily_job(self):
+ CONST.__setattr__('BUILD_TAG', self.build_tag)
self.assertEqual(functest_utils.get_version(), self.version)
- @mock.patch('functest.utils.functest_utils.get_build_tag')
- def test_get_version_weekly_job(self, mock_get_build_tag):
- mock_get_build_tag.return_value = self.build_tag_week
+ def test_get_version_weekly_job(self):
+ CONST.__setattr__('BUILD_TAG', self.build_tag_week)
self.assertEqual(functest_utils.get_version(), self.version)
- @mock.patch('functest.utils.functest_utils.get_build_tag')
- def test_get_version_with_dummy_build_tag(self, mock_get_build_tag):
- mock_get_build_tag.return_value = 'whatever'
+ def test_get_version_with_dummy_build_tag(self):
+ CONST.__setattr__('BUILD_TAG', 'whatever')
self.assertEqual(functest_utils.get_version(), 'unknown')
- @mock.patch('functest.utils.functest_utils.get_build_tag')
- def test_get_version_unknown(self, mock_get_build_tag):
- mock_get_build_tag.return_value = "unknown_build_tag"
+ def test_get_version_unknown(self):
+ CONST.__setattr__('BUILD_TAG', 'unknown_build_tag')
self.assertEqual(functest_utils.get_version(), "unknown")
@mock.patch('functest.utils.functest_utils.logger.info')
@@ -173,33 +169,15 @@ class FunctestUtilsTesting(unittest.TestCase):
self.node_name)
@mock.patch('functest.utils.functest_utils.logger.info')
- def test_get_build_tag_failed(self, mock_logger_info):
- with mock.patch.dict(os.environ,
- {},
- clear=True):
- self.assertEqual(functest_utils.get_build_tag(),
- "none")
- mock_logger_info.assert_called_once_with("Impossible to retrieve"
- " the build tag")
-
- def test_get_build_tag_default(self):
- with mock.patch.dict(os.environ,
- {'BUILD_TAG': self.build_tag},
- clear=True):
- self.assertEqual(functest_utils.get_build_tag(),
- self.build_tag)
-
- @mock.patch('functest.utils.functest_utils.logger.info')
def test_logger_test_results(self, mock_logger_info):
CONST.__setattr__('results_test_db_url', self.db_url)
+ CONST.__setattr__('BUILD_TAG', self.build_tag)
with mock.patch('functest.utils.functest_utils.get_pod_name',
return_value=self.node_name), \
mock.patch('functest.utils.functest_utils.get_scenario',
return_value=self.scenario), \
mock.patch('functest.utils.functest_utils.get_version',
- return_value=self.version), \
- mock.patch('functest.utils.functest_utils.get_build_tag',
- return_value=self.build_tag):
+ return_value=self.version):
functest_utils.logger_test_results(self.project, self.case_name,
self.status, self.details)
mock_logger_info.assert_called_once_with(
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py
index cabd18e5..3bd7e3dd 100644
--- a/functest/tests/unit/utils/test_openstack_utils.py
+++ b/functest/tests/unit/utils/test_openstack_utils.py
@@ -13,6 +13,7 @@ import unittest
import mock
from functest.utils import openstack_utils
+from functest.utils.constants import CONST
class OSUtilsTesting(unittest.TestCase):
@@ -187,11 +188,18 @@ class OSUtilsTesting(unittest.TestCase):
mock_obj.configure_mock(**attrs)
self.role = mock_obj
+ mock_obj = mock.Mock()
+ attrs = {'id': 'domain_id',
+ 'name': 'test_domain'}
+ mock_obj.configure_mock(**attrs)
+ self.domain = mock_obj
+
self.keystone_client = mock.Mock()
attrs = {'projects.list.return_value': [self.tenant],
'tenants.list.return_value': [self.tenant],
'users.list.return_value': [self.user],
'roles.list.return_value': [self.role],
+ 'domains.list.return_value': [self.domain],
'projects.create.return_value': self.tenant,
'tenants.create.return_value': self.tenant,
'users.create.return_value': self.user,
@@ -1650,9 +1658,16 @@ class OSUtilsTesting(unittest.TestCase):
'test_role'),
'role_id')
+ def test_get_domain_id_default(self):
+ self.assertEqual(openstack_utils.
+ get_domain_id(self.keystone_client,
+ 'test_domain'),
+ 'domain_id')
+
def test_create_tenant_default(self):
with mock.patch('functest.utils.openstack_utils.'
'is_keystone_v3', return_value=True):
+ CONST.__setattr__('OS_PROJECT_DOMAIN_NAME', 'Default')
self.assertEqual(openstack_utils.
create_tenant(self.keystone_client,
'test_tenant',