generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
## Description Removing the git controlled `.env` file and automating the dev setup process with `scripts/bootstrap.sh`. ## Additional Notes Developers should be able to customize the .env file to their environment, and not have to worry about it changing whenever they pull new code. To make the developer setup process easy, the new bootstrap script will create a .env file if it doesn't exist, initialize a virtual environment if it doesn't exist, activate the virtual env and install the development python requirements. - Connection pooling parameters now have their default values set to None, so it will work with sqlite:///:memory: - The sessionmaker autocommit parameter was removed in sqlalchemy 2.0
- Loading branch information
1 parent
7de3b70
commit 3a7e58b
Showing
8 changed files
with
94 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
# Use this script to initialize the development environment. | ||
# | ||
# Usage: source bootstrap.sh | ||
# Requires: python3 | ||
|
||
cd "$(dirname "$0")/.." | ||
|
||
# Create a default .env file if it doesn't exist | ||
if [ ! -f .env ]; then | ||
echo "Creating a default .env file..." | ||
echo "DB_URI=sqlite:///db.sqlite3" > .env | ||
else | ||
echo "Default .env file already exists." | ||
fi | ||
|
||
# Create a virtual environment if it doesn't exist | ||
if [ ! -d .venv ]; then | ||
echo "Creating a virtual environment..." | ||
python3 -m venv .venv | ||
else | ||
echo "Virtual environment already exists." | ||
fi | ||
|
||
# Activate the virtual environment | ||
echo "Activating the virtual environment..." | ||
source .venv/bin/activate | ||
# Install the development requirements | ||
echo "Installing the development requirements..." | ||
pip install --upgrade pip > /dev/null | ||
pip install '.[dev]' > /dev/null |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
""" | ||
unit.database.test_base.py | ||
~~~~~~~~~~~~~~~~~~~~~~~~~~ | ||
This module contains the unit tests for the recordlinker.database module. | ||
""" | ||
|
||
import unittest.mock | ||
|
||
from recordlinker.config import settings | ||
from recordlinker.database import create_sessionmaker | ||
|
||
|
||
def test_create_sessionmaker(): | ||
""" | ||
Test the create_sessionmaker function. | ||
""" | ||
with unittest.mock.patch.dict( | ||
"os.environ", | ||
{ | ||
"DB_URI": "sqlite:///test.db", | ||
"CONNECTION_POOL_SIZE": "10", | ||
"CONNECTION_POOL_MAX_OVERFLOW": "20", | ||
}, | ||
): | ||
settings.__init__() | ||
session = create_sessionmaker()() | ||
assert str(session.bind.url) == "sqlite:///test.db" | ||
assert session.bind.pool.size() == 10 | ||
assert session.bind.pool._max_overflow == 20 | ||
settings.__init__() |