Prj2 / test_server.ps1
iitmbs24f's picture
Upload 37 files
2f95553 verified
# 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