summaryrefslogtreecommitdiffstats
path: root/tests/unit/common/test_openstack_utils.py
diff options
context:
space:
mode:
authorchenjiankun <chenjiankun1@huawei.com>2017-02-20 16:05:29 +0000
committerchenjiankun <chenjiankun1@huawei.com>2017-02-24 02:40:30 +0000
commit8fdfd0f7ae809966e946b9425838e5c2c2fad215 (patch)
tree4f8c264e5d581c727656d835acedcecae01e1ff5 /tests/unit/common/test_openstack_utils.py
parent63d4d99cbe9fe57f71da6173eac4626107bfaa51 (diff)
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 <chenjiankun1@huawei.com>
Diffstat (limited to 'tests/unit/common/test_openstack_utils.py')
-rw-r--r--tests/unit/common/test_openstack_utils.py28
1 files changed, 16 insertions, 12 deletions
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()