当前位置: 首页>>代码示例>>Python>>正文


Python fields.Integer方法代码示例

本文整理汇总了Python中marshmallow.fields.Integer方法的典型用法代码示例。如果您正苦于以下问题:Python fields.Integer方法的具体用法?Python fields.Integer怎么用?Python fields.Integer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在marshmallow.fields的用法示例。


在下文中一共展示了fields.Integer方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _validate_marshmallow_type

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def _validate_marshmallow_type(self, field_cfg):
        """Make sure the Marshmallow type is one we support."""
        def validate_basic_marshmallow_type(_type):
            allowed_types = [
                Bool, DateString, Integer, SanitizedUnicode
            ]
            assert any([
                isinstance(_type, allowed_type) for allowed_type
                in allowed_types
            ])

        marshmallow_type = field_cfg["marshmallow"]
        if isinstance(marshmallow_type, List):
            validate_basic_marshmallow_type(marshmallow_type.inner)
        else:
            validate_basic_marshmallow_type(marshmallow_type) 
开发者ID:inveniosoftware,项目名称:invenio-app-ils,代码行数:18,代码来源:metadata_extensions.py

示例2: test_metadata

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_metadata():
    """Metadata should be available in the field definition."""

    class TestSchema(Schema):
        myfield = fields.String(metadata={"foo": "Bar"})
        yourfield = fields.Integer(required=True, baz="waz")

    schema = TestSchema()

    dumped = validate_and_dump(schema)

    props = dumped["definitions"]["TestSchema"]["properties"]
    assert props["myfield"]["foo"] == "Bar"
    assert props["yourfield"]["baz"] == "waz"
    assert "metadata" not in props["myfield"]
    assert "metadata" not in props["yourfield"]

    # repeat process to assert idempotency
    dumped = validate_and_dump(schema)

    props = dumped["definitions"]["TestSchema"]["properties"]
    assert props["myfield"]["foo"] == "Bar"
    assert props["yourfield"]["baz"] == "waz" 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:25,代码来源:test_dump.py

示例3: test_nested_descriptions

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_nested_descriptions():
    class TestNestedSchema(Schema):
        myfield = fields.String(metadata={"description": "Brown Cow"})
        yourfield = fields.Integer(required=True)

    class TestSchema(Schema):
        nested = fields.Nested(
            TestNestedSchema, metadata={"description": "Nested 1", "title": "Title1"}
        )
        yourfield_nested = fields.Integer(required=True)

    schema = TestSchema()

    dumped = validate_and_dump(schema)

    nested_def = dumped["definitions"]["TestNestedSchema"]
    nested_dmp = dumped["definitions"]["TestSchema"]["properties"]["nested"]
    assert nested_def["properties"]["myfield"]["description"] == "Brown Cow"

    assert nested_dmp["$ref"] == "#/definitions/TestNestedSchema"
    assert nested_dmp["description"] == "Nested 1"
    assert nested_dmp["title"] == "Title1" 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:24,代码来源:test_dump.py

示例4: test_nested_string_to_cls

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_nested_string_to_cls():
    class TestNamedNestedSchema(Schema):
        foo = fields.Integer(required=True)

    class TestSchema(Schema):
        foo2 = fields.Integer(required=True)
        nested = fields.Nested("TestNamedNestedSchema")

    schema = TestSchema()

    dumped = validate_and_dump(schema)

    nested_def = dumped["definitions"]["TestNamedNestedSchema"]
    nested_dmp = dumped["definitions"]["TestSchema"]["properties"]["nested"]
    assert nested_dmp["type"] == "object"
    assert nested_def["properties"]["foo"]["format"] == "integer" 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:18,代码来源:test_dump.py

