customeragent-api / server /tests /run_tests.py
anasraza526's picture
Clean deploy to Hugging Face
ac90985
#!/usr/bin/env python3
"""
Quick test runner for development
"""
import subprocess
import sys
import time
import requests
def start_server():
"""Start the FastAPI server"""
print("πŸš€ Starting FastAPI server...")
try:
process = subprocess.Popen([
sys.executable, "-m", "uvicorn",
"app.main:app", "--reload", "--port", "8000"
], cwd=".")
time.sleep(3) # Wait for server to start
return process
except Exception as e:
print(f"❌ Failed to start server: {e}")
return None
def test_basic_endpoints():
"""Test basic API endpoints"""
base_url = "http://localhost:8000"
tests = [
("GET", "/", "Root endpoint"),
("GET", "/health", "Health check"),
("GET", "/metrics", "Metrics endpoint"),
("GET", "/docs", "API documentation"),
]
print("\nπŸ§ͺ Testing basic endpoints...")
for method, endpoint, description in tests:
try:
if method == "GET":
response = requests.get(f"{base_url}{endpoint}", timeout=5)
if response.status_code == 200:
print(f"βœ… {description}: OK")
else:
print(f"⚠️ {description}: Status {response.status_code}")
except Exception as e:
print(f"❌ {description}: {e}")
def main():
print("πŸ”§ Development Test Runner")
print("=" * 40)
# Start server
server_process = start_server()
if not server_process:
return
try:
# Run basic tests
test_basic_endpoints()
print("\nβœ… Basic tests completed!")
print("🌐 Server running at: http://localhost:8000")
print("πŸ“š API docs at: http://localhost:8000/docs")
print("\nPress Ctrl+C to stop the server...")
# Keep server running
server_process.wait()
except KeyboardInterrupt:
print("\nπŸ›‘ Stopping server...")
server_process.terminate()
server_process.wait()
if __name__ == "__main__":
main()