aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests/unit
diff options
context:
space:
mode:
Diffstat (limited to 'functest/tests/unit')
-rw-r--r--functest/tests/unit/core/test_feature.py23
-rw-r--r--functest/tests/unit/utils/test_openstack_clean.py3
-rw-r--r--functest/tests/unit/utils/test_openstack_snapshot.py16
-rw-r--r--functest/tests/unit/utils/test_openstack_utils.py18
4 files changed, 40 insertions, 20 deletions
diff --git a/functest/tests/unit/core/test_feature.py b/functest/tests/unit/core/test_feature.py
index 0160c8e1..988981ef 100644
--- a/functest/tests/unit/core/test_feature.py
+++ b/functest/tests/unit/core/test_feature.py
@@ -38,12 +38,26 @@ class FeatureTestingBase(unittest.TestCase):
self.assertEqual(self.feature.start_time, 1)
self.assertEqual(self.feature.stop_time, 2)
+ def test_logger_module_ko(self):
+ with mock.patch('six.moves.builtins.open'):
+ self.feature = feature.Feature(
+ project_name=self._project_name, case_name=self._case_name)
+ self.assertEqual(self.feature.logger.name, self._case_name)
+
+ def test_logger_module(self):
+ with mock.patch('six.moves.builtins.open'):
+ self.feature = feature.Feature(
+ project_name=self._project_name, case_name=self._case_name,
+ run={'module': 'bar'})
+ self.assertEqual(self.feature.logger.name, 'bar')
+
class FeatureTesting(FeatureTestingBase):
def setUp(self):
- self.feature = feature.Feature(
- project_name=self._project_name, case_name=self._case_name)
+ with mock.patch('six.moves.builtins.open'):
+ self.feature = feature.Feature(
+ project_name=self._project_name, case_name=self._case_name)
def test_run_exc(self):
# pylint: disable=bad-continuation
@@ -60,8 +74,9 @@ class FeatureTesting(FeatureTestingBase):
class BashFeatureTesting(FeatureTestingBase):
def setUp(self):
- self.feature = feature.BashFeature(
- project_name=self._project_name, case_name=self._case_name)
+ with mock.patch('six.moves.builtins.open'):
+ self.feature = feature.BashFeature(
+ project_name=self._project_name, case_name=self._case_name)
@mock.patch("functest.utils.functest_utils.execute_command")
def test_run_no_cmd(self, mock_method=None):
diff --git a/functest/tests/unit/utils/test_openstack_clean.py b/functest/tests/unit/utils/test_openstack_clean.py
index fe7b50d4..5feed167 100644
--- a/functest/tests/unit/utils/test_openstack_clean.py
+++ b/functest/tests/unit/utils/test_openstack_clean.py
@@ -672,6 +672,7 @@ class OSCleanTesting(unittest.TestCase):
RegexMatch(" Removing "
"\s*\S+..."))
+ @mock.patch('functest.utils.openstack_clean.os_utils.get_glance_client')
@mock.patch('functest.utils.openstack_clean.os_utils.get_cinder_client')
@mock.patch('functest.utils.openstack_clean.os_utils'
'.get_keystone_client')
@@ -684,7 +685,7 @@ class OSCleanTesting(unittest.TestCase):
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_main_default(self, mock_logger_debug, mock_logger_info,
mock_creds, mock_nova, mock_neutron,
- mock_keystone, mock_cinder):
+ mock_keystone, mock_cinder, mock_glance):
with mock.patch('functest.utils.openstack_clean.remove_instances') \
as mock_remove_instances, \
diff --git a/functest/tests/unit/utils/test_openstack_snapshot.py b/functest/tests/unit/utils/test_openstack_snapshot.py
index d3f93994..33e74609 100644
--- a/functest/tests/unit/utils/test_openstack_snapshot.py
+++ b/functest/tests/unit/utils/test_openstack_snapshot.py
@@ -12,7 +12,7 @@ import unittest
from functest.utils import openstack_snapshot
-class OSTackerTesting(unittest.TestCase):
+class OSSnapshotTesting(unittest.TestCase):
def _get_instance(self, key):
mock_obj = mock.Mock()
@@ -26,6 +26,8 @@ class OSTackerTesting(unittest.TestCase):
self.test_list = [self._get_instance(1), self._get_instance(2)]
self.update_list = {'id1': 'name1', 'id2': 'name2'}
self.update_floatingips = {'id1': 'ip1', 'id2': 'ip2'}
+ self.floatingips_list = [{'id': 'id1', 'floating_ip_address': 'ip1'},
+ {'id': 'id2', 'floating_ip_address': 'ip2'}]
self.test_dict_list = [{'id': 'id1', 'name': 'name1', 'ip': 'ip1'},
{'id': 'id2', 'name': 'name2', 'ip': 'ip2'}]
@@ -138,8 +140,9 @@ class OSTackerTesting(unittest.TestCase):
@mock.patch('functest.utils.openstack_snapshot.logger.debug')
def test_get_floatingips(self, mock_logger_debug):
with mock.patch('functest.utils.openstack_snapshot.os_utils'
- '.get_floating_ips', return_value=self.test_list):
- resp = openstack_snapshot.get_floatinips(self.client)
+ '.get_floating_ips',
+ return_value=self.floatingips_list):
+ resp = openstack_snapshot.get_floatingips(self.client)
mock_logger_debug.assert_called_once_with("Getting Floating "
"IPs...")
self.assertDictEqual(resp, {'floatingips':
@@ -149,7 +152,7 @@ class OSTackerTesting(unittest.TestCase):
def test_get_floatingips_missing_floatingips(self, mock_logger_debug):
with mock.patch('functest.utils.openstack_snapshot.os_utils'
'.get_floating_ips', return_value=[]):
- resp = openstack_snapshot.get_floatinips(self.client)
+ resp = openstack_snapshot.get_floatingips(self.client)
mock_logger_debug.assert_called_once_with("Getting Floating "
"IPs...")
self.assertDictEqual(resp, {'floatingips': {}})
@@ -186,6 +189,7 @@ class OSTackerTesting(unittest.TestCase):
mock_logger_debug.assert_called_once_with("Getting tenants...")
self.assertDictEqual(resp, {'tenants': {}})
+ @mock.patch('functest.utils.openstack_clean.os_utils.get_glance_client')
@mock.patch('functest.utils.openstack_snapshot.os_utils.get_cinder_client')
@mock.patch('functest.utils.openstack_snapshot.os_utils'
'.get_keystone_client')
@@ -197,7 +201,7 @@ class OSTackerTesting(unittest.TestCase):
@mock.patch('functest.utils.openstack_snapshot.logger.debug')
def test_main_default(self, mock_logger_debug, mock_logger_info,
mock_creds, mock_nova, mock_neutron,
- mock_keystone, mock_cinder):
+ mock_keystone, mock_cinder, mock_glance):
with mock.patch('functest.utils.openstack_snapshot.get_instances',
return_value=self.update_list), \
mock.patch('functest.utils.openstack_snapshot.get_images',
@@ -212,7 +216,7 @@ class OSTackerTesting(unittest.TestCase):
return_value=self.update_list), \
mock.patch('functest.utils.openstack_snapshot.get_security_groups',
return_value=self.update_list), \
- mock.patch('functest.utils.openstack_snapshot.get_floatinips',
+ mock.patch('functest.utils.openstack_snapshot.get_floatingips',
return_value=self.update_floatingips), \
mock.patch('functest.utils.openstack_snapshot.get_users',
return_value=self.update_list), \
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py
index 33d0ee4e..74b49aaa 100644
--- a/functest/tests/unit/utils/test_openstack_utils.py
+++ b/functest/tests/unit/utils/test_openstack_utils.py
@@ -77,9 +77,8 @@ class OSUtilsTesting(unittest.TestCase):
self.availability_zone = mock_obj
mock_obj = mock.Mock()
- attrs = {'id': 'floating_id',
- 'zoneName': 'test_floating_ip',
- 'status': 'ok'}
+ attrs = {'floating_network_id': 'floating_id',
+ 'floating_ip_address': 'test_floating_ip'}
mock_obj.configure_mock(**attrs)
self.floating_ip = mock_obj
@@ -115,8 +114,6 @@ class OSUtilsTesting(unittest.TestCase):
'aggregates.delete.return_value': mock.Mock(),
'availability_zones.list.return_value':
[self.availability_zone],
- 'floating_ips.list.return_value': [self.floating_ip],
- 'floating_ips.delete.return_value': mock.Mock(),
'hypervisors.list.return_value': [self.hypervisor],
'create.return_value': mock.Mock(),
'add_security_group.return_value': mock.Mock(),
@@ -273,7 +270,10 @@ class OSUtilsTesting(unittest.TestCase):
'create_security_group.return_value': {'security_group':
self.sec_group},
'update_quota.return_value': mock.Mock(),
- 'delete_security_group.return_value': mock.Mock()
+ 'delete_security_group.return_value': mock.Mock(),
+ 'list_floatingips.return_value': {'floatingips':
+ [self.floating_ip]},
+ 'delete_floatingip.return_value': mock.Mock(),
}
self.neutron_client.configure_mock(**attrs)
@@ -723,7 +723,7 @@ class OSUtilsTesting(unittest.TestCase):
def test_get_floating_ips_default(self):
self.assertEqual(openstack_utils.
- get_floating_ips(self.nova_client),
+ get_floating_ips(self.neutron_client),
[self.floating_ip])
@mock.patch('functest.utils.openstack_utils.logger.error')
@@ -869,7 +869,7 @@ class OSUtilsTesting(unittest.TestCase):
def test_delete_floating_ip_default(self):
self.assertTrue(openstack_utils.
- delete_floating_ip(self.nova_client,
+ delete_floating_ip(self.neutron_client,
'floating_ip_id'))
@mock.patch('functest.utils.openstack_utils.logger.error')
@@ -1474,7 +1474,7 @@ class OSUtilsTesting(unittest.TestCase):
def test_get_images_default(self):
self.assertEqual(openstack_utils.
- get_images(self.nova_client),
+ get_images(self.glance_client),
[self.image])
@mock.patch('functest.utils.openstack_utils.logger.error')