]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Removing sorted() function from assertEqual()
authorEvgeny Fedoruk <evgenyf@radware.com>
Tue, 12 Aug 2014 11:13:24 +0000 (04:13 -0700)
committerEvgeny Fedoruk <evgenyf@radware.com>
Sun, 24 Aug 2014 06:35:59 +0000 (23:35 -0700)
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

neutron/tests/unit/test_db_plugin.py
neutron/tests/unit/vmware/vshield/test_lbaas_plugin.py

index d004fb359a7ff8722a0a7dac610a0162841b9888..16c904b2e87f94831ea5951345e374e6e8452fcf 100644 (file)
@@ -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):
index bd9fe937f1199ca2eff15de912e2d6d0e56d3a76..978e159652fed2a3611f68b99fef53612371fb82 100644 (file)
@@ -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')