From 3021b3e9d5f69a2a604921a6203962ffc57b9d79 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Fri, 15 Jun 2012 09:08:55 -0400 Subject: Improve output validation We only checked the length of Command output dictionaries. A misspelled key in would not be caught. Fix the problem by checking if the sets of keys are equal. Add a test. Split the test methods into more manageable pieces. https://fedorahosted.org/freeipa/ticket/2860 --- ipalib/frontend.py | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'ipalib/frontend.py') diff --git a/ipalib/frontend.py b/ipalib/frontend.py index c28fa54a..fadcb863 100644 --- a/ipalib/frontend.py +++ b/ipalib/frontend.py @@ -913,16 +913,19 @@ class Command(HasParam): raise TypeError('%s: need a %r; got a %r: %r' % ( nice, dict, type(output), output) ) - if len(output) < len(self.output): - missing = sorted(set(self.output).difference(output)) - raise ValueError('%s: missing keys %r in %r' % ( - nice, missing, output) - ) - if len(output) > len(self.output): - extra = sorted(set(output).difference(self.output)) - raise ValueError('%s: unexpected keys %r in %r' % ( - nice, extra, output) - ) + expected_set = set(self.output) + actual_set = set(output) + if expected_set != actual_set: + missing = expected_set - actual_set + if missing: + raise ValueError('%s: missing keys %r in %r' % ( + nice, sorted(missing), output) + ) + extra = actual_set - expected_set + if extra: + raise ValueError('%s: unexpected keys %r in %r' % ( + nice, sorted(extra), output) + ) for o in self.output(): value = output[o.name] if not (o.type is None or isinstance(value, o.type)): -- cgit