summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMauro S. M. Rodrigues <maurosr@linux.vnet.ibm.com>2012-09-21 14:21:00 -0400
committerMatthew Treinish <treinish@linux.vnet.ibm.com>2012-09-27 13:33:41 -0400
commit24e6e4f4963ab5cd837bb657a157033b3ad9df33 (patch)
tree0ad8d4b8627b676de9855e5fcbfdb297ba6c9ad4
parent3ea56ce6c8d0dd6f1671e4519423c4dcce235b7a (diff)
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
-rw-r--r--nova/tests/integrated/test_api_samples.py11
1 files 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