Exemplo n.º 1
0
def test_add_rule_decorators(client, flask_app):
    def hello_world():
        return "hello world"

    api = Api(flask_app, request_decorators=[auth_required])
    api.add_url_rule("/",
                     "index",
                     hello_world,
                     request_decorators={"POST": [post_hook]})
    resp = client.get("/")
    assert resp.status_code == 403
    resp = client.post("/", headers={"auth": True})
    assert resp.status_code == 200
    assert resp.data == b"hello worldpost_hook"
Exemplo n.º 2
0
def test_url_rule(flask_app, client):
    def hello_world(name):
        return f"hello {name}"

    api = Api(flask_app)
    api.add_url_rule("/<string:name>", "index", hello_world)
    resp = client.get("/raynor")
    assert resp.status_code == 200
    assert resp.data == b"hello raynor"

    resp = client.post("/kerrigan")
    assert resp.status_code == 200
    assert resp.data == b"hello kerrigan"

    resp = client.put("/artanis")
    assert resp.status_code == 200
    assert resp.data == b"hello artanis"

    resp = client.delete("/zeratul")
    assert resp.status_code == 200
    assert resp.data == b"hello zeratul"