Solves the error using a map type with a max_length contraint.

Change-Id: Id5fddf70e752313d47fc65602678f6b86c29c90b
Related-Bug: 1528171
This commit is contained in:
Miguel Caballer
2016-01-25 10:51:13 +01:00
parent 839d099c5f
commit 348bb50b40
2 changed files with 11 additions and 2 deletions

View File

@@ -522,7 +522,7 @@ class MaxLength(Constraint):
valid_types = (int, )
valid_prop_types = (Schema.STRING, )
valid_prop_types = (Schema.STRING, Schema.MAP)
def __init__(self, property_name, property_type, constraint):
super(MaxLength, self).__init__(property_name, property_type,
@@ -533,7 +533,8 @@ class MaxLength(Constraint):
'expects an integer.')))
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 False

View File

@@ -363,3 +363,11 @@ class ConstraintTest(TestCase):
constraint.validate({"k": "v"})
except Exception as 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)