summaryrefslogtreecommitdiffstats
path: root/ipalib/tests/test_public.py
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-13 05:14:12 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-13 05:14:12 +0000
commitb4ad681f410ee5be56b0b02f73306aa49e5c668a (patch)
treefd52bfcc9f1cade2edcaa0610ffed1f4aad022fc /ipalib/tests/test_public.py
parent47fed6c4c2ec509f1283bf18c4aad6eff9a4b756 (diff)
downloadfreeipa.git-b4ad681f410ee5be56b0b02f73306aa49e5c668a.tar.gz
freeipa.git-b4ad681f410ee5be56b0b02f73306aa49e5c668a.tar.xz
freeipa.git-b4ad681f410ee5be56b0b02f73306aa49e5c668a.zip
143: Added errors.RequirementError exception; cmd.validate() now raises RequirementError if a required option is missing
Diffstat (limited to 'ipalib/tests/test_public.py')
-rw-r--r--ipalib/tests/test_public.py37
1 files changed, 24 insertions, 13 deletions
diff --git a/ipalib/tests/test_public.py b/ipalib/tests/test_public.py
index eb19f28a..a331316d 100644
--- a/ipalib/tests/test_public.py
+++ b/ipalib/tests/test_public.py
@@ -177,7 +177,7 @@ class test_cmd(ClassChecker):
class option0(my_option):
pass
class option1(my_option):
- pass
+ required = True
class example(self.cls):
option_classes = (option0, option1)
return example
@@ -254,18 +254,30 @@ class test_cmd(ClassChecker):
Tests the `validate` method.
"""
assert 'validate' in self.cls.__public__ # Public
+
sub = self.subcls()
- for name in ('option0', 'option1'):
- okay = {
- name: name,
- 'another_option': 'some value',
- }
- fail = {
- name: 'whatever',
- 'another_option': 'some value',
- }
- sub.validate(**okay)
- raises(errors.RuleError, sub.validate, **fail)
+
+ # Check with valid args
+ okay = dict(
+ option0='option0',
+ option1='option1',
+ another_option='some value',
+ )
+ sub.validate(**okay)
+
+ # Check with an invalid arg
+ fail = dict(okay)
+ fail['option0'] = 'whatever'
+ raises(errors.RuleError, sub.validate, **fail)
+
+ # Check with a missing required arg
+ fail = dict(okay)
+ fail.pop('option1')
+ raises(errors.RequirementError, sub.validate, **fail)
+
+ # Check with missing *not* required arg
+ okay.pop('option0')
+ sub.validate(**okay)
def test_execute(self):
"""
@@ -274,7 +286,6 @@ class test_cmd(ClassChecker):
assert 'execute' in self.cls.__public__ # Public
-
def test_obj():
cls = public.obj
assert issubclass(cls, plugable.Plugin)