From 69f6b86768ec2c3e8b6ccf4704bef13f6f8cc4f8 Mon Sep 17 00:00:00 2001 From: "Mauro S. M. Rodrigues" Date: Mon, 10 Sep 2012 08:26:43 -0400 Subject: Add a criteria to sort a list of dict in api samples Add 'key' parameter in the sorted call to order the list of dictionaries by a specified criteria: the __tag__ value. So far the sorted method considered an unspecified criteria (it seems it considered the whole dict content) when ordering and this was causing some few cases fail. Change-Id: I1ebb295a7a3a53267e8f9f4286093f5b63d48eb3 --- nova/tests/integrated/test_api_samples.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index d51240871..0c1bfdd3f 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -137,7 +137,17 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase): if not isinstance(result, list): raise NoMatch( _('Result: %(result)s is not a list.') % locals()) - for ex_obj, res_obj in zip(sorted(expected), sorted(result)): + # NOTE(maurosr): sort the list of dicts by their __tag__ element + # when using xml. This will avoid some fails in keypairs api sample + # which order in different way when using a private key itself or + # its regular expression, and after all doesn't interfere with + # other tests. + # Should we define a criteria when ordering json? Doesn't seems + # necessary so far. + for ex_obj, res_obj in zip(sorted(expected, key=lambda k: + k.get('__tag__', k)), + sorted(result, key=lambda k: + k.get('__tag__', k))): res = self._compare_result(subs, ex_obj, res_obj) matched_value = res or matched_value -- cgit