diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 386fd7a..cc01ab2 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -17,6 +17,8 @@ jobs: - run: ./test.sh working-directory: flask - run: ./fastapi/test.sh + env: + DATABASE_URL: postgresql+asyncpg://postgres:postgrespass@localhost:5432/postgres services: postgres: diff --git a/fastapi/35-example-model.sh b/fastapi/35-example-model.sh new file mode 100755 index 0000000..d018fad --- /dev/null +++ b/fastapi/35-example-model.sh @@ -0,0 +1,164 @@ +#!/bin/bash + +# This step adds an example SQLAlchemy model with CRUD routes and tests +# using a real PostgreSQL database. +# It is NOT included in everything.sh — it exists solely to verify +# that the scaffolded app can easily be extended with new models. + +# Determine project name if not set +if [[ -z "$FASTAPI_PROJECT_NAME" ]]; then + FASTAPI_PROJECT_NAME=$(basename "$PWD") + FASTAPI_PROJECT_NAME=${FASTAPI_PROJECT_NAME//[-.]/_} + export FASTAPI_PROJECT_NAME +fi + +# Install pytest-asyncio for async test support +poetry add --group dev 'pytest-asyncio==*' + +# Create example SQLAlchemy model with routes +cat > "$FASTAPI_PROJECT_NAME/example.py" < "conftest.py" < "test_app.py" <