示例#1
0
def test_stupeflask_response_with_empty_list(json_app, client):
    json_app.route("/")(lambda: [])
    response = client.get("/")
    assert response.status_code == 200

    response_dict = response_to_dict(response)
    assert response_dict.get("data") == []
    assert response_dict["code"] == 200
示例#2
0
def test_stupeflask_response_with_data_and_code(json_app, client):
    json_app.route("/")(lambda: ("foo", 201))
    response = client.get("/")
    assert response.status_code == 201

    response_dict = response_to_dict(response)
    assert response_dict["data"] == "foo"
    assert response_dict["code"] == 201
示例#3
0
def test_stupeflask_response_with_code(json_app, client):
    json_app.route("/")(lambda: 201)
    response = client.get("/")
    assert response.status_code == 201

    response_dict = response_to_dict(response)
    assert "data" not in response_dict
    assert response_dict["code"] == 201
示例#4
0
def test_stupeflask_converters(json_app, client):
    @json_app.route("/<ObjectId:foo_id>")
    def foo_id(foo_id):
        return foo_id

    object_id = ObjectId()
    response = client.get("/{}".format(object_id))
    assert response.status_code == 200

    response_dict = response_to_dict(response)
    assert response_dict["data"] == str(object_id)
示例#5
0
def test_stupeflask_response_with_metadata(json_app, client):
    @json_app.route("/")
    def foo():
        from flask import request
        request.metadata.update(bar="baz")

    response = client.get("/")
    assert response.status_code == 200

    response_dict = response_to_dict(response)
    assert "data" not in response_dict
    assert response_dict["code"] == 200
    assert response_dict["bar"] == "baz"
示例#6
0
def test_stupeflask_response_with_paginate(json_app, client):
    encoder_rules.append((Cursor, lambda c: c.data))

    @json_app.route("/")
    @paginate(limit=2)
    def foo():
        return Cursor([1, 2, 3])

    response = client.get("/")
    assert response.status_code == 200

    response_dict = response_to_dict(response)
    assert len(response_dict["data"]) == 2
    assert response_dict["code"] == 200
    assert response_dict["count"] == 3