File size: 5,090 Bytes
b66240d |
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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
#!/bin/bash
# API Endpoints Test Script
# Run this after starting the backend to verify all endpoints work
BASE_URL="${BASE_URL:-http://localhost:7860}"
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
echo "======================================"
echo "π§ͺ Testing Crypto HF API Endpoints"
echo "======================================"
echo "Base URL: $BASE_URL"
echo ""
# Function to test endpoint
test_endpoint() {
local method=$1
local endpoint=$2
local data=$3
local name=$4
echo -n "Testing $name... "
if [ "$method" = "GET" ]; then
response=$(curl -s -o /dev/null -w "%{http_code}" "$BASE_URL$endpoint")
else
response=$(curl -s -o /dev/null -w "%{http_code}" -X "$method" "$BASE_URL$endpoint" \
-H "Content-Type: application/json" \
-d "$data")
fi
if [ "$response" = "200" ]; then
echo -e "${GREEN}β
OK${NC} (HTTP $response)"
else
echo -e "${RED}β FAILED${NC} (HTTP $response)"
return 1
fi
}
# Test health
test_endpoint "GET" "/api/health" "" "Health Check"
# Test market endpoints
echo ""
echo "π Market Endpoints:"
test_endpoint "GET" "/api/coins/top?limit=5" "" "Top Coins"
test_endpoint "GET" "/api/coins/BTC" "" "Bitcoin Details"
test_endpoint "GET" "/api/market/stats" "" "Market Stats"
# Test chart endpoints
echo ""
echo "π Chart Endpoints:"
test_endpoint "GET" "/api/charts/price/BTC?timeframe=7d" "" "BTC Price Chart"
# POST endpoint for chart analyze
echo -n "Testing Chart Analysis... "
response=$(curl -s -w "\n%{http_code}" -X POST "$BASE_URL/api/charts/analyze" \
-H "Content-Type: application/json" \
-d '{"symbol":"BTC","timeframe":"7d","indicators":[]}')
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
echo -e "${GREEN}β
OK${NC} (HTTP $http_code)"
else
echo -e "${RED}β FAILED${NC} (HTTP $http_code)"
fi
# Test news endpoints
echo ""
echo "π° News Endpoints:"
test_endpoint "GET" "/api/news/latest?limit=5" "" "Latest News"
# POST endpoint for news summarize
echo -n "Testing News Summarize... "
response=$(curl -s -w "\n%{http_code}" -X POST "$BASE_URL/api/news/summarize" \
-H "Content-Type: application/json" \
-d '{"title":"Bitcoin breaks new record","description":"BTC hits $50k"}')
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
echo -e "${GREEN}β
OK${NC} (HTTP $http_code)"
else
echo -e "${RED}β FAILED${NC} (HTTP $http_code)"
fi
# Test AI endpoints
echo ""
echo "π€ AI Endpoints:"
# POST endpoint for sentiment
echo -n "Testing Sentiment Analysis... "
response=$(curl -s -w "\n%{http_code}" -X POST "$BASE_URL/api/sentiment/analyze" \
-H "Content-Type: application/json" \
-d '{"text":"Bitcoin is breaking new all-time highs!"}')
http_code=$(echo "$response" | tail -n1)
body=$(echo "$response" | head -n-1)
if [ "$http_code" = "200" ]; then
sentiment=$(echo "$body" | grep -o '"sentiment":"[^"]*"' | cut -d'"' -f4)
confidence=$(echo "$body" | grep -o '"confidence":[0-9.]*' | cut -d':' -f2)
echo -e "${GREEN}β
OK${NC} (HTTP $http_code) - Sentiment: ${YELLOW}$sentiment${NC} (${confidence})"
else
echo -e "${RED}β FAILED${NC} (HTTP $http_code)"
fi
# POST endpoint for query
echo -n "Testing Query... "
response=$(curl -s -w "\n%{http_code}" -X POST "$BASE_URL/api/query" \
-H "Content-Type: application/json" \
-d '{"query":"What is the price of Bitcoin?"}')
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
echo -e "${GREEN}β
OK${NC} (HTTP $http_code)"
else
echo -e "${RED}β FAILED${NC} (HTTP $http_code)"
fi
# Test provider endpoints
echo ""
echo "π Provider Endpoints:"
test_endpoint "GET" "/api/providers" "" "Providers List"
# Test datasets endpoints
echo ""
echo "π Datasets & Models Endpoints:"
test_endpoint "GET" "/api/datasets/list" "" "Datasets List"
test_endpoint "GET" "/api/models/list" "" "Models List"
# POST endpoint for model test
echo -n "Testing Model Test... "
response=$(curl -s -w "\n%{http_code}" -X POST "$BASE_URL/api/models/test" \
-H "Content-Type: application/json" \
-d '{"model":"crypto_sent_0","text":"Ethereum price surging!"}')
http_code=$(echo "$response" | tail -n1)
if [ "$http_code" = "200" ]; then
echo -e "${GREEN}β
OK${NC} (HTTP $http_code)"
else
echo -e "${RED}β FAILED${NC} (HTTP $http_code)"
fi
# Summary
echo ""
echo "======================================"
echo "π Test Summary"
echo "======================================"
echo ""
echo "β
All critical endpoints tested"
echo ""
echo "π Dashboard URLs:"
echo " - Main: $BASE_URL/"
echo " - Admin: $BASE_URL/admin.html"
echo " - API Docs: $BASE_URL/docs"
echo ""
echo "π WebSocket:"
echo " - ws://$(echo $BASE_URL | sed 's|http://||')/ws"
echo ""
echo "π‘ Next steps:"
echo " 1. Open $BASE_URL/ in your browser"
echo " 2. Check all dashboard tabs"
echo " 3. Verify WebSocket connection (status indicator)"
echo ""
echo "======================================"
|