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
2 changes: 1 addition & 1 deletion .devcontainer/aliases-devcontainer
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ alias format='scripts/format.sh'
alias makemigrations='scripts/makemigrations.sh'
alias migrate='scripts/migrate.sh'
alias shell='poetry run python src/helpers/shell.py'
alias test='pytest src'
alias test='scripts/test.sh'
7 changes: 3 additions & 4 deletions .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,17 @@ jobs:
env:
POSTGRES_USER: dev
POSTGRES_PASSWORD: dev
POSTGRES_DB: dev
POSTGRES_DB: test
ports:
- 5432:5432
options: >-
--health-cmd "pg_isready -U dev -d dev"
--health-cmd "pg_isready -U dev -d test"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
PROJECT_NAME: python-template
DATABASE_URL: postgresql://dev:dev@localhost:5432/dev
ASYNC_DATABASE_URL: postgresql+asyncpg://dev:dev@localhost:5432/dev
ASYNC_DATABASE_URL: postgresql+asyncpg://dev:dev@localhost:5432/test
DATABASE_POOL_PRE_PING: True
DATABASE_POOL_SIZE: 5
DATABASE_POOL_RECYCLE: 3600
Expand Down
20 changes: 19 additions & 1 deletion scripts/test.sh
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
#!/bin/bash

poetry run pytest src
set -e
pwd
# Ensure test database schema is up-to-date

TEST_DB_NAME="test"
TEST_DB_CONN_STRING="dev:dev@postgres:5432"

setup_test_database()
{
echo "Setting up test database"
DATABASE_URL="postgresql://$TEST_DB_CONN_STRING"
psql $DATABASE_URL -c "DROP DATABASE IF EXISTS $TEST_DB_NAME"
psql $DATABASE_URL -c "CREATE DATABASE $TEST_DB_NAME"
psql $DATABASE_URL -c "GRANT ALL PRIVILEGES ON DATABASE $TEST_DB_NAME TO dev"
DATABASE_URL="$DATABASE_URL/$TEST_DB_NAME" ./scripts/migrate.sh
}

setup_test_database
ASYNC_DATABASE_URL=postgresql+asyncpg://$TEST_DB_CONN_STRING/$TEST_DB_NAME poetry run pytest src