示例5: test_list_nested

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_list_nested():
    """Test that a list field will work with an inner nested field."""

    class InnerSchema(Schema):
        foo = fields.Integer(required=True)

    class ListSchema(Schema):
        bar = fields.List(fields.Nested(InnerSchema), required=True)

    schema = ListSchema()
    dumped = validate_and_dump(schema)

    nested_json = dumped["definitions"]["ListSchema"]["properties"]["bar"]

    assert nested_json["type"] == "array"
    assert "items" in nested_json

    item_schema = nested_json["items"]
    assert "InnerSchema" in item_schema["$ref"] 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:21,代码来源:test_dump.py

示例6: test_respect_only_for_nested_schema

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_respect_only_for_nested_schema():
    """Should ignore fields not in 'only' metadata for nested schemas."""

    class InnerRecursiveSchema(Schema):
        id = fields.Integer(required=True)
        baz = fields.String()
        recursive = fields.Nested("InnerRecursiveSchema")

    class MiddleSchema(Schema):
        id = fields.Integer(required=True)
        bar = fields.String()
        inner = fields.Nested("InnerRecursiveSchema", only=("id", "baz"))

    class OuterSchema(Schema):
        foo2 = fields.Integer(required=True)
        nested = fields.Nested("MiddleSchema")

    schema = OuterSchema()
    dumped = validate_and_dump(schema)
    inner_props = dumped["definitions"]["InnerRecursiveSchema"]["properties"]
    assert "recursive" not in inner_props 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:23,代码来源:test_dump.py

示例7: test_respect_exclude_for_nested_schema

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_respect_exclude_for_nested_schema():
    """Should ignore fields in 'exclude' metadata for nested schemas."""

    class InnerRecursiveSchema(Schema):
        id = fields.Integer(required=True)
        baz = fields.String()
        recursive = fields.Nested("InnerRecursiveSchema")

    class MiddleSchema(Schema):
        id = fields.Integer(required=True)
        bar = fields.String()
        inner = fields.Nested("InnerRecursiveSchema", exclude=("recursive",))

    class OuterSchema(Schema):
        foo2 = fields.Integer(required=True)
        nested = fields.Nested("MiddleSchema")

    schema = OuterSchema()

    dumped = validate_and_dump(schema)

    inner_props = dumped["definitions"]["InnerRecursiveSchema"]["properties"]
    assert "recursive" not in inner_props 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:25,代码来源:test_dump.py

示例8: test_respect_dotted_exclude_for_nested_schema

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_respect_dotted_exclude_for_nested_schema():
    """Should ignore dotted fields in 'exclude' metadata for nested schemas."""

    class InnerRecursiveSchema(Schema):
        id = fields.Integer(required=True)
        baz = fields.String()
        recursive = fields.Nested("InnerRecursiveSchema")

    class MiddleSchema(Schema):
        id = fields.Integer(required=True)
        bar = fields.String()
        inner = fields.Nested("InnerRecursiveSchema")

    class OuterSchema(Schema):
        foo2 = fields.Integer(required=True)
        nested = fields.Nested("MiddleSchema", exclude=("inner.recursive",))

    schema = OuterSchema()

    dumped = validate_and_dump(schema)

    inner_props = dumped["definitions"]["InnerRecursiveSchema"]["properties"]
    assert "recursive" not in inner_props 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:25,代码来源:test_dump.py

示例9: test_nested_instance

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_nested_instance():
    """Should also work with nested schema instances"""

    class TestNestedSchema(Schema):
        baz = fields.Integer()

    class TestSchema(Schema):
        foo = fields.String()
        bar = fields.Nested(TestNestedSchema())

    schema = TestSchema()

    dumped = validate_and_dump(schema)

    nested_def = dumped["definitions"]["TestNestedSchema"]
    nested_obj = dumped["definitions"]["TestSchema"]["properties"]["bar"]

    assert "baz" in nested_def["properties"]
    assert nested_obj["$ref"] == "#/definitions/TestNestedSchema" 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:21,代码来源:test_dump.py

示例10: test_metadata_direct_from_field

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_metadata_direct_from_field():
    """Should be able to get metadata without accessing metadata kwarg."""

    class TestSchema(Schema):
        id = fields.Integer(required=True)
        metadata_field = fields.String(description="Directly on the field!")

    schema = TestSchema()

    dumped = validate_and_dump(schema)

    assert dumped["definitions"]["TestSchema"]["properties"]["metadata_field"] == {
        "title": "metadata_field",
        "type": "string",
        "description": "Directly on the field!",
    } 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:18,代码来源:test_dump.py

示例11: test_dumps_iterable_enums

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_dumps_iterable_enums():
    mapping = {"a": 0, "b": 1, "c": 2}

    class TestSchema(Schema):
        foo = fields.Integer(
            validate=validate.OneOf(mapping.values(), labels=mapping.keys())
        )

    schema = TestSchema()

    dumped = validate_and_dump(schema)

    assert dumped["definitions"]["TestSchema"]["properties"]["foo"] == {
        "enum": [v for v in mapping.values()],
        "enumNames": [k for k in mapping.keys()],
        "format": "integer",
        "title": "foo",
        "type": "number",
    } 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:21,代码来源:test_dump.py

示例12: test_additional_properties_from_nested_meta

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_additional_properties_from_nested_meta(additional_properties_value):
    class TestNestedSchema(Schema):
        class Meta:
            additional_properties = additional_properties_value

        foo = fields.Integer()

    class TestSchema(Schema):
        nested = fields.Nested(TestNestedSchema())

    schema = TestSchema()

    dumped = validate_and_dump(schema)

    assert (
        dumped["definitions"]["TestNestedSchema"]["additionalProperties"]
        == additional_properties_value
    ) 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:20,代码来源:test_additional_properties.py

示例13: test_range_marshmallow_3

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [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 
开发者ID:fuhrysteve,项目名称:marshmallow-jsonschema,代码行数:18,代码来源:test_validation.py

示例14: test_arguments_are_added_to_request_with_Resource_and_schema

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_arguments_are_added_to_request_with_Resource_and_schema(app, client):  # noqa
    class TestSchema(Schema):
        _id = fields.Integer()
        name = fields.String()

    api = Api(app)

    @api.route("/test")
    class TestResource(Resource):
        @accepts(
            "Foo",
            dict(name="foo", type=int, help="An important foo"),
            schema=TestSchema,
            api=api,
        )
        def post(self):
            assert request.parsed_obj
            assert request.parsed_obj["_id"] == 42
            assert request.parsed_obj["name"] == "test name"
            return "success"

    with client as cl:
        resp = cl.post("/test?foo=3", json={"_id": 42, "name": "test name"})
        assert resp.status_code == 200 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:26,代码来源:decorators_test.py

示例15: test_accepts_with_postional_args_query_params_schema_and_header_schema

# 需要导入模块: from marshmallow import fields [as 别名]
# 或者: from marshmallow.fields import Integer [as 别名]
def test_accepts_with_postional_args_query_params_schema_and_header_schema(app, client):  # noqa
    class QueryParamsSchema(Schema):
        query_param = fields.List(fields.String(), required=True)

    class HeadersSchema(Schema):
        Header = fields.Integer(required=True)

    @app.route("/test")
    @accepts(
        dict(name="foo", type=int, help="An important foo"),
        query_params_schema=QueryParamsSchema,
        headers_schema=HeadersSchema)
    def test():
        assert request.parsed_args["foo"] == 3
        assert request.parsed_query_params["query_param"] == ["baz", "qux"]
        assert request.parsed_headers["Header"] == 3
        return "success"

    with client as cl:
        resp = cl.get("/test?foo=3&query_param=baz&query_param=qux", headers={"Header": "3"})
        assert resp.status_code == 200 
开发者ID:apryor6,项目名称:flask_accepts,代码行数:23,代码来源:decorators_test.py


注:本文中的marshmallow.fields.Integer方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。