From 3519434b5b78b1422d0f24c4dbdcb68dcf2d2f4d Mon Sep 17 00:00:00 2001 From: Zhao Chao Date: Mon, 26 Feb 2018 13:45:50 +0800 Subject: [PATCH] Fix incorrect usage of assertTrue Previously assertTrue is incorrectly used as assertEqual or assertIsNotNone, this patch fixes. Some assertEqual around the changes introduced by this patch are also updated to use the proper arguments convention, from assertEqual(observed, expected) to assertEqual(expected, observed) Change-Id: If1d75a850594eff72b69e265a25505382e82022b Signed-off-by: Zhao Chao --- .../tests/integration/tests/volumes/driver.py | 22 +++++++++---------- .../cluster/test_cluster_pxc_controller.py | 2 +- .../cluster/test_cluster_redis_controller.py | 2 +- .../test_cluster_vertica_controller.py | 2 +- .../common/test_common_extensions.py | 8 +++---- 5 files changed, 18 insertions(+), 18 deletions(-) diff --git a/integration/tests/integration/tests/volumes/driver.py b/integration/tests/integration/tests/volumes/driver.py index 340b721cab..3e08459737 100644 --- a/integration/tests/integration/tests/volumes/driver.py +++ b/integration/tests/integration/tests/volumes/driver.py @@ -217,8 +217,8 @@ class AddVolumeFailure(VolumeTest): snapshot_id=None, name=name, description=desc) self.assertEqual(HUGE_VOLUME, volume["size"]) - self.assertTrue("creating", volume["status"]) - self.assertTrue("detached", volume["attach_status"]) + self.assertEqual("creating", volume["status"]) + self.assertEqual("detached", volume["attach_status"]) self.storyFail.volume = volume self.storyFail.volume_id = volume["id"] @@ -236,8 +236,8 @@ class AfterVolumeFailureIsAdded(VolumeTest): """Wait until the volume is a FAILURE.""" volume = poll_until(lambda: self.storyFail.get_volume(), lambda volume: volume["status"] != "creating") - self.assertEqual(volume["status"], "error") - self.assertTrue(volume["attach_status"], "detached") + self.assertEqual("error", volume["status"]) + self.assertEqual("detached", volume["attach_status"]) @time_out(60) def test_mgmt_volume_check(self): @@ -267,8 +267,8 @@ class AddVolume(VolumeTest): snapshot_id=None, name=name, description=desc) self.assert_volume_as_expected(volume) - self.assertTrue("creating", volume["status"]) - self.assertTrue("detached", volume["attach_status"]) + self.assertEqual("creating", volume["status"]) + self.assertEqual("detached", volume["attach_status"]) self.story.volume = volume self.story.volume_id = volume["id"] @@ -286,9 +286,9 @@ class AfterVolumeIsAdded(VolumeTest): """Wait until the volume is finished provisioning.""" volume = poll_until(lambda: self.story.get_volume(), lambda volume: volume["status"] != "creating") - self.assertEqual(volume["status"], "available") + self.assertEqual("available", volume["status"]) self.assert_volume_as_expected(volume) - self.assertTrue(volume["attach_status"], "detached") + self.assertEqual("detached", volume["attach_status"]) @time_out(60) def test_mgmt_volume_check(self): @@ -404,9 +404,9 @@ class ResizeVolume(VolumeTest): volume = poll_until(lambda: self.story.get_volume(), lambda volume: volume["status"] == "resized") - self.assertEqual(volume["status"], "resized") - self.assertTrue(volume["attach_status"], "attached") - self.assertTrue(volume['size'], self.story.resize_volume_size) + self.assertEqual("resized", volume["status"]) + self.assertEqual("attached", volume["attach_status"]) + self.assertEqual(self.story.resize_volume_size, volume['size']) @time_out(300) def test_resizefs_rescan(self): diff --git a/trove/tests/unittests/cluster/test_cluster_pxc_controller.py b/trove/tests/unittests/cluster/test_cluster_pxc_controller.py index 133c4b4adb..89edc3c975 100644 --- a/trove/tests/unittests/cluster/test_cluster_pxc_controller.py +++ b/trove/tests/unittests/cluster/test_cluster_pxc_controller.py @@ -60,7 +60,7 @@ class TestClusterController(trove_testtools.TestCase): schema = self.controller.get_schema('create', self.cluster) self.assertIsNotNone(schema) self.assertIn('cluster', schema['properties']) - self.assertTrue('cluster') + self.assertIsNotNone(schema['properties']['cluster']) def test_validate_create(self): body = self.cluster diff --git a/trove/tests/unittests/cluster/test_cluster_redis_controller.py b/trove/tests/unittests/cluster/test_cluster_redis_controller.py index 3161a87d1a..80159cebad 100644 --- a/trove/tests/unittests/cluster/test_cluster_redis_controller.py +++ b/trove/tests/unittests/cluster/test_cluster_redis_controller.py @@ -74,7 +74,7 @@ class TestClusterController(trove_testtools.TestCase): schema = self.controller.get_schema('create', self.cluster) self.assertIsNotNone(schema) self.assertIn('cluster', schema['properties']) - self.assertTrue('cluster') + self.assertIsNotNone(schema['properties']['cluster']) def test_validate_create(self): body = self.cluster diff --git a/trove/tests/unittests/cluster/test_cluster_vertica_controller.py b/trove/tests/unittests/cluster/test_cluster_vertica_controller.py index da0d6cb98d..8929870144 100644 --- a/trove/tests/unittests/cluster/test_cluster_vertica_controller.py +++ b/trove/tests/unittests/cluster/test_cluster_vertica_controller.py @@ -60,7 +60,7 @@ class TestClusterController(trove_testtools.TestCase): schema = self.controller.get_schema('create', self.cluster) self.assertIsNotNone(schema) self.assertIn('cluster', schema['properties']) - self.assertTrue('cluster') + self.assertIsNotNone(schema['properties']['cluster']) def test_validate_create(self): body = self.cluster diff --git a/trove/tests/unittests/common/test_common_extensions.py b/trove/tests/unittests/common/test_common_extensions.py index e23d9a892e..813c936e47 100644 --- a/trove/tests/unittests/common/test_common_extensions.py +++ b/trove/tests/unittests/common/test_common_extensions.py @@ -111,7 +111,7 @@ class TestRootController(trove_testtools.TestCase): root_controller.root_index = Mock(return_value=ret) service_load_root_controller.return_value = root_controller - self.assertTrue(ret, self.controller.index(req, tenant_id, uuid)) + self.assertEqual(ret, self.controller.index(req, tenant_id, uuid)) service_get_datastore.assert_called_with(tenant_id, uuid) service_load_root_controller.assert_called_with(ds_manager) root_controller.root_index.assert_called_with( @@ -135,7 +135,7 @@ class TestRootController(trove_testtools.TestCase): root_controller.root_create = Mock(return_value=ret) service_load_root_controller.return_value = root_controller - self.assertTrue( + self.assertEqual( ret, self.controller.create(req, tenant_id, uuid, body=body)) service_get_datastore.assert_called_with(tenant_id, uuid) service_load_root_controller.assert_called_with(ds_manager) @@ -280,8 +280,8 @@ class TestClusterRootController(trove_testtools.TestCase): cluster_instances = [db_inst_1, db_inst_2] mock_find_all.return_value.all.return_value = cluster_instances ret = self.controller._get_cluster_instance_id(tenant_id, cluster_id) - self.assertTrue(db_inst_1.id, ret[0]) - self.assertTrue(cluster_instances, ret[1]) + self.assertEqual(db_inst_1.id, ret[0]) + self.assertEqual([db_inst_1.id, db_inst_2.id], ret[1]) @patch.object(models.ClusterRoot, "create") def test_instance_root_create(self, mock_cluster_root_create):