def test_missing_method(self): @api class API: def GET(arg: str): ... class Impl(TestControllerBase): pass app = web.Application() with self.assertRaises(MissingImplementationError) as cm: bind(app.router, API, Impl()) self.assertEqual(cm.exception.methname, "GET")
def test_signature_checking(self): @api class API: def GET(arg: str): ... class Impl(TestControllerBase): async def GET(self, arg: int): return arg app = web.Application() with self.assertRaises(SignatureMisatchError) as cm: bind(app.router, API, Impl()) self.assertEqual(cm.exception.methname, "API.GET")
async def start_api_server(self): app = web.Application(middlewares=[self.middleware]) bind(app.router, API.meta, MetaController(self)) bind(app.router, API.errors, ErrorController(self)) if self.opts.dry_run: from .dryrun import DryRunController bind(app.router, API.dry_run, DryRunController(self)) runner = web.AppRunner(app) await runner.setup() site = web.UnixSite(runner, self.opts.socket) await site.start()
async def start_api_server(self): app = web.Application(middlewares=[self.middleware]) bind(app.router, API.meta, MetaController(self)) bind(app.router, API.errors, ErrorController(self)) if self.opts.dry_run: from .dryrun import DryRunController bind(app.router, API.dry_run, DryRunController(self)) for controller in self.controllers.instances: controller.add_routes(app) runner = web.AppRunner(app) await runner.setup() site = web.UnixSite(runner, self.opts.socket) await site.start() # It is intended that a non-root client can connect. os.chmod(self.opts.socket, 0o666)
def add_routes(self, app): if self.endpoint is not None: bind(app.router, self.endpoint, self)
async def makeTestClient(api, impl, middlewares=()): app = web.Application(middlewares=middlewares) bind(app.router, api, impl) async with TestClient(TestServer(app)) as client: yield client