Skip to content
Snippets Groups Projects
Verified Commit a0923841 authored by Karel van Klink's avatar Karel van Klink :smiley_cat:
Browse files

Update unit tests' psycopg to v3

parent 17076de5
Branches
Tags
1 merge request!377Update dependencies
......@@ -169,9 +169,9 @@ def db_uri():
database_host = os.getenv("DATABASE_HOST", "localhost")
if worker_id:
return f"postgresql://nwa:nwa@{database_host}/gso-test-db_{worker_id}"
return f"postgresql+psycopg://nwa:nwa@{database_host}/gso-test-db_{worker_id}"
return os.environ.get("DATABASE_URI_TEST", f"postgresql://nwa:nwa@{database_host}/gso-test-db")
return os.environ.get("DATABASE_URI_TEST", f"postgresql+psycopg://nwa:nwa@{database_host}/gso-test-db")
def run_migrations(db_uri: str) -> None:
......@@ -212,15 +212,14 @@ def _database(db_uri):
engine = create_engine(url)
with engine.connect() as conn:
conn.execute(text("COMMIT;"))
conn.execute(
text("SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname=:db_name").bindparams(
db_name=db_to_create,
),
)
conn.execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";'))
conn.execute(text("COMMIT;"))
conn.commit()
conn.execution_options(isolation_level="AUTOCOMMIT").execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";'))
conn.commit()
conn.execute(text(f'CREATE DATABASE "{db_to_create}";'))
run_migrations(db_uri)
......@@ -231,12 +230,13 @@ def _database(db_uri):
finally:
db.wrapped_database.engine.dispose()
with engine.connect() as conn:
conn.execute(text("COMMIT;"))
# Terminate all connections to the database
conn.execute(
text(f"SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='{db_to_create}';"), # noqa: S608
)
conn.execute(text(f'DROP DATABASE IF EXISTS "{db_to_create}";'))
conn.commit()
conn.execution_options(isolation_level="AUTOCOMMIT").execute(
text(f'DROP DATABASE IF EXISTS "{db_to_create}";')
)
@pytest.fixture(autouse=True)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment