Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/storage/db_connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ def __init__(
address = '/var/run/postgresql'
port = config.common.postgres.port

database = db_name if db_name else config.common.postgres.database
self.database = db_name if db_name else config.common.postgres.database
engine_url = URL.create(
'postgresql',
username=user,
password=password,
host=address,
port=port,
database=database,
database=self.database,
)
self.engine = create_engine(engine_url, pool_size=100, future=True, **kwargs)
self.session_maker = sessionmaker(bind=self.engine, future=True) # future=True => sqlalchemy 2.0 support
Expand Down
2 changes: 2 additions & 0 deletions src/test/common_helper.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from pathlib import Path
from typing import TYPE_CHECKING, Callable

import config
from helperFunctions.fileSystem import get_src_dir
from helperFunctions.tag import TagColor
from objects.file import FileObject
Expand Down Expand Up @@ -299,6 +300,7 @@ def setup_test_tables(db_setup):


def clear_test_tables(db_setup):
assert db_setup.connection.database == config.common.postgres.test_database
db_setup.connection.base.metadata.drop_all(db_setup.connection.engine)


Expand Down
3 changes: 3 additions & 0 deletions src/test/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ def _database_interfaces(): # noqa: PT005
with pytest.MonkeyPatch.context() as mpk:
config.load()
# Make sure to match the config here with the one in src/conftest.py:common_config
assert config.common.postgres.database != config.common.postgres.test_database
sections = {
'postgres': {
'server': config.common.postgres.server,
Expand Down Expand Up @@ -178,6 +179,7 @@ def _database_interfaces(): # noqa: PT005
comparison = ComparisonDbInterface(connection=rw_connection)
admin = AdminDbInterface(intercom=MockIntercom())
stats_update = StatsUpdateDbInterface(connection=rw_connection)
assert common.connection.database == config.common.postgres.test_database

setup_test_tables(db_setup)

Expand All @@ -195,6 +197,7 @@ def database_interfaces(_database_interfaces) -> DatabaseInterfaces:
yield _database_interfaces
finally:
with _database_interfaces.admin.get_read_write_session() as session:
assert _database_interfaces.admin.connection.database == config.common.postgres.test_database
# clear rows from test db between tests
for table in reversed(_database_interfaces.admin.connection.base.metadata.sorted_tables):
session.execute(table.delete())
Expand Down