File size: 3,643 Bytes
2f95553 |
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 |
# Test script to check if server is running and test endpoints
# Usage: .\test_server.ps1
Write-Host "Testing IITM LLM Quiz Solver API" -ForegroundColor Cyan
Write-Host "=================================" -ForegroundColor Cyan
Write-Host ""
# Test 1: Health check
Write-Host "1. Testing /health endpoint..." -ForegroundColor Yellow
try {
$health = Invoke-RestMethod -Uri "http://127.0.0.1:8000/health" -Method GET -ErrorAction Stop
Write-Host " ✓ Server is running!" -ForegroundColor Green
Write-Host " Response: $($health | ConvertTo-Json)" -ForegroundColor Gray
} catch {
Write-Host " ✗ Server is NOT running or not accessible" -ForegroundColor Red
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Red
Write-Host ""
Write-Host " Please start the server first:" -ForegroundColor Yellow
Write-Host " python -m app.main" -ForegroundColor Cyan
exit 1
}
Write-Host ""
# Test 2: Root endpoint
Write-Host "2. Testing / endpoint..." -ForegroundColor Yellow
try {
$root = Invoke-RestMethod -Uri "http://127.0.0.1:8000/" -Method GET -ErrorAction Stop
Write-Host " ✓ Root endpoint works!" -ForegroundColor Green
Write-Host " Available endpoints:" -ForegroundColor Gray
$root.endpoints.PSObject.Properties | ForEach-Object {
Write-Host " $($_.Name): $($_.Value)" -ForegroundColor Gray
}
} catch {
Write-Host " ✗ Root endpoint failed: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
# Test 3: Env check
Write-Host "3. Testing /env-check endpoint..." -ForegroundColor Yellow
try {
$envCheck = Invoke-RestMethod -Uri "http://127.0.0.1:8000/env-check" -Method GET -ErrorAction Stop
Write-Host " ✓ Environment check works!" -ForegroundColor Green
Write-Host " QUIZ_SECRET: $($envCheck.variables.QUIZ_SECRET.set)" -ForegroundColor Gray
Write-Host " OPENAI_API_KEY: $($envCheck.variables.OPENAI_API_KEY.set)" -ForegroundColor Gray
Write-Host " Ready: $($envCheck.ready)" -ForegroundColor Gray
} catch {
Write-Host " ✗ Env check failed: $($_.Exception.Message)" -ForegroundColor Red
}
Write-Host ""
# Test 4: Demo endpoint (if server is running)
Write-Host "4. Testing /demo endpoint..." -ForegroundColor Yellow
Write-Host " (This will make an actual request)" -ForegroundColor Gray
# Set variables if not set
if (-not $env:QUIZ_SECRET) {
$env:QUIZ_SECRET = "EasyQuiz"
}
$body = @{
email = "24f2005753@ds.study.iitm.ac.in"
secret = "EasyQuiz"
url = "https://tds-llm-analysis.s-anand.net/demo"
} | ConvertTo-Json
try {
Write-Host " Sending request..." -ForegroundColor Gray
$response = Invoke-RestMethod `
-Uri "http://127.0.0.1:8000/demo" `
-Method POST `
-ContentType "application/json" `
-Body $body `
-ErrorAction Stop
Write-Host " ✓ Demo endpoint works!" -ForegroundColor Green
Write-Host " Response:" -ForegroundColor Gray
$response | ConvertTo-Json -Depth 10 | Write-Host
} catch {
Write-Host " ✗ Demo endpoint failed" -ForegroundColor Red
Write-Host " Status: $($_.Exception.Response.StatusCode.value__)" -ForegroundColor Yellow
if ($_.ErrorDetails.Message) {
Write-Host " Error: $($_.ErrorDetails.Message)" -ForegroundColor Yellow
} else {
Write-Host " Error: $($_.Exception.Message)" -ForegroundColor Yellow
}
}
Write-Host ""
Write-Host "=================================" -ForegroundColor Cyan
Write-Host "Test complete!" -ForegroundColor Cyan
|