summaryrefslogtreecommitdiffstats
path: root/tests/test_ipalib
diff options
context:
space:
mode:
authorJan Cholasta <jcholast@redhat.com>2011-11-21 10:50:27 -0500
committerMartin Kosek <mkosek@redhat.com>2011-11-30 17:08:35 +0100
commit135ccf89de866ea2cdda96993ed2743394e1e716 (patch)
tree1b3c7bef4d5653255b75014218d1d0be9b10d5bb /tests/test_ipalib
parent2ac9d4816a85822825257e16f4fcf74e15a8ea02 (diff)
downloadfreeipa-135ccf89de866ea2cdda96993ed2743394e1e716.tar.gz
freeipa-135ccf89de866ea2cdda96993ed2743394e1e716.tar.xz
freeipa-135ccf89de866ea2cdda96993ed2743394e1e716.zip
Parse comma-separated lists of values in all parameter types. This can be enabled for a specific parameter by setting the "csv" option to True.
Remove "List" parameter type and replace all occurences of it with appropriate multi-valued parameter ("Str" in most cases) with csv enabled. Add new parameter type "Any", capable of holding values of any type. This is needed by the "batch" command, as "Str" is not suitable type for the "methods" parameter. ticket 2007
Diffstat (limited to 'tests/test_ipalib')
-rw-r--r--tests/test_ipalib/test_parameters.py110
1 files changed, 50 insertions, 60 deletions
diff --git a/tests/test_ipalib/test_parameters.py b/tests/test_ipalib/test_parameters.py
index e63bbb736..5cb7abf2a 100644
--- a/tests/test_ipalib/test_parameters.py
+++ b/tests/test_ipalib/test_parameters.py
@@ -192,6 +192,10 @@ class test_Param(ClassChecker):
assert o.include is None
assert o.exclude is None
assert o.flags == frozenset()
+ assert o.sortorder == 2
+ assert o.csv is False
+ assert o.csv_separator == ','
+ assert o.csv_skipspace is True
# Test that doc defaults from label:
o = self.cls('my_param', doc=_('Hello world'))
@@ -267,6 +271,10 @@ class test_Param(ClassChecker):
'exclude', frozenset(['client', 'bar']),
)
+ # Test that ValueError is raised if csv is set and multivalue is not set:
+ e = raises(ValueError, self.cls, 'my_param', csv=True)
+ assert str(e) == '%s: cannot have csv without multivalue' % "Param('my_param')"
+
# Test that _get_default gets set:
call1 = lambda first, last: first[0] + last
call2 = lambda **kw: 'The Default'
@@ -626,6 +634,48 @@ class test_Param(ClassChecker):
assert o._convert_scalar.value is default
assert o.normalizer.value is default
+ def test_csv_normalize(self):
+ """
+ Test the `ipalib.parameters.Param.normalize` method with csv.
+ """
+ o = self.cls('my_list+', csv=True)
+ n = o.normalize('a,b')
+ assert type(n) is tuple
+ assert len(n) is 2
+
+ n = o.normalize('bar, "hi, there",foo')
+ assert type(n) is tuple
+ assert len(n) is 3
+
+ def test_csv_normalize_separator(self):
+ """
+ Test the `ipalib.parameters.Param.normalize` method with csv and a separator.
+ """
+ o = self.cls('my_list+', csv=True, csv_separator='|')
+
+ n = o.normalize('a')
+ assert type(n) is tuple
+ assert len(n) is 1
+
+ n = o.normalize('a|b')
+ assert type(n) is tuple
+ assert len(n) is 2
+
+ def test_csv_normalize_skipspace(self):
+ """
+ Test the `ipalib.parameters.Param.normalize` method with csv without skipping spaces.
+ """
+ o = self.cls('my_list+', csv=True, csv_skipspace=False)
+
+ n = o.normalize('a')
+ assert type(n) is tuple
+ assert len(n) is 1
+
+ n = o.normalize('a, "b,c", d')
+ assert type(n) is tuple
+ # the output w/o skipspace is ['a',' "b','c"',' d']
+ assert len(n) is 4
+
class test_Flag(ClassChecker):
"""
@@ -1324,66 +1374,6 @@ class test_Float(ClassChecker):
assert dummy.called() is True
dummy.reset()
-
-class test_List(ClassChecker):
- """
- Test the `ipalib.parameters.List` class.
- """
- _cls = parameters.List
-
- def test_init(self):
- """
- Test the `ipalib.parameters.List.__init__` method.
- """
- # Test with no kwargs:
- o = self.cls('my_list')
- assert o.type is tuple
- assert isinstance(o, parameters.List)
- assert o.multivalue is True
- assert o.skipspace is True
-
- def test_normalize(self):
- """
- Test the `ipalib.parameters.List.normalize` method.
- """
- o = self.cls('my_list')
- n = o.normalize('a,b')
- assert type(n) is tuple
- assert len(n) is 2
-
- n = o.normalize('bar, "hi, there",foo')
- assert type(n) is tuple
- assert len(n) is 3
-
- def test_normalize_separator(self):
- """
- Test the `ipalib.parameters.List.normalize` method with a separator.
- """
- o = self.cls('my_list', separator='|')
-
- n = o.normalize('a')
- assert type(n) is tuple
- assert len(n) is 1
-
- n = o.normalize('a|b')
- assert type(n) is tuple
- assert len(n) is 2
-
- def test_normalize_skipspace(self):
- """
- Test the `ipalib.parameters.List.normalize` method without skipping spaces.
- """
- o = self.cls('my_list', skipspace=False)
-
- n = o.normalize('a')
- assert type(n) is tuple
- assert len(n) is 1
-
- n = o.normalize('a, "b,c", d')
- assert type(n) is tuple
- # the output w/o skipspace is ['a',' "b','c"',' d']
- assert len(n) is 4
-
class test_AccessTime(ClassChecker):
"""
Test the `ipalib.parameters.AccessTime` class.