diff options
Diffstat (limited to 'functest/tests')
3 files changed, 28 insertions, 35 deletions
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/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', |