async def _(api: Api, bp: Blueprint, hook: type[RequestHandlerProtocol]): api.add_blueprint("", bp) async with api.client() as client: response = await client.get("/") assert response.status_code == HTTPStatus.OK hook_view = api._view_cache[hook] hook_view.mock.assert_called_once()
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
async def _( api: Api, bp: Blueprint, view: type[RequestHandlerProtocol], params: dict, ): api.add_blueprint("", bp) path = api.url_for(view, params) async with api.client() as client: with raises(NotFoundError): await client.get(path)
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]
async def _(api: Api, bp: Blueprint): child_bp = Blueprint() @child_bp.route("/child") class Child: pass bp.add_blueprint("/and", child_bp) api.add_blueprint("/parent", bp) async with api.client() as client: response = await client.get("/parent/and/child") assert response.status_code == HTTPStatus.OK
async def _( api: Api, bp: Blueprint, view: type[RequestHandlerProtocol], params: dict, ): api.add_blueprint("", bp) path = api.url_for(view, params) async with api.client() as client: response = await client.get(path) assert response.status_code == HTTPStatus.OK assert response.json["number"] == params["number"] assert response.json["name"] == params["name"].upper()
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
async def _(api: Api, bp: Blueprint): api.add_blueprint("", bp) async with api.client() as client: response = await client.get("/not/defined") assert response.status_code == 418
async def _(api: Api, bp: Blueprint, startup: MagicMock, shutdown: MagicMock): api.add_blueprint("", bp) async with api.client(): startup.assert_called_once() shutdown.assert_not_called() shutdown.assert_called_once()