示例#1
0
async def _(api: Api, bp: Blueprint, path_code: tuple[str, int]):
    api.routing = "clone"
    api.add_blueprint("/", bp)
    api.add_blueprint("start", bp)
    async with api.client() as client:
        path, code = path_code
        response = await client.get(path, allow_redirects=False)
        assert response.status_code == code
示例#2
0
async def _(api: Api, bp: Blueprint, path_code: tuple[str, int]):
    api.routing = "no_slash"
    api.add_blueprint("/", bp)
    api.add_blueprint("start", bp)
    async with api.client() as client:
        path, code = path_code
        response = await client.get(path, allow_redirects=False)
        assert response.status_code == code
        if response.status_code == HTTPStatus.PERMANENT_REDIRECT:
            location = response.headers["location"]
            assert location == path[:-1]
示例#3
0
def mix_routes(api: Api, bp: Blueprint):
    api.routing = "slash"

    @bp.route("/foo", routing="strict")
    class Foo:
        async def on_post(self, req, resp):
            pass

    @bp.route("/bar")
    class Bar:
        async def on_post(self, req, resp):
            pass

    @bp.route("/baz", routing="no_slash")
    class Baz:
        async def on_post(self, req, resp):
            pass

    api.add_blueprint("/", bp)
    return api