mega chore: update sqlalchemy (#2611)
* update sqlalchemy to 1.4 * async postgres --------- Co-authored-by: Pavol Rusnak <pavol@rusnak.io>
This commit is contained in:
parent
c637e8d31e
commit
21d87adc52
17 changed files with 1020 additions and 951 deletions
|
|
@ -367,11 +367,11 @@ async def test_get_payments_history(client, adminkey_headers_from, fake_payments
|
|||
assert response.status_code == 200
|
||||
data = response.json()
|
||||
assert len(data) == 1
|
||||
assert data[0]["spending"] == sum(
|
||||
payment.amount * 1000 for payment in fake_data if payment.out
|
||||
)
|
||||
assert data[0]["income"] == sum(
|
||||
payment.amount * 1000 for payment in fake_data if not payment.out
|
||||
[int(payment.amount * 1000) for payment in fake_data if not payment.out]
|
||||
)
|
||||
assert data[0]["spending"] == sum(
|
||||
[int(payment.amount * 1000) for payment in fake_data if payment.out]
|
||||
)
|
||||
|
||||
response = await client.get(
|
||||
|
|
|
|||
|
|
@ -25,7 +25,6 @@ from lnbits.core.views.payment_api import api_payments_create_invoice
|
|||
from lnbits.db import DB_TYPE, SQLITE, Database
|
||||
from lnbits.settings import settings
|
||||
from tests.helpers import (
|
||||
clean_database,
|
||||
get_random_invoice_data,
|
||||
)
|
||||
|
||||
|
|
@ -47,7 +46,6 @@ def event_loop():
|
|||
# use session scope to run once before and once after all tests
|
||||
@pytest_asyncio.fixture(scope="session")
|
||||
async def app():
|
||||
clean_database(settings)
|
||||
app = create_app()
|
||||
async with LifespanManager(app) as manager:
|
||||
settings.first_install = False
|
||||
|
|
@ -199,9 +197,9 @@ async def fake_payments(client, adminkey_headers_from):
|
|||
"/api/v1/payments", headers=adminkey_headers_from, json=invoice.dict()
|
||||
)
|
||||
assert response.is_success
|
||||
await update_payment_status(
|
||||
response.json()["checking_id"], status=PaymentState.SUCCESS
|
||||
)
|
||||
data = response.json()
|
||||
assert data["checking_id"]
|
||||
await update_payment_status(data["checking_id"], status=PaymentState.SUCCESS)
|
||||
|
||||
params = {"time[ge]": ts, "time[le]": time()}
|
||||
return fake_data, params
|
||||
|
|
|
|||
|
|
@ -2,11 +2,7 @@ import random
|
|||
import string
|
||||
from typing import Optional
|
||||
|
||||
from psycopg2 import connect
|
||||
from psycopg2.errors import InvalidCatalogName
|
||||
|
||||
from lnbits import core
|
||||
from lnbits.db import DB_TYPE, POSTGRES, FromRowModel
|
||||
from lnbits.db import FromRowModel
|
||||
from lnbits.wallets import get_funding_source, set_funding_source
|
||||
|
||||
|
||||
|
|
@ -35,21 +31,3 @@ set_funding_source()
|
|||
funding_source = get_funding_source()
|
||||
is_fake: bool = funding_source.__class__.__name__ == "FakeWallet"
|
||||
is_regtest: bool = not is_fake
|
||||
|
||||
|
||||
def clean_database(settings):
|
||||
if DB_TYPE == POSTGRES:
|
||||
conn = connect(settings.lnbits_database_url)
|
||||
conn.autocommit = True
|
||||
with conn.cursor() as cur:
|
||||
try:
|
||||
cur.execute("DROP DATABASE lnbits_test")
|
||||
except InvalidCatalogName:
|
||||
pass
|
||||
cur.execute("CREATE DATABASE lnbits_test")
|
||||
core.db.__init__("database")
|
||||
conn.close()
|
||||
else:
|
||||
# TODO: do this once mock data is removed from test data folder
|
||||
# os.remove(settings.lnbits_data_folder + "/database.sqlite3")
|
||||
pass
|
||||
|
|
|
|||
|
|
@ -14,8 +14,8 @@ from lnbits.db import POSTGRES
|
|||
@pytest.mark.asyncio
|
||||
async def test_date_conversion(db):
|
||||
if db.type == POSTGRES:
|
||||
row = await db.fetchone("SELECT now()::date")
|
||||
assert row and isinstance(row[0], date)
|
||||
row = await db.fetchone("SELECT now()::date as now")
|
||||
assert row and isinstance(row.get("now"), date)
|
||||
|
||||
|
||||
# make test to create wallet and delete wallet
|
||||
|
|
|
|||
|
|
@ -12,10 +12,17 @@ test = DbTestModel(id=1, name="test", value="yes")
|
|||
@pytest.mark.asyncio
|
||||
async def test_helpers_insert_query():
|
||||
q = insert_query("test_helpers_query", test)
|
||||
assert q == "INSERT INTO test_helpers_query (id, name, value) VALUES (?, ?, ?)"
|
||||
assert (
|
||||
q == "INSERT INTO test_helpers_query (id, name, value) "
|
||||
"VALUES (:id, :name, :value)"
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_helpers_update_query():
|
||||
q = update_query("test_helpers_query", test)
|
||||
assert q == "UPDATE test_helpers_query SET id = ?, name = ?, value = ? WHERE id = ?"
|
||||
assert (
|
||||
q == "UPDATE test_helpers_query "
|
||||
"SET id = :id, name = :name, value = :value "
|
||||
"WHERE id = :id"
|
||||
)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue