Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Implement email unsubscribe and opt-out system #186

Implement email unsubscribe and opt-out system

Implement email unsubscribe and opt-out system #186

Workflow file for this run

name: Backend Tests
on:
pull_request:
branches: [ main, master ]
paths:
- 'backend/**'
- '.github/workflows/backend-tests.yml'
push:
branches: [ main, master ]
paths:
- 'backend/**'
- '.github/workflows/backend-tests.yml'
workflow_dispatch:
inputs:
environment:
description: 'Environment to test against'
required: false
default: 'ci'
type: choice
options:
- ci
- development
- staging
run_migrations:
description: 'Run database migrations'
required: false
default: true
type: boolean
run_tests:
description: 'Run test suite'
required: false
default: true
type: boolean
run_coverage:
description: 'Generate coverage reports'
required: false
default: true
type: boolean
jobs:
test-backend:
runs-on: ubuntu-latest
services:
mysql:
image: mysql:8.0
env:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: divemap_test
ports:
- 3306:3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
- name: Cache pip dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pip
key: ${{ runner.os }}-pip-${{ hashFiles('backend/requirements.txt') }}
restore-keys: |
${{ runner.os }}-pip-
- name: Install dependencies
run: |
cd backend
python -m venv divemap_venv
source divemap_venv/bin/activate
pip install --upgrade pip
pip install -r requirements.txt
- name: Set up environment variables
run: |
cd backend
source divemap_venv/bin/activate
export PYTHONPATH="/home/runner/work/divemap/divemap/backend/divemap_venv/lib/python3.11/site-packages:$PYTHONPATH"
echo "PYTHONPATH=$PYTHONPATH" >> $GITHUB_ENV
echo "DATABASE_URL=mysql+pymysql://root:password@localhost:3306/divemap_test" >> $GITHUB_ENV
echo "SECRET_KEY=test-secret-key-for-ci" >> $GITHUB_ENV
echo "ENVIRONMENT=${{ github.event.inputs.environment || 'ci' }}" >> $GITHUB_ENV
echo "GOOGLE_CLIENT_ID=dummy-client-id-for-testing" >> $GITHUB_ENV
echo "GITHUB_ACTIONS=true" >> $GITHUB_ENV
- name: Set up MySQL database
if: ${{ github.event.inputs.run_migrations != 'false' || github.event_name != 'workflow_dispatch' }}
run: |
cd backend
source divemap_venv/bin/activate
export DATABASE_URL="mysql+pymysql://root:password@localhost:3306/divemap_test"
export PYTHONPATH="/home/runner/work/divemap/divemap/backend/divemap_venv/lib/python3.11/site-packages:$PYTHONPATH"
# The database is already created by the MySQL service container
echo "✅ MySQL test database ready"
- name: Run database migrations
if: ${{ github.event.inputs.run_migrations != 'false' || github.event_name != 'workflow_dispatch' }}
run: |
cd backend
source divemap_venv/bin/activate
export DATABASE_URL="mysql+pymysql://root:password@localhost:3306/divemap_test"
export PYTHONPATH="/home/runner/work/divemap/divemap/backend/divemap_venv/lib/python3.11/site-packages:$PYTHONPATH"
alembic upgrade head
- name: Run backend tests
if: ${{ github.event.inputs.run_tests != 'false' || github.event_name != 'workflow_dispatch' }}
run: |
cd backend
source divemap_venv/bin/activate
python -m pytest tests/ -v --cov=app --cov-report=term-missing --cov-report=html --cov-report=xml -x --maxfail=1 --tb=short
- name: Upload coverage reports
if: ${{ (github.event.inputs.run_coverage != 'false' || github.event_name != 'workflow_dispatch') && always() }}
uses: codecov/codecov-action@v5
with:
directory: ./backend/
flags: backend
name: backend-coverage
fail_ci_if_error: false
token: ${{ secrets.CODECOV_TOKEN }}
- name: Upload test results
uses: actions/upload-artifact@v4
if: always()
with:
name: test-results
path: |
backend/htmlcov/
backend/.pytest_cache/