test_deployment.py•3.97 kB
#!/usr/bin/env python3
"""
Test script to verify the Render deployment is working correctly.
"""
import httpx
import asyncio
import sys
import os
from typing import Optional
async def test_health_endpoint(base_url: str) -> bool:
"""Test the health endpoint"""
try:
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.get(f"{base_url}/health")
if response.status_code == 200:
data = response.json()
print(f"✅ Health check passed: {data}")
return True
else:
print(f"❌ Health check failed: {response.status_code} - {response.text}")
return False
except Exception as e:
print(f"❌ Health check error: {str(e)}")
return False
async def test_root_endpoint(base_url: str) -> bool:
"""Test the root endpoint"""
try:
async with httpx.AsyncClient(timeout=30.0) as client:
response = await client.get(f"{base_url}/")
if response.status_code == 200:
data = response.json()
print(f"✅ Root endpoint passed: {data}")
return True
else:
print(f"❌ Root endpoint failed: {response.status_code} - {response.text}")
return False
except Exception as e:
print(f"❌ Root endpoint error: {str(e)}")
return False
async def test_mcp_connection(base_url: str) -> bool:
"""Test MCP connection (basic HTTP test)"""
try:
async with httpx.AsyncClient(timeout=30.0) as client:
# Test basic connectivity to the MCP server
response = await client.post(
f"{base_url}/mcp/v1/initialize",
json={
"protocolVersion": "2024-11-05",
"capabilities": {},
"clientInfo": {
"name": "test-client",
"version": "1.0.0"
}
},
headers={"Content-Type": "application/json"}
)
if response.status_code in [200, 404]: # 404 is also fine, means server is responding
print("✅ MCP server is responding")
return True
else:
print(f"⚠️ MCP server response: {response.status_code}")
return True # Still consider it working if server responds
except Exception as e:
print(f"⚠️ MCP connection test: {str(e)}")
return True # Don't fail the test for MCP specifics
async def main():
"""Main test function"""
if len(sys.argv) != 2:
print("Usage: python test_deployment.py <base_url>")
print("Example: python test_deployment.py https://your-service.onrender.com")
sys.exit(1)
base_url = sys.argv[1].rstrip('/')
print(f"Testing deployment at: {base_url}")
print("-" * 50)
tests = [
("Health Endpoint", test_health_endpoint),
("Root Endpoint", test_root_endpoint),
("MCP Connection", test_mcp_connection),
]
results = []
for test_name, test_func in tests:
print(f"\n🧪 Testing {test_name}...")
result = await test_func(base_url)
results.append((test_name, result))
print("\n" + "=" * 50)
print("TEST RESULTS:")
print("=" * 50)
passed = 0
for test_name, result in results:
status = "✅ PASS" if result else "❌ FAIL"
print(f"{status} - {test_name}")
if result:
passed += 1
print(f"\nTests passed: {passed}/{len(tests)}")
if passed == len(tests):
print("\n🎉 All tests passed! Deployment is working correctly.")
sys.exit(0)
else:
print(f"\n⚠️ {len(tests) - passed} test(s) failed. Check the deployment.")
sys.exit(1)
if __name__ == "__main__":
asyncio.run(main())