From 24e6e4f4963ab5cd837bb657a157033b3ad9df33 Mon Sep 17 00:00:00 2001 From: "Mauro S. M. Rodrigues" Date: Fri, 21 Sep 2012 14:21:00 -0400 Subject: Enable list with no dict objects to be sorted in api samples So far we had only dicts to be sorted. Although Aggregates extension has a response case which a list of strings is returned and the current key attribute didn't checked if the instance was a dict or another object which caused a break in the use case above. This fix this, and use None as key to compare if the element is not a dictionary instance. Change-Id: Id5d31d1d2ad88fb538d8a9637a1969b179dd93ab --- nova/tests/integrated/test_api_samples.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index c9d0fddd7..df239db2a 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -145,12 +145,15 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase): # which order in different way when using a private key itself or # its regular expression, and after all doesn't interfere with # other tests. + # Besides that, there are some cases like Aggregates extension + # where we got a list of strings. For those cases key will be None + # (python's default) and the elements will be compared directly. # 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))): + key = (lambda k: k.get('__tag__', k) if isinstance(k, dict) + else None) + for ex_obj, res_obj in zip(sorted(expected, key=key), + sorted(result, key=key)): res = self._compare_result(subs, ex_obj, res_obj) matched_value = res or matched_value -- cgit