]> review.fuel-infra Code Review - openstack-build/cinder-build.git/commitdiff
Fixes misuse of assertTrue in test scripts
authorZhongyue Luo <zhongyue.nah@intel.com>
Fri, 6 Sep 2013 04:10:28 +0000 (12:10 +0800)
committerZhongyue Luo <zhongyue.nah@intel.com>
Fri, 6 Sep 2013 04:13:20 +0000 (12:13 +0800)
Misuse of assertTrue in places where assertEqual should be used.

If assertTrue is used instead of assertEquals, the test will always pass
if the first argument's boolean cast is True. The second argument
passed to assertTrue() will be regarded as the error message
when the assertion fails. Using assertEqual will actually check
if two arguments are same value.

Fixes bug #1221517

Change-Id: I68f614164803729ea26e65f8868b0031e724d324

cinder/tests/brick/test_brick_connector.py
cinder/tests/brick/test_brick_linuxscsi.py

index 291896906331f16487e845edad5ff4948208811c..64dd298237ccddab68127a893802bbc86ce21446 100644 (file)
@@ -57,24 +57,19 @@ class ConnectorTestCase(test.TestCase):
 
     def test_factory(self):
         obj = connector.InitiatorConnector.factory('iscsi', None)
-        self.assertTrue(obj.__class__.__name__,
-                        "ISCSIConnector")
+        self.assertEqual(obj.__class__.__name__, "ISCSIConnector")
 
         obj = connector.InitiatorConnector.factory('fibre_channel', None)
-        self.assertTrue(obj.__class__.__name__,
-                        "FibreChannelConnector")
+        self.assertEqual(obj.__class__.__name__, "FibreChannelConnector")
 
         obj = connector.InitiatorConnector.factory('aoe', None)
-        self.assertTrue(obj.__class__.__name__,
-                        "AoEConnector")
+        self.assertEqual(obj.__class__.__name__, "AoEConnector")
 
         obj = connector.InitiatorConnector.factory('nfs', None)
-        self.assertTrue(obj.__class__.__name__,
-                        "RemoteFsConnector")
+        self.assertEqual(obj.__class__.__name__, "RemoteFsConnector")
 
         obj = connector.InitiatorConnector.factory('glusterfs', None)
-        self.assertTrue(obj.__class__.__name__,
-                        "RemoteFsConnector")
+        self.assertEqual(obj.__class__.__name__, "RemoteFsConnector")
 
         self.assertRaises(ValueError,
                           connector.InitiatorConnector.factory,
index 9b7b0db687da2ffe64d45fb81a5d2f51b7c207c5..55b1dd42ae7b922ee767f63bbbab801a0c1dce11 100644 (file)
@@ -47,7 +47,7 @@ class LinuxSCSITestCase(test.TestCase):
         disk_path = ("/dev/disk/by-path/ip-10.10.220.253:3260-"
                      "iscsi-iqn.2000-05.com.3pardata:21810002ac00383d-lun-0")
         name = self.linuxscsi.get_name_from_path(disk_path)
-        self.assertTrue(name, device_name)
+        self.assertEqual(name, device_name)
         self.stubs.Set(os.path, 'realpath', lambda x: "bogus")
         name = self.linuxscsi.get_name_from_path(disk_path)
         self.assertIsNone(name)