Solves the error using a map type with a max_length contraint.
Change-Id: Id5fddf70e752313d47fc65602678f6b86c29c90b Related-Bug: 1528171
This commit is contained in:
@@ -522,7 +522,7 @@ class MaxLength(Constraint):
|
|||||||
|
|
||||||
valid_types = (int, )
|
valid_types = (int, )
|
||||||
|
|
||||||
valid_prop_types = (Schema.STRING, )
|
valid_prop_types = (Schema.STRING, Schema.MAP)
|
||||||
|
|
||||||
def __init__(self, property_name, property_type, constraint):
|
def __init__(self, property_name, property_type, constraint):
|
||||||
super(MaxLength, self).__init__(property_name, property_type,
|
super(MaxLength, self).__init__(property_name, property_type,
|
||||||
@@ -533,7 +533,8 @@ class MaxLength(Constraint):
|
|||||||
'expects an integer.')))
|
'expects an integer.')))
|
||||||
|
|
||||||
def _is_valid(self, value):
|
def _is_valid(self, value):
|
||||||
if isinstance(value, str) and len(value) <= self.constraint_value:
|
if ((isinstance(value, str) or isinstance(value, dict)) and
|
||||||
|
len(value) <= self.constraint_value):
|
||||||
return True
|
return True
|
||||||
|
|
||||||
return False
|
return False
|
||||||
|
|||||||
@@ -363,3 +363,11 @@ class ConstraintTest(TestCase):
|
|||||||
constraint.validate({"k": "v"})
|
constraint.validate({"k": "v"})
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
self.fail(ex)
|
self.fail(ex)
|
||||||
|
|
||||||
|
def test_max_length_with_map(self):
|
||||||
|
schema = {'max_length': 1}
|
||||||
|
constraint = Constraint('prop', Schema.MAP, schema)
|
||||||
|
try:
|
||||||
|
constraint.validate({"k": "v"})
|
||||||
|
except Exception as ex:
|
||||||
|
self.fail(ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user