From: Evgeny Fedoruk Date: Tue, 12 Aug 2014 11:13:24 +0000 (-0700) Subject: Removing sorted() function from assertEqual() X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=3082a074f819f0479fc941b30dc7cfdbb8aab394;p=openstack-build%2Fneutron-build.git Removing sorted() function from assertEqual() Removing unnecessary sorted() function from assertEqual() function calls in functions used for sorting and pagination testing Using sorted() breaks sorting tests objective which is to test sorting. This is causing every unit test using this functions (_test_list_with_sort, _test_list_with_pagination, _test_list_with_pagination_reverse) for sorting tests to always succeed Switched the parameters for assertEqual() function within the fixed code to meet its signature - assertEqual(self, expected, observed, message='') Test neutron.tests.unit.vmware.vshield.test_lbaas_plugin.TestLoadbalancerPlugin.test_list_vips was succeeding because of this bug, although it should fail. It failed after the bug was fix. Test was fixed. Change-Id: Ia36b81d9a7fd32cae3b567ac1899b56481eb62ce Closes-Bug: #1355251 --- diff --git a/neutron/tests/unit/test_db_plugin.py b/neutron/tests/unit/test_db_plugin.py index d004fb359..16c904b2e 100644 --- a/neutron/tests/unit/test_db_plugin.py +++ b/neutron/tests/unit/test_db_plugin.py @@ -582,8 +582,7 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase): resource = resource.replace('-', '_') resources = resources.replace('-', '_') expected_res = [item[resource]['id'] for item in items] - self.assertEqual(sorted([n['id'] for n in res[resources]]), - sorted(expected_res)) + self.assertEqual(expected_res, [n['id'] for n in res[resources]]) def _test_list_with_pagination(self, resource, items, sort, limit, expected_page_num, @@ -616,10 +615,9 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase): '', content_type) self.assertEqual(len(res[resources]), limit) - self.assertEqual(page_num, expected_page_num) - self.assertEqual(sorted([n[verify_key] for n in items_res]), - sorted([item[resource][verify_key] - for item in items])) + self.assertEqual(expected_page_num, page_num) + self.assertEqual([item[resource][verify_key] for item in items], + [n[verify_key] for n in items_res]) def _test_list_with_pagination_reverse(self, resource, items, sort, limit, expected_page_num, @@ -655,11 +653,10 @@ class NeutronDbPluginV2TestCase(testlib_api.WebTestCase): '', content_type) self.assertEqual(len(res[resources]), limit) - self.assertEqual(page_num, expected_page_num) + self.assertEqual(expected_page_num, page_num) expected_res = [item[resource]['id'] for item in items] expected_res.reverse() - self.assertEqual(sorted([n['id'] for n in item_res]), - sorted(expected_res)) + self.assertEqual(expected_res, [n['id'] for n in item_res]) class TestBasicGet(NeutronDbPluginV2TestCase): diff --git a/neutron/tests/unit/vmware/vshield/test_lbaas_plugin.py b/neutron/tests/unit/vmware/vshield/test_lbaas_plugin.py index bd9fe937f..978e15965 100644 --- a/neutron/tests/unit/vmware/vshield/test_lbaas_plugin.py +++ b/neutron/tests/unit/vmware/vshield/test_lbaas_plugin.py @@ -361,7 +361,7 @@ class TestLoadbalancerPlugin( ) as (vip1, vip2, vip3): self._test_list_with_sort( 'vip', - (vip1, vip3, vip2), + (vip1, vip2, vip3), [('protocol_port', 'asc'), ('name', 'desc')] ) req = self.new_list_request('vips')