本文整理汇总了Python中marshmallow.validate.Range方法的典型用法代码示例。如果您正苦于以下问题:Python validate.Range方法的具体用法?Python validate.Range怎么用?Python validate.Range使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类marshmallow.validate
的用法示例。
在下文中一共展示了validate.Range方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_range_marshmallow_3
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def test_range_marshmallow_3():
class TestSchema(Schema):
foo = fields.Integer(
validate=Range(min=1, min_inclusive=False, max=3, max_inclusive=False)
)
bar = fields.Integer(validate=Range(min=2, max=4))
schema = TestSchema()
dumped = validate_and_dump(schema)
props = dumped["definitions"]["TestSchema"]["properties"]
assert props["foo"]["exclusiveMinimum"] == 1
assert props["foo"]["exclusiveMaximum"] == 3
assert props["bar"]["minimum"] == 2
assert props["bar"]["maximum"] == 4
示例2: __init__
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def __init__(self, allow_extra):
class LocationSchema(Schema):
latitude = fields.Float(allow_none=True)
longitude = fields.Float(allow_none=True)
class SkillSchema(Schema):
subject = fields.Str(required=True)
subject_id = fields.Integer(required=True)
category = fields.Str(required=True)
qual_level = fields.Str(required=True)
qual_level_id = fields.Integer(required=True)
qual_level_ranking = fields.Float(default=0)
class Model(Schema):
id = fields.Integer(required=True)
client_name = fields.Str(validate=validate.Length(max=255), required=True)
sort_index = fields.Float(required=True)
# client_email = fields.Email()
client_phone = fields.Str(validate=validate.Length(max=255), allow_none=True)
location = fields.Nested(LocationSchema)
contractor = fields.Integer(validate=validate.Range(min=0), allow_none=True)
upstream_http_referrer = fields.Str(validate=validate.Length(max=1023), allow_none=True)
grecaptcha_response = fields.Str(validate=validate.Length(min=20, max=1000), required=True)
last_updated = fields.DateTime(allow_none=True)
skills = fields.Nested(SkillSchema, many=True)
self.allow_extra = allow_extra # unused
self.schema = Model()
示例3: get_dbs
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def get_dbs(cls, query=None, ancestor=None, order=None, limit=None, cursor=None, **kwargs):
args = parser.parse({
'cursor': wf.Str(missing=None),
'limit': wf.Int(missing=None, validate=validate.Range(min=-1)),
'order': wf.Str(missing=None),
})
return util.get_dbs(
query or cls.query(ancestor=ancestor),
limit=limit or args['limit'],
cursor=cursor or args['cursor'],
order=order or args['order'],
**kwargs
)
示例4: test_range_marshmallow_2
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def test_range_marshmallow_2():
class TestSchema(Schema):
foo = fields.Integer(validate=Range(min=1, max=3))
schema = TestSchema()
dumped = validate_and_dump(schema)
props = dumped["definitions"]["TestSchema"]["properties"]
assert props["foo"]["minimum"] == 1
assert props["foo"]["maximum"] == 3
示例5: test_range_no_min_or_max
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def test_range_no_min_or_max():
class SchemaNoMin(Schema):
foo = fields.Integer(validate=validate.Range(max=4))
class SchemaNoMax(Schema):
foo = fields.Integer(validate=validate.Range(min=0))
schema1 = SchemaNoMin()
schema2 = SchemaNoMax()
dumped1 = validate_and_dump(schema1)
dumped2 = validate_and_dump(schema2)
assert dumped1["definitions"]["SchemaNoMin"]["properties"]["foo"]["maximum"] == 4
assert dumped2["definitions"]["SchemaNoMax"]["properties"]["foo"]["minimum"] == 0
示例6: test_range_non_number_error
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def test_range_non_number_error():
class TestSchema(Schema):
foo = fields.String(validate=validate.Range(max=4))
schema = TestSchema()
json_schema = JSONSchema()
with pytest.raises(UnsupportedValueError):
json_schema.dump(schema)
示例7: test_custom_validator
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def test_custom_validator():
class TestValidator(validate.Range):
_jsonschema_base_validator_class = validate.Range
class TestSchema(Schema):
test_field = fields.Int(validate=TestValidator(min=1, max=10))
schema = TestSchema()
dumped = validate_and_dump(schema)
props = dumped["definitions"]["TestSchema"]["properties"]
assert props["test_field"]["minimum"] == 1
assert props["test_field"]["maximum"] == 10
示例8: __init__
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def __init__(self, field_me):
super(SizeParam, self).__init__()
# Add a length validator for max_length/min_length
maxmin_args = {}
if hasattr(field_me, 'max_value'):
maxmin_args['max'] = field_me.max_value
if hasattr(field_me, 'min_value'):
maxmin_args['min'] = field_me.min_value
self.field_kwargs['validate'].append(validate.Range(**maxmin_args))
示例9: test_length_validator_set
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def test_length_validator_set(self, models):
fields_ = fields_for_model(models.Student)
validator = contains_validator(fields_['full_name'], validate.Length)
assert validator
assert validator.max == 255
validator = contains_validator(fields_['email'], validate.Length)
assert validator
assert validator.max == 100
validator = contains_validator(fields_['profile_uri'], validate.Length)
assert validator
assert validator.max == 200
validator = contains_validator(fields_['age'], validate.Range)
assert validator
assert validator.max == 99
assert validator.min == 10
示例10: schemas
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def schemas():
class WidgetSchema(Schema):
id = fields.Integer(as_string=True)
color = fields.String()
size = fields.Integer(validate=validate.Range(min=1))
return {"widget": WidgetSchema()}
示例11: schemas
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def schemas():
class WidgetSchema(Schema):
id = fields.Integer(as_string=True)
size = fields.Integer()
class WidgetValidateSchema(WidgetSchema):
size = fields.Integer(validate=validate.Range(max=1))
return {
"widget": WidgetSchema(),
"widget_validate": WidgetValidateSchema(),
}
示例12: __init__
# 需要导入模块: from marshmallow import validate [as 别名]
# 或者: from marshmallow.validate import Range [as 别名]
def __init__(self, **kwargs):
super().__init__(
fields.Float(validate=Range(min=-1.0, max=1.0)),
validate=Length(equal=24),
**kwargs,
)