summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--wsme/tests/test_types.py13
-rw-r--r--wsme/types.py2
2 files changed, 14 insertions, 1 deletions
diff --git a/wsme/tests/test_types.py b/wsme/tests/test_types.py
index c11ba34..fc41417 100644
--- a/wsme/tests/test_types.py
+++ b/wsme/tests/test_types.py
@@ -206,6 +206,19 @@ Value: 'v3'. Value should be one of: v., v.",
self.assertRaises(exc.InvalidInput, setattr, obj, 'alist', 12)
self.assertRaises(exc.InvalidInput, setattr, obj, 'alist', [2, 'a'])
+ def test_attribute_validation_minimum(self):
+ class ATypeInt(object):
+ attr = types.IntegerType(minimum=1, maximum=5)
+
+ types.register_type(ATypeInt)
+
+ obj = ATypeInt()
+ obj.attr = 2
+
+ # comparison between 'zero' value and intger minimum (1) raises a
+ # TypeError which must be wrapped into an InvalidInput exception
+ self.assertRaises(exc.InvalidInput, setattr, obj, 'attr', 'zero')
+
def test_text_attribute_conversion(self):
class SType(object):
atext = types.text
diff --git a/wsme/types.py b/wsme/types.py
index 77404e5..eca915c 100644
--- a/wsme/types.py
+++ b/wsme/types.py
@@ -487,7 +487,7 @@ class wsattr(object):
def __set__(self, instance, value):
try:
value = validate_value(self.datatype, value)
- except ValueError as e:
+ except (ValueError, TypeError) as e:
raise exc.InvalidInput(self.name, value, six.text_type(e))
dataholder = self._get_dataholder(instance)
if value is Unset: