SIH-Crop-Yield-API / tests /test_server.py
AshrafGalibSk's picture
Upload folder using huggingface_hub
bbd5f9c verified
Raw
History Blame Contribute Delete
937 Bytes
#!/usr/bin/env python3
import subprocess
import time
import requests
import os
# Start the server in the background
print("Starting server...")
server_process = subprocess.Popen(
["python3", "app.py"],
env={**os.environ, "PORT": "8004"},
stdout=subprocess.PIPE,
stderr=subprocess.PIPE
)
# Wait for server to start
time.sleep(5)
try:
# Test health endpoint
response = requests.get("http://localhost:8004/health", timeout=10)
print(f"Health check status: {response.status_code}")
print(f"Health response: {response.json()}")
# Test root endpoint
response = requests.get("http://localhost:8004/", timeout=10)
print(f"Root status: {response.status_code}")
print(f"Root response: {response.json()}")
except Exception as e:
print(f"Error testing server: {e}")
finally:
# Stop the server
server_process.terminate()
server_process.wait()
print("Server stopped")