O2Sound_ver2_final/backend/run-tests.sh

98 lines
3.0 KiB
Bash

#!/bin/bash
# 테스트 실행 스크립트 (PostgreSQL 지원)
echo "🧪 Running Backend API Tests..."
echo "================================"
# 환경변수 설정 - BE_ENV를 local로 설정
export TESTING=1
export BE_ENV=local
export ENVIRONMENT=local
# .env.test 파일이 있으면 로드
if [ -f .env.test ]; then
echo "📋 Loading test environment from .env.test"
# python-dotenv가 설치되어 있는지 확인
if ! poetry show python-dotenv &> /dev/null; then
echo "Installing python-dotenv..."
poetry add python-dotenv --group dev
fi
fi
# PostgreSQL 연결 테스트
test_postgres_connection() {
if [ -n "$TEST_DATABASE_URL" ]; then
echo "🔍 Testing PostgreSQL connection..."
poetry run python -c "
import os
from sqlalchemy import create_engine
# .env.test 파일 로드
from dotenv import load_dotenv
load_dotenv('.env.test')
db_url = os.getenv('TEST_DATABASE_URL', 'postgresql://postgres:postgres@localhost:5432/test_o2sound')
try:
engine = create_engine(db_url)
conn = engine.connect()
conn.close()
print('✅ PostgreSQL connection successful')
except Exception as e:
print(f'❌ PostgreSQL connection failed: {e}')
exit(1)
"
return $?
fi
return 0
}
# 테스트 실행 옵션
if [ "$1" = "coverage" ]; then
echo "📊 Running tests with coverage..."
test_postgres_connection
poetry run pytest tests/ --cov=app --cov-report=html --cov-report=term-missing
elif [ "$1" = "verbose" ]; then
echo "🔍 Running tests in verbose mode..."
test_postgres_connection
poetry run pytest tests/ -v
elif [ "$1" = "auth" ]; then
echo "🔐 Running auth tests only..."
test_postgres_connection
poetry run pytest tests/api/v1/test_auth.py -v
elif [ "$1" = "user" ]; then
echo "👤 Running user tests only..."
test_postgres_connection
poetry run pytest tests/api/v1/test_user.py -v
elif [ "$1" = "moviemaker" ]; then
echo "🎬 Running moviemaker tests only..."
test_postgres_connection
poetry run pytest tests/api/v1/test_moviemakers.py -v
elif [ "$1" = "social" ]; then
echo "🌐 Running social tests only..."
test_postgres_connection
poetry run pytest tests/api/v1/test_social.py -v
elif [ "$1" = "video" ]; then
echo "📹 Running video tests only..."
test_postgres_connection
poetry run pytest tests/api/v1/test_uservideo.py -v
elif [ "$1" = "integration" ]; then
echo "🔄 Running integration tests..."
test_postgres_connection
poetry run pytest tests/test_database_integration.py tests/test_integration_scenarios.py -v
elif [ "$1" = "sqlite" ]; then
echo "💾 Running tests with SQLite (limited functionality)..."
export USE_SQLITE_TEST=1
poetry run pytest tests/api/ -v
elif [ "$1" = "setup" ]; then
echo "🐘 Setting up PostgreSQL test environment..."
./setup-postgres-test.sh
else
echo "🚀 Running all tests..."
test_postgres_connection
poetry run pytest tests/
fi
echo "================================"
echo "✅ Test execution completed!"