summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJenkins <jenkins@review.openstack.org>2017-06-18 20:45:32 +0000
committerGerrit Code Review <review@openstack.org>2017-06-18 20:45:32 +0000
commit1fa43b8f79e4cbb8781d3a87d854f9f871bef579 (patch)
treee8b25a363a692b02cf63137a22da27098f798c77
parentb8079d6f70048bee196924742970ac45e74d26f4 (diff)
parent7a84172cb2bbd4b65781f130ce8c3393f399286c (diff)
Merge "Tests: Disallow use of assertTrue(str)"
-rw-r--r--cinder/test.py7
-rw-r--r--cinder/tests/unit/message/test_defined_messages.py4
-rw-r--r--cinder/tests/unit/test_db_api.py2
-rw-r--r--cinder/tests/unit/test_test_utils.py1
-rw-r--r--cinder/tests/unit/volume/drivers/ibm/test_ibm_storage.py2
-rw-r--r--cinder/tests/unit/volume/drivers/test_coprhd.py6
-rw-r--r--cinder/tests/unit/volume/drivers/test_gpfs.py12
-rw-r--r--cinder/tests/unit/volume/test_snapshot.py5
8 files changed, 22 insertions, 17 deletions
diff --git a/cinder/test.py b/cinder/test.py
index 0f8f129..d0821be 100644
--- a/cinder/test.py
+++ b/cinder/test.py
@@ -346,6 +346,13 @@ class TestCase(testtools.TestCase):
346 self.assertEqual(call[0], posargs[0]) 346 self.assertEqual(call[0], posargs[0])
347 self.assertEqual(call[1], posargs[2]) 347 self.assertEqual(call[1], posargs[2])
348 348
349 def assertTrue(self, x, *args, **kwargs):
350 if isinstance(x, six.string_types):
351 raise AssertionError("%s (%s) is a string. Use a more "
352 "specific assertion such as assertEqual." %
353 (x, type(x)))
354 super(TestCase, self).assertTrue(x, *args, **kwargs)
355
349 356
350class ModelsObjectComparatorMixin(object): 357class ModelsObjectComparatorMixin(object):
351 def _dict_from_object(self, obj, ignored_keys): 358 def _dict_from_object(self, obj, ignored_keys):
diff --git a/cinder/tests/unit/message/test_defined_messages.py b/cinder/tests/unit/message/test_defined_messages.py
index 7c5a989..3892309 100644
--- a/cinder/tests/unit/message/test_defined_messages.py
+++ b/cinder/tests/unit/message/test_defined_messages.py
@@ -39,5 +39,5 @@ class DefinedMessagesTest(test.TestCase):
39 for attr_name in dir(defined_messages.EventIds): 39 for attr_name in dir(defined_messages.EventIds):
40 if not attr_name.startswith('_'): 40 if not attr_name.startswith('_'):
41 value = getattr(defined_messages.EventIds, attr_name) 41 value = getattr(defined_messages.EventIds, attr_name)
42 self.assertTrue(defined_messages.event_id_message_map.get( 42 msg = defined_messages.event_id_message_map.get(value)
43 value)) 43 self.assertGreater(len(msg), 1)
diff --git a/cinder/tests/unit/test_db_api.py b/cinder/tests/unit/test_db_api.py
index 58ab9cc..6ac0673 100644
--- a/cinder/tests/unit/test_db_api.py
+++ b/cinder/tests/unit/test_db_api.py
@@ -2525,7 +2525,7 @@ class DBAPIBackupTestCase(BaseTest):
2525 def test_backup_create(self): 2525 def test_backup_create(self):
2526 values = self._get_values() 2526 values = self._get_values()
2527 for i, backup in enumerate(self.created): 2527 for i, backup in enumerate(self.created):
2528 self.assertTrue(backup['id']) 2528 self.assertEqual(36, len(backup['id'])) # dynamic UUID
2529 self._assertEqualObjects(values[i], backup, self._ignored_keys) 2529 self._assertEqualObjects(values[i], backup, self._ignored_keys)
2530 2530
2531 def test_backup_get(self): 2531 def test_backup_get(self):
diff --git a/cinder/tests/unit/test_test_utils.py b/cinder/tests/unit/test_test_utils.py
index 0eeba46..ae3606e 100644
--- a/cinder/tests/unit/test_test_utils.py
+++ b/cinder/tests/unit/test_test_utils.py
@@ -39,5 +39,4 @@ class TestUtilsTestCase(test.TestCase):
39 self.assertEqual([], ctxt.service_catalog) 39 self.assertEqual([], ctxt.service_catalog)
40 self.assertEqual('no', ctxt.read_deleted) 40 self.assertEqual('no', ctxt.read_deleted)
41 41
42 self.assertTrue(ctxt.read_deleted)
43 self.assertTrue(ctxt.is_admin) 42 self.assertTrue(ctxt.is_admin)
diff --git a/cinder/tests/unit/volume/drivers/ibm/test_ibm_storage.py b/cinder/tests/unit/volume/drivers/ibm/test_ibm_storage.py
index 65a4fd5..a198384 100644
--- a/cinder/tests/unit/volume/drivers/ibm/test_ibm_storage.py
+++ b/cinder/tests/unit/volume/drivers/ibm/test_ibm_storage.py
@@ -536,7 +536,7 @@ class IBMStorageVolumeDriverTest(test.TestCase):
536 self.driver.create_volume(volume) 536 self.driver.create_volume(volume)
537 ret = self.driver.retype(ctxt, volume, new_type, diff, host) 537 ret = self.driver.retype(ctxt, volume, new_type, diff, host)
538 self.assertTrue(ret) 538 self.assertTrue(ret)
539 self.assertTrue(volume['easytier']) 539 self.assertEqual('1', volume['easytier'])
540 540
541 def test_retype_fail_on_exception(self): 541 def test_retype_fail_on_exception(self):
542 """Test that retype fails on exception.""" 542 """Test that retype fails on exception."""
diff --git a/cinder/tests/unit/volume/drivers/test_coprhd.py b/cinder/tests/unit/volume/drivers/test_coprhd.py
index a4b8e7a..d2eaa16 100644
--- a/cinder/tests/unit/volume/drivers/test_coprhd.py
+++ b/cinder/tests/unit/volume/drivers/test_coprhd.py
@@ -444,7 +444,7 @@ class EMCCoprHDISCSIDriverTest(test.TestCase):
444 444
445 def test_get_volume_stats(self): 445 def test_get_volume_stats(self):
446 vol_stats = self.driver.get_volume_stats(True) 446 vol_stats = self.driver.get_volume_stats(True)
447 self.assertTrue(vol_stats['free_capacity_gb'], 'unknown') 447 self.assertEqual('unknown', vol_stats['free_capacity_gb'])
448 448
449 def test_create_volume_clone(self): 449 def test_create_volume_clone(self):
450 src_volume_data = get_test_volume_data(self.volume_type_id) 450 src_volume_data = get_test_volume_data(self.volume_type_id)
@@ -610,7 +610,7 @@ class EMCCoprHDFCDriverTest(test.TestCase):
610 610
611 def test_get_volume_stats(self): 611 def test_get_volume_stats(self):
612 vol_stats = self.driver.get_volume_stats(True) 612 vol_stats = self.driver.get_volume_stats(True)
613 self.assertTrue(vol_stats['free_capacity_gb'], 'unknown') 613 self.assertEqual('unknown', vol_stats['free_capacity_gb'])
614 614
615 def test_create_volume_clone(self): 615 def test_create_volume_clone(self):
616 616
@@ -827,7 +827,7 @@ class EMCCoprHDScaleIODriverTest(test.TestCase):
827 827
828 def test_get_volume_stats(self): 828 def test_get_volume_stats(self):
829 vol_stats = self.driver.get_volume_stats(True) 829 vol_stats = self.driver.get_volume_stats(True)
830 self.assertTrue(vol_stats['free_capacity_gb'], 'unknown') 830 self.assertEqual('unknown', vol_stats['free_capacity_gb'])
831 831
832 def test_create_volume_clone(self): 832 def test_create_volume_clone(self):
833 833
diff --git a/cinder/tests/unit/volume/drivers/test_gpfs.py b/cinder/tests/unit/volume/drivers/test_gpfs.py
index f33d856..1e4f21d 100644
--- a/cinder/tests/unit/volume/drivers/test_gpfs.py
+++ b/cinder/tests/unit/volume/drivers/test_gpfs.py
@@ -245,8 +245,8 @@ class GPFSDriverTestCase(test.TestCase):
245 'yes ' 245 'yes '
246 ' 10485760 9953792 ( 95%) ' 246 ' 10485760 9953792 ( 95%) '
247 '10485760 9954560 ( 95%)', '') 247 '10485760 9954560 ( 95%)', '')
248 self.assertTrue(self.driver._gpfs_device, 248 self.assertEqual('/dev/gpfs', self.driver._gpfs_device)
249 self.driver._verify_gpfs_pool('/dev/gpfs')) 249 self.assertTrue(self.driver._verify_gpfs_pool('/dev/gpfs'))
250 250
251 @mock.patch('cinder.utils.execute') 251 @mock.patch('cinder.utils.execute')
252 def test_verify_gpfs_pool_fail_pool(self, mock_exec): 252 def test_verify_gpfs_pool_fail_pool(self, mock_exec):
@@ -260,8 +260,8 @@ class GPFSDriverTestCase(test.TestCase):
260 'yes' 260 'yes'
261 ' 10485760 9953792 ( 95%)' 261 ' 10485760 9953792 ( 95%)'
262 ' 10485760 9954560 ( 95%)', '') 262 ' 10485760 9954560 ( 95%)', '')
263 self.assertTrue(self.driver._gpfs_device, 263 self.assertEqual('/dev/gpfs', self.driver._gpfs_device)
264 self.driver._verify_gpfs_pool('/dev/gpfs')) 264 self.assertTrue(self.driver._verify_gpfs_pool('/dev/gpfs'))
265 265
266 @mock.patch('cinder.utils.execute') 266 @mock.patch('cinder.utils.execute')
267 def test_verify_gpfs_pool_fail_raise(self, mock_exec): 267 def test_verify_gpfs_pool_fail_raise(self, mock_exec):
@@ -1142,11 +1142,11 @@ class GPFSDriverTestCase(test.TestCase):
1142 stats = self.driver.get_volume_stats() 1142 stats = self.driver.get_volume_stats()
1143 self.assertEqual('GPFS', stats['volume_backend_name']) 1143 self.assertEqual('GPFS', stats['volume_backend_name'])
1144 self.assertEqual('file', stats['storage_protocol']) 1144 self.assertEqual('file', stats['storage_protocol'])
1145 self.assertTrue(stats['gpfs_encryption_rest']) 1145 self.assertEqual('True', stats['gpfs_encryption_rest'])
1146 stats = self.driver.get_volume_stats(True) 1146 stats = self.driver.get_volume_stats(True)
1147 self.assertEqual('GPFS', stats['volume_backend_name']) 1147 self.assertEqual('GPFS', stats['volume_backend_name'])
1148 self.assertEqual('file', stats['storage_protocol']) 1148 self.assertEqual('file', stats['storage_protocol'])
1149 self.assertTrue(stats['gpfs_encryption_rest']) 1149 self.assertEqual('True', stats['gpfs_encryption_rest'])
1150 1150
1151 @mock.patch('cinder.utils.execute') 1151 @mock.patch('cinder.utils.execute')
1152 def test_get_gpfs_encryption_status_true(self, mock_exec): 1152 def test_get_gpfs_encryption_status_true(self, mock_exec):
diff --git a/cinder/tests/unit/volume/test_snapshot.py b/cinder/tests/unit/volume/test_snapshot.py
index b4f6ef2..4f1d497 100644
--- a/cinder/tests/unit/volume/test_snapshot.py
+++ b/cinder/tests/unit/volume/test_snapshot.py
@@ -389,9 +389,8 @@ class SnapshotTestCase(base.BaseVolumeTestCase):
389 vol_glance_meta = db.volume_glance_metadata_get(ctxt, volume_id) 389 vol_glance_meta = db.volume_glance_metadata_get(ctxt, volume_id)
390 self.assertTrue(vol_glance_meta) 390 self.assertTrue(vol_glance_meta)
391 snap = create_snapshot(volume_id) 391 snap = create_snapshot(volume_id)
392 snap_stat = snap.status 392 self.assertEqual(36, len(snap.id)) # dynamically-generated UUID
393 self.assertTrue(snap.id) 393 self.assertEqual('creating', snap.status)
394 self.assertTrue(snap_stat)
395 394
396 # set to return DB exception 395 # set to return DB exception
397 with mock.patch.object(db, 'volume_glance_metadata_copy_to_snapshot')\ 396 with mock.patch.object(db, 'volume_glance_metadata_copy_to_snapshot')\