diff --git a/ipalib/ipa_types.py b/ipalib/ipa_types.py index ff62af22e..670c4dd64 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 37546d9e6..5d31b8446 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