summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJason Gerard DeRose <jderose@redhat.com>2008-09-03 20:05:24 +0000
committerJason Gerard DeRose <jderose@redhat.com>2008-09-03 20:05:24 +0000
commit390c1aa4ba9d2c54ac4c737c128f0561d14b58ab (patch)
tree6a4c60d79ffaaa59799a3405010bcb4e6fb9fd63
parent5e8f945a1ea2f34f40a5e033801d66162fc63850 (diff)
downloadfreeipa.git-390c1aa4ba9d2c54ac4c737c128f0561d14b58ab.tar.gz
freeipa.git-390c1aa4ba9d2c54ac4c737c128f0561d14b58ab.tar.xz
freeipa.git-390c1aa4ba9d2c54ac4c737c128f0561d14b58ab.zip
243: Added unit tests for errors.ValidationError
-rw-r--r--ipalib/errors.py2
-rw-r--r--ipalib/tests/test_errors.py33
2 files changed, 35 insertions, 0 deletions
diff --git a/ipalib/errors.py b/ipalib/errors.py
index eb08a7be..cf213d70 100644
--- a/ipalib/errors.py
+++ b/ipalib/errors.py
@@ -119,6 +119,8 @@ class ValidationError(IPAError):
:param error: The error message describing the failure.
:param index: If multivalue, index of value in multivalue tuple
"""
+ assert type(name) is str
+ assert index is None or (type(index) is int and index >= 0)
self.name = name
self.value = value
self.error = error
diff --git a/ipalib/tests/test_errors.py b/ipalib/tests/test_errors.py
index b0b5483c..83dc6e6e 100644
--- a/ipalib/tests/test_errors.py
+++ b/ipalib/tests/test_errors.py
@@ -160,3 +160,36 @@ class test_IPAError(ClassChecker):
e = custom_error(*args)
assert e.args == args
assert str(e) == f % args
+
+
+class test_ValidationError(ClassChecker):
+ """
+ Tests the `errors.ValidationError` exception.
+ """
+ _cls = errors.ValidationError
+
+ def test_class(self):
+ assert self.cls.__bases__ == (errors.IPAError,)
+
+ def test_init(self):
+ """
+ Tests the `errors.ValidationError.__init__` method.
+ """
+ name = 'login'
+ value = 'Whatever'
+ error = 'Must be lowercase.'
+ for index in (None, 3):
+ e = self.cls(name, value, error, index=index)
+ assert e.name is name
+ assert e.value is value
+ assert e.error is error
+ assert e.index is index
+ assert str(e) == 'invalid %r value %r: %s' % (name, value, error)
+ # Check that index default is None:
+ assert self.cls(name, value, error).index is None
+ # Check non str name raises AssertionError:
+ raises(AssertionError, self.cls, unicode(name), value, error)
+ # Check non int index raises AssertionError:
+ raises(AssertionError, self.cls, name, value, error, index=5.0)
+ # Check negative index raises AssertionError:
+ raises(AssertionError, self.cls, name, value, error, index=-2)