From cb6291add6dccdb8c70f4a5b88a84fdb720ef347 Mon Sep 17 00:00:00 2001 From: Vishvananda Ishaya Date: Tue, 2 Oct 2012 13:56:25 -0700 Subject: Compare lists in api samples against all matches Lists of dictionaries don't always sort the same way, so rather than attempting to sort them, just compare each item in the list against all other copies looking for a match. This change uncovered a bug in one of the api samples test where an extra item in the template was being ignored. Change-Id: I8750560a1760de7f1991563788680b2dac445aaa --- .../server-action-rebuild-resp.xml.tpl | 8 +----- .../api_samples/server-action-rebuild-resp.xml.tpl | 10 ++------ nova/tests/integrated/test_api_samples.py | 30 +++++++++++----------- 3 files changed, 18 insertions(+), 30 deletions(-) diff --git a/nova/tests/integrated/api_samples/all_extensions/server-action-rebuild-resp.xml.tpl b/nova/tests/integrated/api_samples/all_extensions/server-action-rebuild-resp.xml.tpl index 105e19fdd..0ede362be 100644 --- a/nova/tests/integrated/api_samples/all_extensions/server-action-rebuild-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/all_extensions/server-action-rebuild-resp.xml.tpl @@ -8,7 +8,7 @@ hostId="%(hostid)s" progress="0" status="ACTIVE" adminPass="%(password)s" created="%(timestamp)s" - updated="%(timestamp)s" + updated="%(timestamp)s" accessIPv4="%(ip)s" accessIPv6="%(ip6)s" OS-DCF:diskConfig="AUTO"> @@ -16,17 +16,11 @@ - - Apache1 diff --git a/nova/tests/integrated/api_samples/server-action-rebuild-resp.xml.tpl b/nova/tests/integrated/api_samples/server-action-rebuild-resp.xml.tpl index 996c9ccbf..d9e80f8c4 100644 --- a/nova/tests/integrated/api_samples/server-action-rebuild-resp.xml.tpl +++ b/nova/tests/integrated/api_samples/server-action-rebuild-resp.xml.tpl @@ -1,30 +1,24 @@ - - Apache1 diff --git a/nova/tests/integrated/test_api_samples.py b/nova/tests/integrated/test_api_samples.py index 1599bd9b8..a4c7f8493 100644 --- a/nova/tests/integrated/test_api_samples.py +++ b/nova/tests/integrated/test_api_samples.py @@ -142,21 +142,21 @@ class ApiSampleTestBase(integrated_helpers._IntegratedTestBase): if not isinstance(result, list): raise NoMatch( _('Result: %(result)s is not a list.') % locals()) - # 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. - # 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. - 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) + if len(expected) != len(result): + raise NoMatch( + _('Length mismatch: %(result)s\n%(expected)s.') + % locals()) + for res_obj in result: + for ex_obj in expected: + try: + res = self._compare_result(subs, ex_obj, res_obj) + break + except NoMatch: + pass + else: + raise NoMatch( + _('Result: %(res_obj)s not in %(expected)s.') + % locals()) matched_value = res or matched_value elif isinstance(expected, basestring) and '%' in expected: -- cgit