Python marshmallow.fields.Int() Examples

The following are 2 code examples of marshmallow.fields.Int(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module marshmallow.fields , or try the search function .
Example #1
Source File: test_validation.py    From marshmallow-jsonschema with MIT License 5 votes vote down vote up
def test_regexp_error():
    class TestSchema(Schema):
        test_regexp = fields.Int(validate=validate.Regexp(r"\d+"))

    schema = TestSchema()

    with pytest.raises(UnsupportedValueError):
        dumped = validate_and_dump(schema) 
Example #2
Source File: test_validation.py    From marshmallow-jsonschema with MIT License 5 votes vote down vote up
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