diff options
author | Jason Gerard DeRose <jderose@redhat.com> | 2008-12-18 00:02:38 -0700 |
---|---|---|
committer | Jason Gerard DeRose <jderose@redhat.com> | 2008-12-18 00:02:38 -0700 |
commit | bf8154fa5017d12c7377175f85f60b670dc294f9 (patch) | |
tree | b8a5e0f8697e828342d4ed80b3631e0f97b836a4 /tests/test_ipalib | |
parent | 8ef6819059dbfaa8e2f97c312e0b932546b0b417 (diff) | |
download | freeipa-bf8154fa5017d12c7377175f85f60b670dc294f9.tar.gz freeipa-bf8154fa5017d12c7377175f85f60b670dc294f9.tar.xz freeipa-bf8154fa5017d12c7377175f85f60b670dc294f9.zip |
New Param: fixed a few things in Param.convert() and added corresponding unit tests
Diffstat (limited to 'tests/test_ipalib')
-rw-r--r-- | tests/test_ipalib/test_parameter.py | 31 |
1 files changed, 30 insertions, 1 deletions
diff --git a/tests/test_ipalib/test_parameter.py b/tests/test_ipalib/test_parameter.py index 508e399f3..7d9315831 100644 --- a/tests/test_ipalib/test_parameter.py +++ b/tests/test_ipalib/test_parameter.py @@ -25,7 +25,7 @@ Test the `ipalib.parameter` module. from tests.util import raises, ClassChecker, read_only from tests.data import binary_bytes, utf8_bytes, unicode_str from ipalib import parameter -from ipalib.constants import TYPE_ERROR, CALLABLE_ERROR +from ipalib.constants import TYPE_ERROR, CALLABLE_ERROR, NULLS class test_DefaultFrom(ClassChecker): @@ -171,6 +171,35 @@ class test_Param(ClassChecker): assert str(e) == \ "Param('my_param'): takes no such kwargs: 'ape', 'great'" + def test_convert(self): + """ + Test the `ipalib.parameter.Param.convert` method. + """ + okay = ('Hello', u'Hello', 0, 4.2, True, False) + class Subclass(self.cls): + def _convert_scalar(self, value, index=None): + return value + + # Test when multivalue=False: + o = Subclass('my_param') + for value in NULLS: + assert o.convert(value) is None + for value in okay: + assert o.convert(value) is value + + # Test when multivalue=True: + o = Subclass('my_param', multivalue=True) + for value in NULLS: + assert o.convert(value) is None + assert o.convert(okay) == okay + assert o.convert(NULLS) is None + assert o.convert(okay + NULLS) == okay + assert o.convert(NULLS + okay) == okay + for value in okay: + assert o.convert(value) == (value,) + assert o.convert([None, value]) == (value,) + assert o.convert([value, None]) == (value,) + def test_convert_scalar(self): """ Test the `ipalib.parameter.Param._convert_scalar` method. |