File size: 1,691 Bytes
a8f56ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f70897f
 
a8f56ca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
5827878
a8f56ca
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#!/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."