aboutsummaryrefslogtreecommitdiffstats
path: root/functest/tests
diff options
context:
space:
mode:
Diffstat (limited to 'functest/tests')
-rw-r--r--functest/tests/unit/cli/commands/test_cli_os.py5
-rw-r--r--functest/tests/unit/energy/test_functest_energy.py2
-rw-r--r--functest/tests/unit/test_utils.py14
-rw-r--r--functest/tests/unit/utils/test_openstack_clean.py37
-rw-r--r--functest/tests/unit/utils/test_openstack_snapshot.py2
-rw-r--r--functest/tests/unit/utils/test_openstack_utils.py5
6 files changed, 43 insertions, 22 deletions
diff --git a/functest/tests/unit/cli/commands/test_cli_os.py b/functest/tests/unit/cli/commands/test_cli_os.py
index 806bc931..434370a5 100644
--- a/functest/tests/unit/cli/commands/test_cli_os.py
+++ b/functest/tests/unit/cli/commands/test_cli_os.py
@@ -82,7 +82,7 @@ class CliOpenStackTesting(unittest.TestCase):
return_value=True)
@mock.patch('functest.cli.commands.cli_os.click.echo')
def test_snapshot_create_overwrite(self, mock_click_echo, mock_os_path):
- with mock.patch('__builtin__.raw_input', return_value="y") \
+ with mock.patch('six.moves.input', return_value="y") \
as mock_raw_input, \
mock.patch.object(self.cli_os, 'ping_endpoint'), \
mock.patch('functest.cli.commands.cli_os.os_snapshot.main') \
@@ -111,7 +111,8 @@ class CliOpenStackTesting(unittest.TestCase):
return_value=True)
@mock.patch('functest.cli.commands.cli_os.click.echo')
def test_snapshot_show_default(self, mock_click_echo, mock_os_path):
- with mock.patch('__builtin__.open', mock.mock_open(read_data='0')) \
+ with mock.patch('six.moves.builtins.open',
+ mock.mock_open(read_data='0')) \
as m:
self.cli_os.snapshot_file = self.snapshot_file
self.cli_os.snapshot_show()
diff --git a/functest/tests/unit/energy/test_functest_energy.py b/functest/tests/unit/energy/test_functest_energy.py
index 99110802..9e19a33d 100644
--- a/functest/tests/unit/energy/test_functest_energy.py
+++ b/functest/tests/unit/energy/test_functest_energy.py
@@ -266,7 +266,7 @@ class EnergyRecorderTest(unittest.TestCase):
with self.assertRaises(Exception) as context:
self.__decorated_method_with_ex()
self.assertTrue(
- self.exception_message_to_preserve in context.exception
+ self.exception_message_to_preserve in str(context.exception)
)
self.assertTrue(finish_mock.called)
diff --git a/functest/tests/unit/test_utils.py b/functest/tests/unit/test_utils.py
index e171db02..15904764 100644
--- a/functest/tests/unit/test_utils.py
+++ b/functest/tests/unit/test_utils.py
@@ -8,16 +8,22 @@
import re
-class RegexMatch(str):
+class RegexMatch(object):
+ def __init__(self, msg):
+ self.msg = msg
+
def __eq__(self, other):
- match = re.search(self, other)
+ match = re.search(self.msg, other)
if match:
return True
return False
-class SubstrMatch(str):
+class SubstrMatch(object):
+ def __init__(self, msg):
+ self.msg = msg
+
def __eq__(self, other):
- if self in other:
+ if self.msg in other:
return True
return False
diff --git a/functest/tests/unit/utils/test_openstack_clean.py b/functest/tests/unit/utils/test_openstack_clean.py
index 6ae7faa4..afd9120a 100644
--- a/functest/tests/unit/utils/test_openstack_clean.py
+++ b/functest/tests/unit/utils/test_openstack_clean.py
@@ -73,8 +73,9 @@ class OSCleanTesting(unittest.TestCase):
"-----------------"
"---------")
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances(self, mock_logger_debug):
+ def test_remove_instances(self, mock_logger_debug, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.test_list):
openstack_clean.remove_instances(self.client, self.update_list)
@@ -83,16 +84,19 @@ class OSCleanTesting(unittest.TestCase):
"instance and will "
"NOT be deleted.")
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_missing_instances(self, mock_logger_debug):
+ def test_remove_instances_missing_instances(self, mock_logger_debug,
+ *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=[]):
openstack_clean.remove_instances(self.client, self.update_list)
mock_logger_debug.assert_any_call("Removing Nova instances...")
mock_logger_debug.assert_any_call("No instances found.")
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_delete_success(self, mock_logger_debug):
+ def test_remove_instances_delete_success(self, mock_logger_debug, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.test_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -105,8 +109,10 @@ class OSCleanTesting(unittest.TestCase):
" '\s*\S+'"
" ..."))
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_pending_delete_success(self, mock_logger_debug):
+ def test_remove_instances_pending_delete_success(self, mock_logger_debug,
+ *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.deleted_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -118,8 +124,10 @@ class OSCleanTesting(unittest.TestCase):
" '\s*\S+'"
" ...").assert_not_called()
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.debug')
- def test_remove_instances_other_delete_success(self, mock_logger_debug):
+ def test_remove_instances_other_delete_success(self, mock_logger_debug,
+ *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.other_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -132,10 +140,11 @@ class OSCleanTesting(unittest.TestCase):
" '\s*\S+'"
" ..."))
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.logger.error')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_instances_delete_failed(self, mock_logger_debug,
- mock_logger_error):
+ mock_logger_error, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_instances', return_value=self.test_list), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -276,7 +285,7 @@ class OSCleanTesting(unittest.TestCase):
def test_remove_floatingips_delete_success(self, mock_logger_debug):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_floating_ips',
- return_value=self.floatingips_list), \
+ side_effect=[self.floatingips_list, None]), \
mock.patch('functest.utils.openstack_clean.os_utils'
'.delete_floating_ip', return_value=True):
openstack_clean.remove_floatingips(self.client, self.remove_list)
@@ -306,12 +315,13 @@ class OSCleanTesting(unittest.TestCase):
RegexMatch("Removing floating "
"IP \s*\S+ ..."))
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_networks(self, mock_logger_debug,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list',
return_value=self.test_dict_list), \
@@ -331,12 +341,13 @@ class OSCleanTesting(unittest.TestCase):
self.routers,
self.update_list)
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_networks_missing_networks(self, mock_logger_debug,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list', return_value=None), \
mock.patch('functest.utils.openstack_clean.os_utils'
@@ -354,12 +365,13 @@ class OSCleanTesting(unittest.TestCase):
self.routers,
self.update_list)
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.debug')
def test_remove_networks_delete_success(self, mock_logger_debug,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list',
@@ -385,6 +397,7 @@ class OSCleanTesting(unittest.TestCase):
self.routers,
self.remove_list)
+ @mock.patch('time.sleep')
@mock.patch('functest.utils.openstack_clean.remove_routers')
@mock.patch('functest.utils.openstack_clean.remove_ports')
@mock.patch('functest.utils.openstack_clean.logger.error')
@@ -392,7 +405,7 @@ class OSCleanTesting(unittest.TestCase):
def test_remove_networks_delete_failed(self, mock_logger_debug,
mock_logger_error,
mock_remove_ports,
- mock_remove_routers):
+ mock_remove_routers, *args):
with mock.patch('functest.utils.openstack_clean.os_utils'
'.get_network_list',
return_value=self.test_dict_list), \
@@ -711,7 +724,7 @@ class OSCleanTesting(unittest.TestCase):
as mock_remove_tenants, \
mock.patch('functest.utils.openstack_clean.yaml.safe_load',
return_value=mock.Mock()), \
- mock.patch('__builtin__.open', mock.mock_open()) as m:
+ mock.patch('six.moves.builtins.open', mock.mock_open()) as m:
openstack_clean.main()
self.assertTrue(mock_remove_instances)
self.assertTrue(mock_remove_images)
diff --git a/functest/tests/unit/utils/test_openstack_snapshot.py b/functest/tests/unit/utils/test_openstack_snapshot.py
index 33e74609..919b28c6 100644
--- a/functest/tests/unit/utils/test_openstack_snapshot.py
+++ b/functest/tests/unit/utils/test_openstack_snapshot.py
@@ -222,7 +222,7 @@ class OSSnapshotTesting(unittest.TestCase):
return_value=self.update_list), \
mock.patch('functest.utils.openstack_snapshot.get_tenants',
return_value=self.update_list), \
- mock.patch('__builtin__.open', mock.mock_open()) as m:
+ mock.patch('six.moves.builtins.open', mock.mock_open()) as m:
openstack_snapshot.main()
mock_logger_info.assert_called_once_with("Generating OpenStack "
"snapshot...")
diff --git a/functest/tests/unit/utils/test_openstack_utils.py b/functest/tests/unit/utils/test_openstack_utils.py
index 307cbe37..01085bb7 100644
--- a/functest/tests/unit/utils/test_openstack_utils.py
+++ b/functest/tests/unit/utils/test_openstack_utils.py
@@ -365,7 +365,8 @@ class OSUtilsTesting(unittest.TestCase):
except:
pass
f = 'rc_file'
- with mock.patch('__builtin__.open', mock.mock_open(read_data=msg),
+ with mock.patch('six.moves.builtins.open',
+ mock.mock_open(read_data=msg),
create=True) as m:
m.return_value.__iter__ = lambda self: iter(self.readline, '')
openstack_utils.source_credentials(f)
@@ -1460,7 +1461,7 @@ class OSUtilsTesting(unittest.TestCase):
return_value=True), \
mock.patch('functest.utils.openstack_utils.get_image_id',
return_value=''), \
- mock.patch('__builtin__.open',
+ mock.patch('six.moves.builtins.open',
mock.mock_open(read_data='1')) as m:
self.assertEqual(openstack_utils.
create_glance_image(self.glance_client,