From 8fdfd0f7ae809966e946b9425838e5c2c2fad215 Mon Sep 17 00:00:00 2001 From: chenjiankun Date: Mon, 20 Feb 2017 16:05:29 +0000 Subject: Add common method of openstack in openstack_utils JIRA: YARDSTICK-569 We have much redundancy code when using nova/neutron/glance... python client. So I write this code in openstack_utils for calling. Change-Id: I322b7577de4933246a15e6742ae5a28bea16eb02 Signed-off-by: chenjiankun --- tests/unit/common/test_openstack_utils.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) (limited to 'tests/unit/common') diff --git a/tests/unit/common/test_openstack_utils.py b/tests/unit/common/test_openstack_utils.py index d610e181c..b3dc2d9c4 100644 --- a/tests/unit/common/test_openstack_utils.py +++ b/tests/unit/common/test_openstack_utils.py @@ -22,21 +22,25 @@ class GetCredentialsTestCase(unittest.TestCase): @mock.patch('yardstick.common.openstack_utils.os') def test_get_credentials(self, mock_os): - mock_os.getenv.return_value = ('2') - openstack_utils.get_credentials() + with mock.patch.dict('os.environ', {'OS_IDENTITY_API_VERSION': '2'}, + clear=True): + openstack_utils.get_credentials() class GetHeatApiVersionTestCase(unittest.TestCase): - @mock.patch('yardstick.common.openstack_utils.os') - def test_get_heat_api_version(self, mock_os): + def test_get_heat_api_version_check_result(self): API = 'HEAT_API_VERSION' - openstack_utils.get_heat_api_version() - mock_os.getenv.assert_called_with(API) - - @mock.patch('yardstick.common.openstack_utils.os') - def test_get_heat_api_version(self, mock_os): - mock_os.getenv.return_value = ('2') expected_result = '2' - api_version = openstack_utils.get_heat_api_version() - self.assertEqual(api_version, expected_result) + + with mock.patch.dict('os.environ', {API: '2'}, clear=True): + api_version = openstack_utils.get_heat_api_version() + self.assertEqual(api_version, expected_result) + + +def main(): + unittest.main() + + +if __name__ == '__main__': + main() -- cgit 1.2.3-korg