Testing: postgres db backend (#711)

* try postgres run

* fix yaml

* test with postgres

* check with postgres

* inkey_from

* remove trio

* add coverage

* add coverage

* more python testing

* use @pytest_asyncio.fixture

* remove unused imports

* fix api_payment payment lookup

* measure durations
This commit is contained in:
calle 2022-07-07 18:29:26 +02:00 committed by GitHub
parent 262bd32f44
commit 63d4e60542
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 91 additions and 45 deletions

View file

@ -1,5 +1,6 @@
import asyncio
import pytest
import pytest_asyncio
from httpx import AsyncClient
from lnbits.app import create_app
from lnbits.commands import migrate_databases
@ -15,7 +16,7 @@ from lnbits.core.models import User, Wallet, Payment, BalanceCheck
from typing import Tuple
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
def event_loop():
loop = asyncio.get_event_loop()
yield loop
@ -23,7 +24,7 @@ def event_loop():
# use session scope to run once before and once after all tests
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
def app(event_loop):
app = create_app()
# use redefined version of the event loop for scope="session"
@ -37,19 +38,19 @@ def app(event_loop):
# loop.close()
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
async def client(app):
client = AsyncClient(app=app, base_url=f"http://{HOST}:{PORT}")
yield client
await client.aclose()
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
async def db():
yield Database("database")
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
async def from_user_wallet():
user = await create_account()
wallet = await create_wallet(user_id=user.id, wallet_name="test_wallet_from")
@ -61,7 +62,7 @@ async def from_user_wallet():
yield user, wallet
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
async def to_user_wallet():
user = await create_account()
wallet = await create_wallet(user_id=user.id, wallet_name="test_wallet_to")
@ -73,7 +74,7 @@ async def to_user_wallet():
yield user, wallet
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
async def inkey_headers_from(from_user_wallet):
_, wallet = from_user_wallet
yield {
@ -82,7 +83,7 @@ async def inkey_headers_from(from_user_wallet):
}
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
async def adminkey_headers_from(from_user_wallet):
_, wallet = from_user_wallet
yield {
@ -91,7 +92,7 @@ async def adminkey_headers_from(from_user_wallet):
}
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
async def inkey_headers_to(to_user_wallet):
_, wallet = to_user_wallet
yield {
@ -100,7 +101,7 @@ async def inkey_headers_to(to_user_wallet):
}
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
async def adminkey_headers_to(to_user_wallet):
_, wallet = to_user_wallet
yield {
@ -109,7 +110,7 @@ async def adminkey_headers_to(to_user_wallet):
}
@pytest.fixture(scope="session")
@pytest_asyncio.fixture(scope="session")
async def invoice(to_user_wallet):
_, wallet = to_user_wallet
data = await get_random_invoice_data()