本文整理汇总了Python中cerberus.Validator.schema[field]["required"]方法的典型用法代码示例。如果您正苦于以下问题:Python Validator.schema[field]["required"]方法的具体用法?Python Validator.schema[field]["required"]怎么用?Python Validator.schema[field]["required"]使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类cerberus.Validator
的用法示例。
在下文中一共展示了Validator.schema[field]["required"]方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_ignore_none_values
# 需要导入模块: from cerberus import Validator [as 别名]
# 或者: from cerberus.Validator import schema[field]["required"] [as 别名]
def test_ignore_none_values():
field = "test"
schema = {field: {"type": "string", "empty": False, "required": False}}
document = {field: None}
# Test normal behaviour
validator = Validator(schema, ignore_none_values=False)
assert_fail(document, validator=validator)
validator.schema[field]["required"] = True
validator.schema.validate()
_errors = assert_fail(document, validator=validator)
assert_not_has_error(_errors, field, (field, "required"), errors.REQUIRED_FIELD, True)
# Test ignore None behaviour
validator = Validator(schema, ignore_none_values=True)
validator.schema[field]["required"] = False
validator.schema.validate()
assert_success(document, validator=validator)
validator.schema[field]["required"] = True
_errors = assert_fail(schema=schema, document=document, validator=validator)
assert_has_error(_errors, field, (field, "required"), errors.REQUIRED_FIELD, True)
assert_not_has_error(_errors, field, (field, "type"), errors.BAD_TYPE, "string")