forked from GithubBackups/healthchecks
add "minLength" support to the jsonschema validator
This commit is contained in:
parent
0c6dcfa766
commit
887c4d534a
@ -16,6 +16,8 @@ def validate(obj, schema, obj_name="value"):
|
||||
if schema.get("type") == "string":
|
||||
if not isinstance(obj, str):
|
||||
raise ValidationError("%s is not a string" % obj_name)
|
||||
if "minLength" in schema and len(obj) < schema["minLength"]:
|
||||
raise ValidationError("%s is too short" % obj_name)
|
||||
if "maxLength" in schema and len(obj) > schema["maxLength"]:
|
||||
raise ValidationError("%s is too long" % obj_name)
|
||||
if schema.get("format") == "cron":
|
||||
|
@ -12,6 +12,10 @@ class JsonSchemaTestCase(TestCase):
|
||||
with self.assertRaises(ValidationError):
|
||||
validate(123, {"type": "string"})
|
||||
|
||||
def test_it_checks_string_min_length(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
validate("abcd", {"type": "string", "minLength": 5})
|
||||
|
||||
def test_it_checks_string_length(self):
|
||||
with self.assertRaises(ValidationError):
|
||||
validate("abcd", {"type": "string", "maxLength": 3})
|
||||
|
Loading…
x
Reference in New Issue
Block a user