]> review.fuel-infra Code Review - openstack-build/neutron-build.git/commitdiff
Do not assume order of convert_kvp_list_to_dict method responses
authorCedric Brandily <zzelle@gmail.com>
Wed, 27 May 2015 12:54:35 +0000 (14:54 +0200)
committerCedric Brandily <zzelle@gmail.com>
Wed, 27 May 2015 12:54:35 +0000 (14:54 +0200)
This fixes the test_attributes unit tests[1] that breaks with a
randomized PYTHONHASHSEED (see the bug report).

The test assumed that the convert_kvp_list_to_dict method from
neutron.api.v2.attributes returned elements in a particular
order. Found with PYTHONHASHSEED=1.

The fix refactors the test case to handle unsorted responses from
convert_kvp_list_to_dict.

[1] neutron.tests.unit.api.v2.test_attributes.TestConvertKvp

Partial-bug: #1348818

Note: There are several other unrelated unit tests that also break with
a randomized PYTHONHASHSEED, but they are not addressed here. They will
be addressed in separate patches.

Change-Id: I864904db1428b88c482ad17a69b33e876a8d042c

neutron/tests/unit/api/v2/test_attributes.py

index 7a79d900a26209fc036e02b7e545701502745451..28b8d6621b28f62f2d276f25e31efc9412098c37 100644 (file)
@@ -21,6 +21,7 @@ import mock
 from neutron.api.v2 import attributes
 from neutron.common import exceptions as n_exc
 from neutron.tests import base
+from neutron.tests import tools
 
 
 class TestAttributes(base.BaseTestCase):
@@ -807,7 +808,8 @@ class TestConvertKvp(base.BaseTestCase):
     def test_convert_kvp_list_to_dict_succeeds_for_multiple_values(self):
         result = attributes.convert_kvp_list_to_dict(
             ['a=b', 'a=c', 'a=c', 'b=a'])
-        self.assertEqual({'a': ['c', 'b'], 'b': ['a']}, result)
+        expected = {'a': tools.UnorderedList(['c', 'b']), 'b': ['a']}
+        self.assertEqual(expected, result)
 
     def test_convert_kvp_list_to_dict_succeeds_for_values(self):
         result = attributes.convert_kvp_list_to_dict(['a=b', 'c=d'])