#!/bin/bash # API Testing Script Runner # Make sure the API server is running before executing this script echo "๐Ÿš€ Stock Monitoring API Test Suite" echo "==================================" # Load PORT from .env file - simplified approach if [ -f "../.env" ]; then # Extract PORT specifically from .env PORT_LINE=$(grep "^PORT" ../.env | head -1) if [ -n "$PORT_LINE" ]; then # Extract value after = and clean it up PORT=$(echo "$PORT_LINE" | cut -d'=' -f2- | sed 's/^[[:space:]]*//;s/[[:space:]]*$//;s/^"//;s/"$//') fi echo "โœ… Loaded environment variables from .env" else echo "โš ๏ธ .env file not found, using default values" fi # Use PORT from .env or default to 7860 PORT=${PORT:-7860} echo "๐Ÿ”ง Using PORT: $PORT" # Check if server is running echo "๐Ÿ” Checking if API server is running..." if curl -s http://localhost:$PORT/ > /dev/null; then echo "โœ… API server is running on localhost:$PORT" else echo "โŒ API server is not running!" echo "Please start the server first:" echo " cd .." echo " source .venv/bin/activate" echo " python api/index.py" exit 1 fi # Check if virtual environment is activated if [[ "$VIRTUAL_ENV" != "" ]]; then echo "โœ… Virtual environment is active: $VIRTUAL_ENV" else echo "โš ๏ธ Virtual environment not detected" echo "Consider running: source .venv/bin/activate" fi # Install test dependencies if needed echo "๐Ÿ“ฆ Installing test dependencies..." pip install requests python-dotenv pandas > /dev/null 2>&1 # Run the tests echo "๐Ÿงช Running API tests..." python test_api.py echo "" echo "๐Ÿ“ Test completed! Check the output above for results."