ticker_monitor_api / tests /run_tests.sh
dromerosm's picture
Refactor code structure for improved readability and maintainability
5827878
#!/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."