#!/bin/bash
# Quick test runner script for django-cronjob-utils
# Usage: ./run_tests.sh [test_file] [test_class] [test_method]

set -e

# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color

echo -e "${BLUE}Running django-cronjob-utils tests...${NC}"

# Check if virtual environment is activated
if [ -z "$VIRTUAL_ENV" ]; then
    echo "Warning: Virtual environment not detected. Activate it first:"
    echo "  source venv/bin/activate"
    echo ""
fi

# Check if Django settings are set
if [ -z "$DJANGO_SETTINGS_MODULE" ]; then
    export DJANGO_SETTINGS_MODULE=tests.settings
fi

# Run tests based on arguments
if [ $# -eq 0 ]; then
    # Run all tests
    echo -e "${GREEN}Running all tests...${NC}"
    python manage.py test tests --verbosity=2
elif [ $# -eq 1 ]; then
    # Run specific test file
    echo -e "${GREEN}Running tests from: $1${NC}"
    python manage.py test tests.$1 --verbosity=2
elif [ $# -eq 2 ]; then
    # Run specific test class
    echo -e "${GREEN}Running test class: $1.$2${NC}"
    python manage.py test tests.$1.$2 --verbosity=2
elif [ $# -eq 3 ]; then
    # Run specific test method
    echo -e "${GREEN}Running test method: $1.$2.$3${NC}"
    python manage.py test tests.$1.$2.$3 --verbosity=2
fi

echo -e "${GREEN}Tests completed!${NC}"
