summaryrefslogtreecommitdiffstats
path: root/tests/test_ipalib
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2009-01-13 00:27:06 -0700
committerJason Gerard DeRose <jderose@redhat.com>2009-01-13 00:27:06 -0700
commit33db9fee6017c0777f4fc5da8b020aefd714e387 (patch)
treee193c3f057b2f76f08e03b961a287c488aabd1ca /tests/test_ipalib
parent11dce19225b2ebcf41adb9d06b402610226ab047 (diff)
downloadfreeipa-33db9fee6017c0777f4fc5da8b020aefd714e387.tar.gz
freeipa-33db9fee6017c0777f4fc5da8b020aefd714e387.tar.xz
freeipa-33db9fee6017c0777f4fc5da8b020aefd714e387.zip
New Param: ported create_param() function and unit tests
Diffstat (limited to 'tests/test_ipalib')
-rw-r--r--tests/test_ipalib/test_parameter.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/tests/test_ipalib/test_parameter.py b/tests/test_ipalib/test_parameter.py
index 7f1b11ea4..8abba496a 100644
--- a/tests/test_ipalib/test_parameter.py
+++ b/tests/test_ipalib/test_parameter.py
@@ -748,3 +748,35 @@ class test_Str(ClassChecker):
assert dummy.message == \
'%(name)s must be exactly %(length)d characters'
dummy = dummy_ugettext(translation)
+
+
+def test_create_param():
+ """
+ Test the `ipalib.parameter.create_param` function.
+ """
+ f = parameter.create_param
+
+ # Test that Param instances are returned unchanged:
+ params = (
+ parameter.Param('one?'),
+ parameter.Int('two+'),
+ parameter.Str('three*'),
+ parameter.Bytes('four'),
+ )
+ for p in params:
+ assert f(p) is p
+
+ # Test that the spec creates an Str instance:
+ for spec in ('one?', 'two+', 'three*', 'four'):
+ (name, kw) = parameter.parse_param_spec(spec)
+ p = f(spec)
+ assert p.param_spec is spec
+ assert p.name == name
+ assert p.required is kw['required']
+ assert p.multivalue is kw['multivalue']
+
+ # Test that TypeError is raised when spec is neither a Param nor a str:
+ for spec in (u'one', 42, parameter.Param, parameter.Str):
+ e = raises(TypeError, f, spec)
+ assert str(e) == \
+ TYPE_ERROR % ('spec', (str, parameter.Param), spec, type(spec))