2021-11-17 10:53:32 -06:00
|
|
|
import asyncio
|
2020-04-27 19:01:53 +02:00
|
|
|
import pytest
|
2021-11-17 10:53:32 -06:00
|
|
|
from httpx import AsyncClient
|
2020-09-05 08:00:44 +02:00
|
|
|
from lnbits.app import create_app
|
2021-11-17 10:53:32 -06:00
|
|
|
from lnbits.commands import migrate_databases
|
|
|
|
from lnbits.settings import HOST, PORT
|
|
|
|
import tests.mocks
|
2020-04-27 19:01:53 +02:00
|
|
|
|
2021-11-17 10:53:32 -06:00
|
|
|
# use session scope to run once before and once after all tests
|
|
|
|
@pytest.fixture(scope="session")
|
|
|
|
def app():
|
|
|
|
# yield and pass the app to the test
|
2020-09-05 08:00:44 +02:00
|
|
|
app = create_app()
|
2021-11-17 10:53:32 -06:00
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
loop.run_until_complete(migrate_databases())
|
|
|
|
yield app
|
|
|
|
# get the current event loop and gracefully stop any running tasks
|
|
|
|
loop = asyncio.get_event_loop()
|
|
|
|
loop.run_until_complete(loop.shutdown_asyncgens())
|
|
|
|
loop.close()
|
2020-04-27 19:01:53 +02:00
|
|
|
|
2021-11-17 10:53:32 -06:00
|
|
|
@pytest.fixture
|
|
|
|
async def client(app):
|
|
|
|
client = AsyncClient(app=app, base_url=f'http://{HOST}:{PORT}')
|
|
|
|
# yield and pass the client to the test
|
|
|
|
yield client
|
|
|
|
# close the async client after the test has finished
|
|
|
|
await client.aclose()
|