summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Crittenden <rcritten@redhat.com>2009-11-04 09:41:48 -0500
committerJason Gerard DeRose <jderose@redhat.com>2009-11-17 09:36:38 -0700
commit680bf7c54863452263b9cd324ede444fd438436d (patch)
tree2f81be6443cb44d5bb4c37237001399d79f52414
parent1d1d82fda4c499f16ec1d74d8b9b63e03ecae144 (diff)
downloadfreeipa-680bf7c54863452263b9cd324ede444fd438436d.tar.gz
freeipa-680bf7c54863452263b9cd324ede444fd438436d.tar.xz
freeipa-680bf7c54863452263b9cd324ede444fd438436d.zip
_convert_scalar() should throw an error if passed a tuple or list
A parameter needs to have multivalue set in order to work on lists/tuples and even then _convert_scalar() will be sent one value at a time.
-rw-r--r--ipalib/parameters.py12
-rw-r--r--tests/test_ipalib/test_parameters.py8
2 files changed, 19 insertions, 1 deletions
diff --git a/ipalib/parameters.py b/ipalib/parameters.py
index 0630915cb..227757d63 100644
--- a/ipalib/parameters.py
+++ b/ipalib/parameters.py
@@ -227,6 +227,9 @@ class Param(ReadOnly):
# Subclasses should override this with something more specific:
type_error = _('incorrect type')
+ # _convert_scalar operates only on scalar values
+ scalar_error = _('Only one value is allowed')
+
kwargs = (
('cli_name', str, None),
('cli_short_name', str, None),
@@ -810,6 +813,9 @@ class Bool(Param):
return True
if value in self.falsehoods:
return False
+ if type(value) in (tuple, list):
+ raise ConversionError(name=self.name, index=index,
+ error=ugettext(self.scalar_error))
raise ConversionError(name=self.name, index=index,
error=ugettext(self.type_error),
)
@@ -873,6 +879,9 @@ class Number(Param):
return self.type(value)
except ValueError:
pass
+ if type(value) in (tuple, list):
+ raise ConversionError(name=self.name, index=index,
+ error=ugettext(self.scalar_error))
raise ConversionError(name=self.name, index=index,
error=ugettext(self.type_error),
)
@@ -1106,6 +1115,9 @@ class Str(Data):
return value
if type(value) in (int, float):
return self.type(value)
+ if type(value) in (tuple, list):
+ raise ConversionError(name=self.name, index=index,
+ error=ugettext(self.scalar_error))
raise ConversionError(name=self.name, index=index,
error=ugettext(self.type_error),
)
diff --git a/tests/test_ipalib/test_parameters.py b/tests/test_ipalib/test_parameters.py
index 44286ac07..f6bc66f4e 100644
--- a/tests/test_ipalib/test_parameters.py
+++ b/tests/test_ipalib/test_parameters.py
@@ -923,7 +923,7 @@ class test_Str(ClassChecker):
mthd = o._convert_scalar
for value in (u'Hello', 42, 1.2, unicode_str):
assert mthd(value) == unicode(value)
- bad = [True, 'Hello', (u'Hello',), [42.3], dict(one=1), utf8_bytes]
+ bad = [True, 'Hello', dict(one=1), utf8_bytes]
for value in bad:
e = raises(errors.ConversionError, mthd, value)
assert e.name == 'my_str'
@@ -933,6 +933,12 @@ class test_Str(ClassChecker):
assert e.name == 'my_str'
assert e.index == 18
assert_equal(e.error, u'must be Unicode text')
+ bad = [(u'Hello',), [42.3]]
+ for value in bad:
+ e = raises(errors.ConversionError, mthd, value)
+ assert e.name == 'my_str'
+ assert e.index is None
+ assert_equal(e.error, u'Only one value is allowed')
assert o.convert(None) is None
def test_rule_minlength(self):