mirror of
https://salsa.debian.org/freeipa-team/freeipa.git
synced 2025-02-25 18:55:28 -06:00
214: Added ipa_types.Bool.validate() method; added corresponding unit tests
This commit is contained in:
parent
b865b30511
commit
07ac867ed3
@ -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):
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user