Skip to content

Commit

Permalink
Add a criteria to sort a list of dict in api samples
Browse files Browse the repository at this point in the history
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
  • Loading branch information
maurorodrigues committed Sep 10, 2012
1 parent 28a5b31 commit 69f6b86
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion nova/tests/integrated/test_api_samples.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,17 @@ def _compare_result(self, subs, expected, result):
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

Expand Down

0 comments on commit 69f6b86

Please sign in to comment.