Exemple #1
0
async def lifespan(
        chdir_tmp_path: pathlib.Path,
        lifecycle: Any) -> AsyncIterator[asgi_lifespan.LifespanManager]:
    config = config_lib.Config(public_enable=False, )
    config.update(
        {f"session_{k}": v
         for k, v in get_isolated_settings().items()})
    await config.write_to_disk(services.CONFIG_PATH)
    async with asgi_lifespan.LifespanManager(app_lib.APP,
                                             startup_timeout=None,
                                             shutdown_timeout=None) as manager:
        yield manager
Exemple #2
0
async def client():
    """fixture to provide a http AsyncClient on our app"""
    from tome.app import app
    import tome.database

    async with asgi_lifespan.LifespanManager(app):
        async with httpx.AsyncClient(app=app,
                                     base_url="http://testserver") as client:
            transaction = tome.database.connection().transaction()
            await transaction.start()
            try:
                yield client
            finally:
                await transaction.rollback()
Exemple #3
0
    async def asyncSetUp(self) -> None:
        await super().asyncSetUp()
        self.tempdir = await concurrency.to_thread(tempfile.TemporaryDirectory)
        self.cwd = await concurrency.to_thread(pathlib.Path.cwd)
        await concurrency.to_thread(os.chdir, self.tempdir.name)
        self.config = create_isolated_config()
        await self.config.write_to_disk(services.CONFIG_PATH)
        self.lifespan_manager = asgi_lifespan.LifespanManager(
            app_lib.APP, startup_timeout=None, shutdown_timeout=None
        )
        await asyncio.wait_for(self.lifespan_manager.__aenter__(), 5)

        # https://github.com/encode/httpx/issues/2239: httpx doesn't honor timeouts for
        # ASGI/WSGI

        async def app_with_timeout(*args) -> None:
            await asyncio.wait_for(app_lib.APP(*args), 5)

        self.client = httpx.AsyncClient(
            app=app_with_timeout,
            base_url="http://test",
            follow_redirects=True,
            timeout=5,
        )
Exemple #4
0
async def client(storage) -> AsyncClient:
    # https://fastapi.tiangolo.com/advanced/testing-events/
    # https://github.com/encode/starlette/issues/104
    async with asgi_lifespan.LifespanManager(app):  # trigger events
        async with AsyncClient(app=app, base_url="http://test") as c:
            yield c
Exemple #5
0
async def app():
    app = create_app(debug=True)
    async with asgi_lifespan.LifespanManager(app):
        yield app
Exemple #6
0
async def app(
    service_settings: ServiceSettings,
) -> AsyncGenerator[fastapi.FastAPI, None]:
    application = get_application(settings=service_settings)
    async with asgi_lifespan.LifespanManager(application):
        yield application