From: Cedric Brandily Date: Wed, 27 May 2015 12:54:35 +0000 (+0200) Subject: Do not assume order of convert_kvp_list_to_dict method responses X-Git-Url: https://review.fuel-infra.org/gitweb?a=commitdiff_plain;h=ce957ac83a85a421f2e60cc39a3103291ba95e4a;p=openstack-build%2Fneutron-build.git Do not assume order of convert_kvp_list_to_dict method responses 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 --- diff --git a/neutron/tests/unit/api/v2/test_attributes.py b/neutron/tests/unit/api/v2/test_attributes.py index 7a79d900a..28b8d6621 100644 --- a/neutron/tests/unit/api/v2/test_attributes.py +++ b/neutron/tests/unit/api/v2/test_attributes.py @@ -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'])