Spaces:
Sleeping
Sleeping
# 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." |