Skip to content
Merged
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
7 changes: 6 additions & 1 deletion python_template_server/db/base_database_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,15 @@ class BaseDatabaseManager(ABC):
"""Manager class for database operations.

Subclasses must implement the `db_url` property to provide the correct database URL.
The database manager must be configured using `configure()` after the server has loaded the configuration.
"""

def __init__(self, db_config: DatabaseConfig) -> None:
def __init__(self) -> None:
"""Initialize the database manager."""
logger.info("Ready to be configured...")

def configure(self, db_config: DatabaseConfig) -> None:
"""Configure the database manager with the given configuration."""
self.db_config = db_config
self.db_config.db_directory.mkdir(parents=True, exist_ok=True)

Expand Down
7 changes: 4 additions & 3 deletions tests/db/test_base_database_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,17 @@ def db_url(self) -> str:
@pytest.fixture
def mock_database_manager(mock_db_config: DatabaseConfig) -> Generator[BaseDatabaseManager]:
"""Fixture for creating a mock database manager."""
db_manager = MockDatabaseManager(db_config=mock_db_config)
db_manager = MockDatabaseManager()
db_manager.configure(mock_db_config)
yield db_manager
db_manager.engine.dispose()


class TestBaseDatabaseManager:
"""Unit tests for the BaseDatabaseManager class."""

def test_initialization(self, mock_database_manager: BaseDatabaseManager) -> None:
"""Test that the database manager initializes correctly."""
def test_configuration(self, mock_database_manager: BaseDatabaseManager) -> None:
"""Test that the database manager is configured correctly."""
assert isinstance(mock_database_manager.db_config, DatabaseConfig)
assert isinstance(mock_database_manager.engine, Engine)

Expand Down