test: lint tests and tools aswell (#2296)

* test: lint `tests` and `tools` aswell

more linting :)

* fix linting issues in tests and tools

* fixup!

* how is this working?
This commit is contained in:
dni ⚡
2024-02-27 14:30:52 +01:00
committed by GitHub
parent e8aa498683
commit 884a1b9d6f
6 changed files with 103 additions and 28 deletions

View File

@ -7,9 +7,9 @@ import time
from subprocess import PIPE, Popen, TimeoutExpired
from typing import Tuple
import psycopg2
from loguru import logger
from sqlalchemy.engine.url import make_url
from psycopg2 import connect
from psycopg2.errors import InvalidCatalogName
from lnbits import core
from lnbits.db import DB_TYPE, POSTGRES
@ -158,24 +158,17 @@ def pay_onchain(address: str, sats: int) -> str:
def clean_database(settings):
if DB_TYPE == POSTGRES:
db_url = make_url(settings.lnbits_database_url)
conn = psycopg2.connect(settings.lnbits_database_url)
conn = connect(settings.lnbits_database_url)
conn.autocommit = True
with conn.cursor() as cur:
try:
cur.execute("DROP DATABASE lnbits_test")
except psycopg2.errors.InvalidCatalogName:
except InvalidCatalogName:
pass
cur.execute("CREATE DATABASE lnbits_test")
db_url.database = "lnbits_test"
settings.lnbits_database_url = str(db_url)
core.db.__init__("database")
conn.close()
else:
# FIXME: do this once mock data is removed from test data folder
# TODO: do this once mock data is removed from test data folder
# os.remove(settings.lnbits_data_folder + "/database.sqlite3")
pass