示例#1
0
def test_base_field(
    app, description, required, name, choices, serialized_field, path_parameters
):

    field = doc.Field(
        description=description, required=required, name=name, choices=choices
    )
    assert field.serialize() == serialized_field

    @app.get("/")
    @doc.consumes(field, location="body", required=True)
    def test(request):
        return text("test")

    _, response = app.test_client.get("/swagger/swagger.json")
    assert response.status == 200
    assert response.content_type == "application/json"

    swagger_json = response.json
    path = swagger_json["paths"]["/"]["get"]
    assert path["parameters"] == path_parameters
示例#2
0
        "name": None,
        "type": "string",
        "format": "uuid",
        "required": True,
    }


class TestSchema:
    pass


@pytest.mark.parametrize(
    "schema, expected_schema",
    [
        (doc.Field, {}),
        (doc.Field(), {}),
        (int, {"type": "integer", "format": "int64"}),
        (doc.Integer, {"type": "integer", "format": "int64"}),
        (doc.Integer(), {"type": "integer", "format": "int64"}),
        (float, {"type": "number", "format": "double"}),
        (doc.Float, {"type": "number", "format": "double"}),
        (doc.Float(), {"type": "number", "format": "double"}),
        (str, {"type": "string"}),
        (doc.String, {"type": "string"}),
        (doc.String(), {"type": "string"}),
        (bool, {"type": "boolean"}),
        (doc.Boolean, {"type": "boolean"}),
        (doc.Boolean(), {"type": "boolean"}),
        (date, {"type": "string", "format": "date"}),
        (doc.Date, {"type": "string", "format": "date"}),
        (doc.Date(), {"type": "string", "format": "date"}),