Example #1
0
class ItemPutRequest:
    id = doc.Integer()  # Ignored in favor of URL
    brand = doc.String()
    name = doc.String(required=True)
    item_size = doc.Float(required=True)
    unit = doc.String(required=True)
    count = doc.Float(required=True)
    serving = doc.Float()
    category = doc.String()
    subcategory = doc.String()
    expiration_date = doc.Date()
    purchase_date = doc.Date()
    created_at = doc.DateTime()
    deleted_at = doc.DateTime()
    inventory_id = doc.Integer(required=True)
Example #2
0
def test_datetime_field(app):

    field = doc.DateTime()
    assert field.serialize() == {"type": "string", "format": "date-time"}

    @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"][0] == {
        "required": True,
        "in": "body",
        "name": None,
        "type": "string",
        "format": "date-time",
    }
Example #3
0
        (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"}),
        (datetime, {"type": "string", "format": "date-time"}),
        (doc.DateTime, {"type": "string", "format": "date-time"}),
        (doc.DateTime(), {"type": "string", "format": "date-time"}),
        (TestSchema, {"$ref": "#/definitions/TestSchema"}),
        (dict, {"type": "object", "properties": {}}),
        ({"foo": "bar"}, {"type": "object", "properties": {"foo": {}}}),
        (list, {"type": "array", "items": []}),
        (["foo", "bar"], {"type": "array", "items": {"description": ["foo", "bar"]}}),
    ],
)
def test_serialize_schema(schema, expected_schema):
    serialized_schema = doc.serialize_schema(schema)

    assert serialized_schema == expected_schema


def test_jsonbody_field(app):
    field = doc.JsonBody()
Example #4
0
db_conn = pymysql.Connect(host="127.0.0.1",
                          user="******",
                          password="******",
                          db="auto_water",
                          cursorclass=pymysql.cursors.DictCursor)


@app.get("/temp")
@doc.produces(
    {
        "ID": doc.Integer("record's id"),
        "IOT_ID": doc.Integer("iot's id"),
        "air_temp": doc.Float("air temperature"),
        "air_hum": doc.Float("air hum"),
        "dirt_hum": doc.Float("dirt hum"),
        "ts": doc.DateTime("timestamp")
    },
    content_type="application/json")
async def get_record(request):
    result = None
    with db_conn.cursor() as cur:
        sql = "SELECT * FROM `record` LIMIT 100"
        cur.execute(sql)
        result = cur.fetchall()

    for line in result:
        line["ts"] = line["ts"].strftime("%Y-%m-%d %H:%M:%S")
    return json(result)


@app.post("/temp")
Example #5
0
     "type": "string",
     "format": "date"
 }),
 (doc.Date(), {
     "type": "string",
     "format": "date"
 }),
 (datetime, {
     "type": "string",
     "format": "date-time"
 }),
 (doc.DateTime, {
     "type": "string",
     "format": "date-time"
 }),
 (doc.DateTime(), {
     "type": "string",
     "format": "date-time"
 }),
 (TestSchema, {
     "$ref": "#/definitions/TestSchema"
 }),
 (dict, {
     "type": "object",
     "properties": {}
 }),
 ({
     "foo": "bar"
 }, {
     "type": "object",
     "properties": {
class FriendRequest:
    sender = doc.Integer('user id of the user requested')
    created_at = doc.DateTime('timestamp when the request was sent')
class Friend:
    friend_id = doc.Integer('user id of the friend')
    created_at = doc.DateTime(
        'timestamp when the relationship was established')
Example #8
0
class FavoriteResponse:
    video_id = doc.Integer()
    favorite = doc.DateTime()
Example #9
0
 class test_result:
     test_date = doc.DateTime()
     duration = doc.Integer()
     summary = doc.String()
     status = doc.String()  #default='FAIL')
     more_result = doc.JsonBody()