Cerberus 1.3 renamed 'validator' → 'check_with'

This results in a change in schemas as well as in validator function names.
This commit is contained in:
Sybren A. Stüvel 2019-05-29 12:56:13 +02:00
parent f53217cabf
commit 6f8fd4cd72
4 changed files with 6 additions and 6 deletions

View File

@ -144,7 +144,7 @@ class ValidateCustomFields(Validator):
if not value:
self._error(field, "Value is required once the document was created")
def _validator_iprange(self, field_name: str, value: str):
def _check_with_iprange(self, field_name: str, value: str):
"""Ensure the field contains a valid IP address.
Supports both IPv6 and IPv4 ranges. Requires the IPy module.
@ -181,12 +181,12 @@ if __name__ == '__main__':
v = ValidateCustomFields()
v.schema = {
'foo': {'type': 'string', 'validator': 'markdown'},
'foo': {'type': 'string', 'check_with': 'markdown'},
'foo_html': {'type': 'string'},
'nested': {
'type': 'dict',
'schema': {
'bar': {'type': 'string', 'validator': 'markdown'},
'bar': {'type': 'string', 'check_with': 'markdown'},
'bar_html': {'type': 'string'},
}
}

View File

@ -256,7 +256,7 @@ organizations_schema = {
'start': {'type': 'binary', 'required': True},
'end': {'type': 'binary', 'required': True},
'prefix': {'type': 'integer', 'required': True},
'human': {'type': 'string', 'required': True, 'validator': 'iprange'},
'human': {'type': 'string', 'required': True, 'check_with': 'iprange'},
}
},
},

View File

@ -727,7 +727,7 @@ def iter_markdown(proj_node_types: dict, some_node: dict, callback: typing.Calla
to_visit.append((subdoc, definition['schema']))
continue
coerce = definition.get('coerce') # Eve < 0.8
validator = definition.get('validator') # Eve >= 0.8
validator = definition.get('check_with') or definition.get('validator') # Eve >= 0.8
if coerce != 'markdown' and validator != 'markdown':
continue

View File

@ -185,7 +185,7 @@ class AbstractSchemaValidationTest(AbstractValidationTest):
class IPRangeValidatorTest(AbstractSchemaValidationTest):
schema = {'iprange': {'type': 'string', 'required': True, 'validator': 'iprange'}}
schema = {'iprange': {'type': 'string', 'required': True, 'check_with': 'iprange'}}
def test_ipv6(self):
self.assertValid({'iprange': '2a03:b0c0:0:1010::8fe:6ef1'})