From 514ecc6e963bd0c05425f0da8aec79a69ed122c6 Mon Sep 17 00:00:00 2001 From: Terry Howe Date: Thu, 4 Sep 2014 08:06:03 -0600 Subject: Unordered dicts and lists causes variable results The unordered dict and lists causes variable results. The user may see different results and tests can fail. Might as well make this more consistent. Change-Id: I7045b40b44cbf3ee0f2ca79c6ea0d279b6d8cfe3 --- openstackclient/common/utils.py | 4 ++-- openstackclient/tests/common/test_utils.py | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/openstackclient/common/utils.py b/openstackclient/common/utils.py index 51c3ed4b..eb7f1b0e 100644 --- a/openstackclient/common/utils.py +++ b/openstackclient/common/utils.py @@ -77,7 +77,7 @@ def format_dict(data): """ output = "" - for s in data: + for s in sorted(data): output = output + s + "='" + six.text_type(data[s]) + "', " return output[:-2] @@ -89,7 +89,7 @@ def format_list(data): :rtype: a string formatted to a,b,c """ - return ', '.join(data) + return ', '.join(sorted(data)) def get_item_properties(item, fields, mixed_case_fields=[], formatters={}): diff --git a/openstackclient/tests/common/test_utils.py b/openstackclient/tests/common/test_utils.py index 6d75a9b5..e782d410 100644 --- a/openstackclient/tests/common/test_utils.py +++ b/openstackclient/tests/common/test_utils.py @@ -130,3 +130,15 @@ class TestFindResource(test_utils.TestCase): str(result)) self.manager.get.assert_called_with(self.name) self.manager.find.assert_called_with(name=self.name) + + def test_format_dict(self): + expected = "a='b', c='d', e='f'" + self.assertEqual(expected, + utils.format_dict({'a': 'b', 'c': 'd', 'e': 'f'})) + self.assertEqual(expected, + utils.format_dict({'e': 'f', 'c': 'd', 'a': 'b'})) + + def test_format_list(self): + expected = 'a, b, c' + self.assertEqual(expected, utils.format_list(['a', 'b', 'c'])) + self.assertEqual(expected, utils.format_list(['c', 'b', 'a'])) -- cgit v1.2.1