summaryrefslogtreecommitdiffstats
path: root/tests/test_ipalib
diff options
context:
space:
mode:
authorPetr Viktorin <pviktori@redhat.com>2012-06-15 09:08:55 -0400
committerRob Crittenden <rcritten@redhat.com>2012-06-25 22:04:14 -0400
commit3021b3e9d5f69a2a604921a6203962ffc57b9d79 (patch)
treee40d7fbd8770b5a7ed6d4251d99eefd0a860fdf1 /tests/test_ipalib
parentec5115a15513b40f7ef5d2bcf4f5e66c139f5d87 (diff)
downloadfreeipa-3021b3e9d5f69a2a604921a6203962ffc57b9d79.tar.gz
freeipa-3021b3e9d5f69a2a604921a6203962ffc57b9d79.tar.xz
freeipa-3021b3e9d5f69a2a604921a6203962ffc57b9d79.zip
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
Diffstat (limited to 'tests/test_ipalib')
-rw-r--r--tests/test_ipalib/test_frontend.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/tests/test_ipalib/test_frontend.py b/tests/test_ipalib/test_frontend.py
index 5f7ce65fb..528609d9e 100644
--- a/tests/test_ipalib/test_frontend.py
+++ b/tests/test_ipalib/test_frontend.py
@@ -615,7 +615,7 @@ class test_Command(ClassChecker):
assert o.run.im_func is self.cls.run.im_func
assert ('forward', args, kw) == o.run(*args, **kw)
- def test_validate_output(self):
+ def test_validate_output_basic(self):
"""
Test the `ipalib.frontend.Command.validate_output` method.
"""
@@ -646,7 +646,18 @@ class test_Command(ClassChecker):
'Example', ['azz', 'fee'], wrong
)
- # Test with per item type validation:
+ # Test with different keys:
+ wrong = dict(baz=1, xyzzy=2, quux=3)
+ e = raises(ValueError, inst.validate_output, wrong)
+ assert str(e) == '%s.validate_output(): missing keys %r in %r' % (
+ 'Example', ['bar', 'foo'], wrong
+ ), str(e)
+
+ def test_validate_output_per_type(self):
+ """
+ Test `ipalib.frontend.Command.validate_output` per-type validation.
+ """
+
class Complex(self.cls):
has_output = (
output.Output('foo', int),
@@ -667,6 +678,11 @@ class test_Command(ClassChecker):
'Complex.validate_output()', 'bar', list, int, 17
)
+ def test_validate_output_nested(self):
+ """
+ Test `ipalib.frontend.Command.validate_output` nested validation.
+ """
+
class Subclass(output.ListOfEntries):
pass