From 9afd7d0875f96f0ada6f683e9e229f0f42004acf Mon Sep 17 00:00:00 2001 From: Bin Zhou Date: Fri, 2 Sep 2016 13:23:36 +0800 Subject: [PATCH] Modify use of assertTrue(A in B) Developers should use assertIn(A, B) instead of assertTrue(A in B ). TrivialFix Change-Id: I93f3c540e4cc9015162283ea71813613a13e3555 --- horizon/test/tests/messages.py | 4 +-- horizon/test/tests/middleware.py | 32 +++++++++---------- horizon/test/tests/selenium_tests.py | 2 +- horizon/test/tests/tables.py | 4 +-- .../dashboards/admin/info/tests.py | 6 ++-- .../dashboards/admin/metadata_defs/tests.py | 8 ++--- .../dashboards/admin/metering/tests.py | 4 +-- .../volumes/volume_types/qos_specs/tests.py | 2 +- .../dashboards/project/instances/tests.py | 2 +- .../dashboards/project/overview/tests.py | 2 +- .../test/api_tests/cinder_tests.py | 2 +- .../test/tests/policy_backend.py | 4 +-- openstack_dashboard/test/tests/templates.py | 12 +++---- 13 files changed, 42 insertions(+), 42 deletions(-) diff --git a/horizon/test/tests/messages.py b/horizon/test/tests/messages.py index fb4a9b73bb..50f30ae25c 100644 --- a/horizon/test/tests/messages.py +++ b/horizon/test/tests/messages.py @@ -28,7 +28,7 @@ class MessageTests(test.TestCase): req = self.request string = "Giant ants are attacking San Francisco!" expected = ["error", force_text(string), ""] - self.assertTrue("async_messages" in req.horizon) + self.assertIn("async_messages", req.horizon) self.assertItemsEqual(req.horizon['async_messages'], []) req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' messages.error(req, string) @@ -42,7 +42,7 @@ class MessageTests(test.TestCase): req = self.request string = mark_safe("We are now safe from ants! Go here!") expected = ["error", force_text(string), " safe"] - self.assertTrue("async_messages" in req.horizon) + self.assertIn("async_messages", req.horizon) self.assertItemsEqual(req.horizon['async_messages'], []) req.META['HTTP_X_REQUESTED_WITH'] = 'XMLHttpRequest' messages.error(req, string) diff --git a/horizon/test/tests/middleware.py b/horizon/test/tests/middleware.py index b9a067ed55..8bc29e7ff4 100644 --- a/horizon/test/tests/middleware.py +++ b/horizon/test/tests/middleware.py @@ -131,14 +131,14 @@ class OperationLogMiddlewareTest(test.TestCase): self.assertEqual(302, resp.status_code) log_args = mock_logger.info.call_args[0] logging_str = log_args[0] % log_args[1] - self.assertTrue(request.user.username in logging_str) - self.assertTrue(self.http_referer in logging_str) - self.assertTrue(settings.LOGIN_URL in logging_str) - self.assertTrue('POST' in logging_str) - self.assertTrue('302' in logging_str) + self.assertIn(request.user.username, logging_str) + self.assertIn(self.http_referer, logging_str) + self.assertIn(settings.LOGIN_URL, logging_str) + self.assertIn('POST', logging_str) + self.assertIn('302', logging_str) post_data = ['"username": "admin"', '"password": "********"'] for data in post_data: - self.assertTrue(data in logging_str) + self.assertIn(data, logging_str) @override_settings(OPERATION_LOG_ENABLED=True) @override_settings(OPERATION_LOG_OPTIONS={'target_methods': ['GET']}) @@ -154,11 +154,11 @@ class OperationLogMiddlewareTest(test.TestCase): self.assertEqual(302, resp.status_code) log_args = mock_logger.info.call_args[0] logging_str = log_args[0] % log_args[1] - self.assertTrue(request.user.username in logging_str) - self.assertTrue(self.http_referer in logging_str) - self.assertTrue(request.path in logging_str) - self.assertTrue('GET' in logging_str) - self.assertTrue('302' in logging_str) + self.assertIn(request.user.username, logging_str) + self.assertIn(self.http_referer, logging_str) + self.assertIn(request.path, logging_str) + self.assertIn('GET', logging_str) + self.assertIn('302', logging_str) @override_settings(OPERATION_LOG_ENABLED=True) @patch(('horizon.middleware.operation_log.OperationLogMiddleware.' @@ -186,10 +186,10 @@ class OperationLogMiddlewareTest(test.TestCase): log_args = mock_logger.info.call_args[0] logging_str = log_args[0] % log_args[1] self.assertTrue(mock_logger.info.called) - self.assertTrue(request.user.username in logging_str) - self.assertTrue(self.http_referer in logging_str) - self.assertTrue(settings.LOGIN_URL in logging_str) - self.assertTrue('Unexpected error occurred.' in logging_str) + self.assertIn(request.user.username, logging_str) + self.assertIn(self.http_referer, logging_str) + self.assertIn(settings.LOGIN_URL, logging_str) + self.assertIn('Unexpected error occurred.', logging_str) post_data = ['"username": "admin"', '"password": "********"'] for data in post_data: - self.assertTrue(data in logging_str) + self.assertIn(data, logging_str) diff --git a/horizon/test/tests/selenium_tests.py b/horizon/test/tests/selenium_tests.py index 1c776b5943..77af4c9735 100644 --- a/horizon/test/tests/selenium_tests.py +++ b/horizon/test/tests/selenium_tests.py @@ -27,7 +27,7 @@ class BrowserTests(test.SeleniumTestCase): failures = driver.find_element_by_class_name("jasmine-bar").text return failures - self.assertTrue('0 failures' in wait.until(jasmine_legacy_done)) + self.assertIn('0 failures', wait.until(jasmine_legacy_done)) @override_settings( diff --git a/horizon/test/tests/tables.py b/horizon/test/tests/tables.py index be073d2108..22cfeb0230 100644 --- a/horizon/test/tests/tables.py +++ b/horizon/test/tests/tables.py @@ -597,7 +597,7 @@ class DataTableTests(test.TestCase): # Ensure data is not cached on the column across table instances self.table = MyTable(self.request, TEST_DATA_2) row = self.table.get_rows()[0] - self.assertTrue("down" in row.cells['status'].value) + self.assertIn("down", row.cells['status'].value) def test_table_row(self): self.table = MyTable(self.request, TEST_DATA) @@ -1394,7 +1394,7 @@ class DataTableTests(test.TestCase): # Ensure data is not cached on the column across table instances self.table = MyTable(self.request, TEST_DATA_6) row = self.table.get_rows()[0] - self.assertTrue("down" in row.cells['status'].value) + self.assertIn("down", row.cells['status'].value) def test_broken_filter(self): class MyTableBrokenFilter(MyTable): diff --git a/openstack_dashboard/dashboards/admin/info/tests.py b/openstack_dashboard/dashboards/admin/info/tests.py index 70b6d6b3b6..61570d028d 100644 --- a/openstack_dashboard/dashboards/admin/info/tests.py +++ b/openstack_dashboard/dashboards/admin/info/tests.py @@ -60,9 +60,9 @@ class SystemInfoViewTests(test.BaseAdminViewTests): def test_index(self): res = self._test_base_index() services_tab = res.context['tab_group'].get_tab('services') - self.assertTrue("region" in services_tab._tables['services'].data[0]) - self.assertTrue("endpoints" in - services_tab._tables['services'].data[0]) + self.assertIn("region", services_tab._tables['services'].data[0]) + self.assertIn("endpoints", + services_tab._tables['services'].data[0]) self.mox.VerifyAll() def test_neutron_index(self): diff --git a/openstack_dashboard/dashboards/admin/metadata_defs/tests.py b/openstack_dashboard/dashboards/admin/metadata_defs/tests.py index 4718aa0bfd..68e3a55fd1 100644 --- a/openstack_dashboard/dashboards/admin/metadata_defs/tests.py +++ b/openstack_dashboard/dashboards/admin/metadata_defs/tests.py @@ -102,10 +102,10 @@ class MetadataDefinitionsView(test.BaseAdminViewTests): for i in [1, 2]: row_actions = ns_table.get_row_actions(namespaces[i]) self.assertTrue(len(row_actions), 2) - self.assertTrue('delete' in - [a.name for a in row_actions]) - self.assertTrue('manage_resource_types' in - [a.name for a in row_actions]) + self.assertIn('delete', + [a.name for a in row_actions]) + self.assertIn('manage_resource_types', + [a.name for a in row_actions]) @test.create_stubs({api.glance: ('metadefs_namespace_get',)}) def test_metadata_defs_get(self): diff --git a/openstack_dashboard/dashboards/admin/metering/tests.py b/openstack_dashboard/dashboards/admin/metering/tests.py index aca34a2608..7cecbadd49 100644 --- a/openstack_dashboard/dashboards/admin/metering/tests.py +++ b/openstack_dashboard/dashboards/admin/metering/tests.py @@ -64,10 +64,10 @@ class MeteringLineChartTabTests(test.BaseAdminViewTests): def _verify_series(self, series, value, date, expected_names): data = jsonutils.loads(series) - self.assertTrue('series' in data) + self.assertIn('series', data) self.assertEqual(len(data['series']), len(expected_names)) for d in data['series']: - self.assertTrue('data' in d) + self.assertIn('data', d) self.assertEqual(len(d['data']), 1) self.assertAlmostEqual(d['data'][0].get('y'), value) self.assertEqual(d['data'][0].get('x'), date) diff --git a/openstack_dashboard/dashboards/admin/volumes/volume_types/qos_specs/tests.py b/openstack_dashboard/dashboards/admin/volumes/volume_types/qos_specs/tests.py index b9c6e497e4..17ca65e2b8 100644 --- a/openstack_dashboard/dashboards/admin/volumes/volume_types/qos_specs/tests.py +++ b/openstack_dashboard/dashboards/admin/volumes/volume_types/qos_specs/tests.py @@ -41,7 +41,7 @@ class QosSpecsTests(test.BaseAdminViewTests): specs = self.cinder_qos_specs.first().specs for row in rows: key = row.cells['key'].data - self.assertTrue(key in specs) + self.assertIn(key, specs) self.assertEqual(row.cells['value'].data, specs.get(key)) diff --git a/openstack_dashboard/dashboards/project/instances/tests.py b/openstack_dashboard/dashboards/project/instances/tests.py index ca089fab95..6283f9059a 100644 --- a/openstack_dashboard/dashboards/project/instances/tests.py +++ b/openstack_dashboard/dashboards/project/instances/tests.py @@ -1851,7 +1851,7 @@ class InstanceTests(helpers.TestCase): volume_sources_ids.append(volume[0].split(":vol")[0]) for volume in bootable_volumes: - self.assertTrue(volume in volume_sources_ids) + self.assertIn(volume, volume_sources_ids) @helpers.update_settings( OPENSTACK_NEUTRON_NETWORK={'profile_support': 'cisco'}) diff --git a/openstack_dashboard/dashboards/project/overview/tests.py b/openstack_dashboard/dashboards/project/overview/tests.py index 712cf4a5e4..1770e825d6 100644 --- a/openstack_dashboard/dashboards/project/overview/tests.py +++ b/openstack_dashboard/dashboards/project/overview/tests.py @@ -362,7 +362,7 @@ class UsageViewTests(test.TestCase): def test_usage_charts_created(self): res = self._test_usage_charts() - self.assertTrue('charts' in res.context) + self.assertIn('charts', res.context) def test_usage_charts_infinite_quota(self): res = self._test_usage_charts() diff --git a/openstack_dashboard/test/api_tests/cinder_tests.py b/openstack_dashboard/test/api_tests/cinder_tests.py index 3181a05337..cce045ff2f 100644 --- a/openstack_dashboard/test/api_tests/cinder_tests.py +++ b/openstack_dashboard/test/api_tests/cinder_tests.py @@ -450,7 +450,7 @@ class CinderApiVersionTests(test.TestCase): key_value = "snapshot_meta_value" metadata_value = {key_name: key_value} setattr(snapshot._apiresource, 'metadata', metadata_value) - self.assertTrue(key_name in snapshot.metadata.keys()) + self.assertIn(key_name, snapshot.metadata.keys()) self.assertEqual(key_value, snapshot.metadata['snapshot_meta_key']) def test_get_id_for_nameless_volume(self): diff --git a/openstack_dashboard/test/tests/policy_backend.py b/openstack_dashboard/test/tests/policy_backend.py index 48e7b82285..23fcf1a114 100644 --- a/openstack_dashboard/test/tests/policy_backend.py +++ b/openstack_dashboard/test/tests/policy_backend.py @@ -22,8 +22,8 @@ class PolicyBackendTestCase(test.TestCase): policy_backend.reset() enforcer = policy_backend._get_enforcer() self.assertEqual(2, len(enforcer)) - self.assertTrue('identity' in enforcer) - self.assertTrue('compute' in enforcer) + self.assertIn('identity', enforcer) + self.assertIn('compute', enforcer) def test_policy_reset(self): policy_backend._get_enforcer() diff --git a/openstack_dashboard/test/tests/templates.py b/openstack_dashboard/test/tests/templates.py index b8baf5ad1f..582ba36360 100644 --- a/openstack_dashboard/test/tests/templates.py +++ b/openstack_dashboard/test/tests/templates.py @@ -38,7 +38,7 @@ class TemplateRenderTest(test.TestCase): template.Context(context)) self.assertFalse("&" in out) - self.assertTrue("ENG Perf R&D" in out) + self.assertIn("ENG Perf R&D", out) def test_openrc_html_evil_shell_escape(self): context = { @@ -51,8 +51,8 @@ class TemplateRenderTest(test.TestCase): context, template.Context(context)) - self.assertFalse('o"' in out) - self.assertTrue('\"' in out) + self.assertNotIn('o"', out) + self.assertIn('\"', out) def test_openrc_html_evil_shell_backslash_escape(self): context = { @@ -67,7 +67,7 @@ class TemplateRenderTest(test.TestCase): self.assertFalse('o\"' in out) self.assertFalse('o"' in out) - self.assertTrue('\\"' in out) + self.assertIn('\\"', out) def test_openrc_set_region(self): context = { @@ -81,7 +81,7 @@ class TemplateRenderTest(test.TestCase): context, template.Context(context)) - self.assertTrue("OS_REGION_NAME=\"Colorado\"" in out) + self.assertIn("OS_REGION_NAME=\"Colorado\"", out) def test_openrc_region_not_set(self): context = { @@ -94,4 +94,4 @@ class TemplateRenderTest(test.TestCase): context, template.Context(context)) - self.assertTrue("OS_REGION_NAME=\"\"" in out) + self.assertIn("OS_REGION_NAME=\"\"", out)