diff options
author | Stamatis Katsaounis <mokats@intracom-telecom.com> | 2018-11-08 16:58:09 +0200 |
---|---|---|
committer | Dan Xu <xudan16@huawei.com> | 2018-11-14 14:31:50 +0000 |
commit | c92c49a9031602030f0f4d4fe2f99a9054eabaee (patch) | |
tree | e6ca8b2bbb9d80d064dfeae1e91ac86d50dc318b /dovetail/tests/unit/utils/test_openstack_utils.py | |
parent | 930ebc4af5c9895775443b9a0ab17a73dc35693c (diff) |
Add missing unit tests for utils files
JIRA: DOVETAIL-724
This patch adds unit tests which were missing from dovetail code base.
Furthermore it updates the test_parser existing unit test. Finally,
it fixes some minor issues in dovetail_utils itself.
Change-Id: I8fd7cd4f6b1ede11664914746d2279f062511639
Signed-off-by: Stamatis Katsaounis <mokats@intracom-telecom.com>
Diffstat (limited to 'dovetail/tests/unit/utils/test_openstack_utils.py')
-rw-r--r-- | dovetail/tests/unit/utils/test_openstack_utils.py | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/dovetail/tests/unit/utils/test_openstack_utils.py b/dovetail/tests/unit/utils/test_openstack_utils.py new file mode 100644 index 00000000..73583838 --- /dev/null +++ b/dovetail/tests/unit/utils/test_openstack_utils.py @@ -0,0 +1,87 @@ +#!/usr/bin/env python +# +# Copyright (c) 2018 mokats@intracom-telecom.com and others. +# +# All rights reserved. This program and the accompanying materials +# are made available under the terms of the Apache License, Version 2.0 +# which accompanies this distribution, and is available at +# http://www.apache.org/licenses/LICENSE-2.0 +## + +import unittest + +from mock import patch +import munch +import os_client_config +import shade + +import dovetail.utils.openstack_utils as os_dovetail_utils + +__author__ = 'Stamatis Katsaounis <mokats@intracom-telecom.com>' + + +class OpenStackUtilsTesting(unittest.TestCase): + + def setUp(self): + self.patcher1 = patch.object(shade, + 'OperatorCloud', autospec=True) + self.patcher2 = patch.object(os_client_config, + 'get_config', autospec=True) + self.cloud = self.patcher1.start().return_value + self.os_client_config = self.patcher2.start().return_value + self.os_dovetail = os_dovetail_utils.OS_Utils() + + def tearDown(self): + self.patcher1.stop() + self.patcher2.stop() + + def test_search_endpoints(self): + endpoint = munch.Munch({u'region_id': u'RegionOne', + u'url': u'http://127.0.0.1:8977/', + u'region': u'RegionOne', + u'enabled': True, + u'interface': u'public', + u'service_id': u'123456', + u'id': u'123456'}) + endpoints = [endpoint] + self.cloud.search_endpoints.return_value = endpoints + + expected = (True, endpoints) + result = self.os_dovetail.search_endpoints() + + self.assertEqual(expected, result) + + def test_search_endpoints_raised_exception(self): + errorMSG = 'Exception was raised' + exception = shade.exc.OpenStackCloudException(errorMSG) + self.cloud.search_endpoints.side_effect = exception + + expected = (False, errorMSG) + result = self.os_dovetail.search_endpoints() + + self.assertEqual(expected, result) + + def test_search_services(self): + service = munch.Munch({'description': u'OpenStack Identity Service', + 'service_type': u'identity', + 'type': u'identity', + 'enabled': True, + 'id': u'1bd26028c8714f3bb726126dc1ea62fc', + 'name': u'keystone'}) + services = [service] + self.cloud.search_services.return_value = services + + expected = (True, services) + result = self.os_dovetail.search_services() + + self.assertEqual(expected, result) + + def test_search_services_raised_exception(self): + errorMSG = 'Exception was raised' + exception = shade.exc.OpenStackCloudException(errorMSG) + self.cloud.search_services.side_effect = exception + + expected = (False, errorMSG) + result = self.os_dovetail.search_services() + + self.assertEqual(expected, result) |