diff options
author | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-02-22 17:43:35 +0100 |
---|---|---|
committer | Cédric Ollivier <cedric.ollivier@orange.com> | 2018-02-22 19:41:31 +0100 |
commit | 9f7c63ffaf64b3ca81ae86a0b3477e5007916fcd (patch) | |
tree | 71d1e082404d4356a1f3491482c03bbb6a6914a5 /functest/tests/unit | |
parent | d701e9737f83ff29faba830df426b5a75c9746b1 (diff) |
Switch from CONST to CONF
It also removes constants.CONST and env.Environment which are now
useless.
Depends-On: I764a0a2a24447c941d1e726f3116593b29dd1c1e
Depends-On: I6cfa832466dcefd737314633d807512e46267a69
Change-Id: Ife41c59d9f2e6ec4e49df38af962039f99554bc5
Signed-off-by: Cédric Ollivier <cedric.ollivier@orange.com>
Diffstat (limited to 'functest/tests/unit')
-rw-r--r-- | functest/tests/unit/openstack/tempest/test_conf_utils.py | 32 | ||||
-rw-r--r-- | functest/tests/unit/utils/test_env.py | 39 |
2 files changed, 16 insertions, 55 deletions
diff --git a/functest/tests/unit/openstack/tempest/test_conf_utils.py b/functest/tests/unit/openstack/tempest/test_conf_utils.py index 34dc0f4c..e88bb248 100644 --- a/functest/tests/unit/openstack/tempest/test_conf_utils.py +++ b/functest/tests/unit/openstack/tempest/test_conf_utils.py @@ -14,7 +14,7 @@ import unittest import mock from functest.opnfv_tests.openstack.tempest import tempest, conf_utils -from functest.utils.constants import CONST +from functest.utils import config from snaps.openstack.os_credentials import OSCreds @@ -77,13 +77,13 @@ class OSTempestConfUtilsTesting(unittest.TestCase): tempest_resources = tempest.TempestResourcesManager( os_creds=self.os_creds) - setattr(CONST, 'tempest_use_custom_flavors', 'True') + setattr(config.CONF, 'tempest_use_custom_flavors', 'True') with self.assertRaises(Exception) as context: tempest_resources.create() msg = 'Failed to create flavor' self.assertTrue(msg in context.exception, msg=str(context.exception)) - setattr(CONST, 'tempest_use_custom_flavors', 'False') + setattr(config.CONF, 'tempest_use_custom_flavors', 'False') with self.assertRaises(Exception) as context: tempest_resources.create(use_custom_flavors=True) msg = 'Failed to create flavor' @@ -101,12 +101,12 @@ class OSTempestConfUtilsTesting(unittest.TestCase): cmd = "rally deployment destroy opnfv-rally" error_msg = "Deployment %s does not exist." % \ - getattr(CONST, 'rally_deployment_name') + getattr(config.CONF, 'rally_deployment_name') mock_logger_info.assert_any_call("Creating Rally environment...") mock_exec.assert_any_call(cmd, error_msg=error_msg, verbose=False) cmd = "rally deployment create --fromenv --name=" - cmd += getattr(CONST, 'rally_deployment_name') + cmd += getattr(config.CONF, 'rally_deployment_name') error_msg = "Problem while creating Rally deployment" mock_exec_raise.assert_any_call(cmd, error_msg=error_msg) @@ -123,12 +123,12 @@ class OSTempestConfUtilsTesting(unittest.TestCase): 'stdout.readline.return_value': '0'} mock_popen.configure_mock(**attrs) - setattr(CONST, 'tempest_verifier_name', 'test_veifier_name') + setattr(config.CONF, 'tempest_verifier_name', 'test_verifier_name') with mock.patch('functest.utils.functest_utils.execute_command_raise', side_effect=Exception), \ self.assertRaises(Exception): conf_utils.create_verifier() - mock_logger_debug.assert_any_call("Tempest test_veifier_name" + mock_logger_debug.assert_any_call("Tempest test_verifier_name" " does not exist") @mock.patch('functest.opnfv_tests.openstack.tempest.conf_utils.' @@ -137,7 +137,7 @@ class OSTempestConfUtilsTesting(unittest.TestCase): 'create_rally_deployment', return_value=mock.Mock()) def test_get_verif_id_missing_verif(self, mock_rally, mock_tempest): # pylint: disable=unused-argument - setattr(CONST, 'tempest_verifier_name', 'test_verifier_name') + setattr(config.CONF, 'tempest_verifier_name', 'test_verifier_name') with mock.patch('functest.opnfv_tests.openstack.tempest.' 'conf_utils.subprocess.Popen') as mock_popen, \ self.assertRaises(Exception): @@ -153,7 +153,7 @@ class OSTempestConfUtilsTesting(unittest.TestCase): 'create_rally_deployment', return_value=mock.Mock()) def test_get_verifier_id_default(self, mock_rally, mock_tempest): # pylint: disable=unused-argument - setattr(CONST, 'tempest_verifier_name', 'test_verifier_name') + setattr(config.CONF, 'tempest_verifier_name', 'test_verifier_name') with mock.patch('functest.opnfv_tests.openstack.tempest.' 'conf_utils.subprocess.Popen') as mock_popen: mock_stdout = mock.Mock() @@ -165,7 +165,7 @@ class OSTempestConfUtilsTesting(unittest.TestCase): 'test_deploy_id') def test_get_depl_id_missing_rally(self): - setattr(CONST, 'tempest_verifier_name', 'test_deploy_name') + setattr(config.CONF, 'tempest_verifier_name', 'test_deploy_name') with mock.patch('functest.opnfv_tests.openstack.tempest.' 'conf_utils.subprocess.Popen') as mock_popen, \ self.assertRaises(Exception): @@ -176,7 +176,7 @@ class OSTempestConfUtilsTesting(unittest.TestCase): conf_utils.get_verifier_deployment_id() def test_get_depl_id_default(self): - setattr(CONST, 'tempest_verifier_name', 'test_deploy_name') + setattr(config.CONF, 'tempest_verifier_name', 'test_deploy_name') with mock.patch('functest.opnfv_tests.openstack.tempest.' 'conf_utils.subprocess.Popen') as mock_popen: mock_stdout = mock.Mock() @@ -313,12 +313,12 @@ class OSTempestConfUtilsTesting(unittest.TestCase): 'test_image_id_alt'), None, None) def test_upd_missing_flavor_id(self): - setattr(CONST, 'tempest_use_custom_flavors', 'True') + setattr(config.CONF, 'tempest_use_custom_flavors', 'True') self._test_missing_param(('compute', 'flavor_ref', 'test_flavor_id'), None, 'test_flavor_id') def test_upd_missing_flavor_id_alt(self): - setattr(CONST, 'tempest_use_custom_flavors', 'True') + setattr(config.CONF, 'tempest_use_custom_flavors', 'True') conf_utils.FLAVOR_ID_ALT = 'test_flavor_id_alt' self._test_missing_param(('compute', 'flavor_ref_alt', 'test_flavor_id_alt'), None, None) @@ -327,14 +327,14 @@ class OSTempestConfUtilsTesting(unittest.TestCase): with mock.patch('functest.opnfv_tests.openstack.tempest.' 'conf_utils.os.path.isfile', return_value=False), \ - mock.patch('functest.opnfv_tests.openstack.tempest.' - 'conf_utils.ft_utils.execute_command') as mexe, \ + mock.patch('functest.opnfv_tests.openstack.tempest.' + 'conf_utils.ft_utils.execute_command') as mexe, \ self.assertRaises(Exception) as context: conf_utils.configure_verifier('test_dep_dir') mexe.assert_any_call("rally verify configure-verifier") msg = ("Tempest configuration file 'test_dep_dir/tempest.conf'" " NOT found.") - self.assertTrue(msg in context) + self.assertTrue(msg in context.exception) def test_configure_verifier_default(self): with mock.patch('functest.opnfv_tests.openstack.tempest.' diff --git a/functest/tests/unit/utils/test_env.py b/functest/tests/unit/utils/test_env.py index 064ff988..49d2d974 100644 --- a/functest/tests/unit/utils/test_env.py +++ b/functest/tests/unit/utils/test_env.py @@ -16,7 +16,6 @@ import unittest from six.moves import reload_module from functest.utils import env -from functest.utils import constants class EnvTesting(unittest.TestCase): @@ -30,65 +29,27 @@ class EnvTesting(unittest.TestCase): def test_get_unset_unknown_env(self): del os.environ['FOO'] self.assertEqual(env.get('FOO'), None) - # Backward compatibilty (waiting for SDNVPN and SFC) - reload_module(env) - with self.assertRaises(AttributeError): - getattr(env.ENV, 'FOO') - reload_module(constants) - with self.assertRaises(AttributeError): - getattr(constants.CONST, 'FOO') def test_get_unknown_env(self): self.assertEqual(env.get('FOO'), 'foo') reload_module(env) - # Backward compatibilty (waiting for SDNVPN and SFC) - with self.assertRaises(AttributeError): - getattr(env.ENV, 'FOO') - reload_module(constants) - with self.assertRaises(AttributeError): - getattr(constants.CONST, 'FOO') def test_get_unset_env(self): del os.environ['CI_LOOP'] self.assertEqual( env.get('CI_LOOP'), env.INPUTS['CI_LOOP']) - # Backward compatibilty (waiting for SDNVPN and SFC) - reload_module(env) - self.assertEqual( - getattr(env.ENV, 'CI_LOOP'), env.INPUTS['CI_LOOP']) - reload_module(constants) - self.assertEqual( - getattr(constants.CONST, 'CI_LOOP'), - env.INPUTS['CI_LOOP']) def test_get_env(self): self.assertEqual( env.get('CI_LOOP'), 'weekly') - # Backward compatibilty (waiting for SDNVPN and SFC) - reload_module(env) - self.assertEqual(getattr(env.ENV, 'CI_LOOP'), 'weekly') - reload_module(constants) - self.assertEqual(getattr(constants.CONST, 'CI_LOOP'), 'weekly') def test_get_unset_env2(self): del os.environ['BUILD_TAG'] self.assertEqual( env.get('BUILD_TAG'), env.INPUTS['BUILD_TAG']) - # Backward compatibilty (waiting for SDNVPN and SFC) - reload_module(env) - self.assertEqual( - getattr(env.ENV, 'BUILD_TAG'), env.INPUTS['BUILD_TAG']) - reload_module(constants) - self.assertEqual( - getattr(constants.CONST, 'BUILD_TAG'), env.INPUTS['BUILD_TAG']) def test_get_env2(self): self.assertEqual(env.get('BUILD_TAG'), 'master') - # Backward compatibilty (waiting for SDNVPN and SFC) - reload_module(env) - self.assertEqual(getattr(env.ENV, 'BUILD_TAG'), 'master') - reload_module(env) - self.assertEqual(getattr(constants.CONST, 'BUILD_TAG'), 'master') if __name__ == "__main__": |