refactor: use new fastapi lifespan instead of startup/shutdown events (#2294)

* refactor: use new fastapi lifespan instead of events
recommended use: https://fastapi.tiangolo.com/advanced/events/?h=lifespan
threw warnings in pytest
* make startup and shutdown functions
* nix: add override for asgi-lifespan

---------

Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
dni ⚡ 2024-04-05 07:05:26 +02:00 committed by GitHub
parent d64239f1ad
commit 820882db28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 95 additions and 75 deletions

View file

@ -3,6 +3,7 @@ import asyncio
from time import time
import uvloop
from asgi_lifespan import LifespanManager
uvloop.install()
@ -35,6 +36,7 @@ settings.lnbits_admin_extensions = []
settings.lnbits_data_folder = "./tests/data"
settings.lnbits_admin_ui = True
settings.lnbits_extensions_default_install = []
settings.lnbits_extensions_deactivate_all = True
@pytest_asyncio.fixture(scope="session")
@ -49,17 +51,16 @@ def event_loop():
async def app():
clean_database(settings)
app = create_app()
await app.router.startup()
settings.first_install = False
yield app
await app.router.shutdown()
async with LifespanManager(app) as manager:
settings.first_install = False
yield manager.app
@pytest_asyncio.fixture(scope="session")
async def client(app):
client = AsyncClient(app=app, base_url=f"http://{settings.host}:{settings.port}")
yield client
await client.aclose()
url = f"http://{settings.host}:{settings.port}"
async with AsyncClient(app=app, base_url=url) as client:
yield client
@pytest.fixture(scope="session")