summaryrefslogtreecommitdiffstats
path: root/ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-08-28 05:06:13 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-08-28 05:06:13 +0000
commit07ac867ed39b9539c4667bf51ef32778e5fb01df (patch)
tree03cf496a960feca695021e01ab2228c96917356e /ipalib
parentb865b30511316f2874de6c95b648e6f653f5a46c (diff)
downloadfreeipa.git-07ac867ed39b9539c4667bf51ef32778e5fb01df.tar.gz
freeipa.git-07ac867ed39b9539c4667bf51ef32778e5fb01df.tar.xz
freeipa.git-07ac867ed39b9539c4667bf51ef32778e5fb01df.zip
214: Added ipa_types.Bool.validate() method; added corresponding unit tests
Diffstat (limited to 'ipalib')
-rw-r--r--ipalib/ipa_types.py4
-rw-r--r--ipalib/tests/test_ipa_types.py9
2 files changed, 13 insertions, 0 deletions
diff --git a/ipalib/ipa_types.py b/ipalib/ipa_types.py
index ff62af22..670c4dd6 100644
--- a/ipalib/ipa_types.py
+++ b/ipalib/ipa_types.py
@@ -102,6 +102,10 @@ class Bool(Type):
return False
return None
+ def validate(self, value):
+ if not (value is True or value is False):
+ return 'Must be %r or %r' % (self.true, self.false)
+
class Int(Type):
def __init__(self, min_value=None, max_value=None):
diff --git a/ipalib/tests/test_ipa_types.py b/ipalib/tests/test_ipa_types.py
index 37546d9e..5d31b844 100644
--- a/ipalib/tests/test_ipa_types.py
+++ b/ipalib/tests/test_ipa_types.py
@@ -126,6 +126,15 @@ class test_Bool(ClassChecker):
# value is not be converted, so None is returned
assert o(value) is None
+ def test_validate(self):
+ t = 'For sure!'
+ f = 'No way!'
+ o = self.cls(true=t, false=f)
+ assert o.validate(True) is None
+ assert o.validate(False) is None
+ for value in (t, f, 0, 1, 'True', 'False', 'Yes', 'No'):
+ assert o.validate(value) == 'Must be %r or %r' % (t, f)
+
class test_Int(ClassChecker):
_cls = ipa_types.Int