Ejemplo n.º 1
0
async def api_client(aiohttp_client, coresys: CoreSys):
    """Fixture for RestAPI client."""
    api = RestAPI(coresys)
    api.webapp = web.Application()
    api.start = AsyncMock()
    await api.load()
    yield await aiohttp_client(api.webapp)
Ejemplo n.º 2
0
async def api_client(aiohttp_client, coresys: CoreSys):
    """Fixture for RestAPI client."""
    @web.middleware
    async def _security_middleware(request: web.Request,
                                   handler: web.RequestHandler):
        """Make request are from Core."""
        request[REQUEST_FROM] = coresys.homeassistant
        return await handler(request)

    api = RestAPI(coresys)
    api.webapp = web.Application(middlewares=[_security_middleware])
    api.start = AsyncMock()
    await api.load()
    yield await aiohttp_client(api.webapp)