Datasourceforcryptocurrency / final /TEST_ENDPOINTS.sh
Really-amin's picture
Upload 325 files
b66240d verified
#!/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 "======================================"