54 lines
No EOL
1.5 KiB
Python
54 lines
No EOL
1.5 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test if the application runs correctly.
|
|
"""
|
|
import sys
|
|
import subprocess
|
|
import time
|
|
import requests
|
|
|
|
def test_app_start():
|
|
"""Try to start the app and make a request."""
|
|
print("Testing application startup...")
|
|
|
|
# Start the app in a subprocess
|
|
proc = subprocess.Popen(
|
|
[sys.executable, "-m", "uvicorn", "app.core.app:app", "--host", "0.0.0.0", "--port", "8001"],
|
|
stdout=subprocess.PIPE,
|
|
stderr=subprocess.PIPE,
|
|
text=True
|
|
)
|
|
|
|
try:
|
|
# Give it time to start
|
|
time.sleep(3)
|
|
|
|
# Try to make a request
|
|
print("Making test request...")
|
|
try:
|
|
resp = requests.get("http://localhost:8001/health", timeout=5)
|
|
print(f"Response: {resp.status_code} - {resp.json()}")
|
|
if resp.status_code == 200:
|
|
print("✅ Application starts and responds correctly")
|
|
return True
|
|
else:
|
|
print(f"❌ Unexpected status: {resp.status_code}")
|
|
except requests.exceptions.ConnectionError:
|
|
print("❌ Could not connect to server")
|
|
|
|
# Check process output
|
|
stdout, stderr = proc.communicate(timeout=1)
|
|
print(f"STDOUT: {stdout[:200]}")
|
|
print(f"STDERR: {stderr[:200]}")
|
|
|
|
except Exception as e:
|
|
print(f"Error: {e}")
|
|
finally:
|
|
proc.terminate()
|
|
proc.wait()
|
|
|
|
return False
|
|
|
|
if __name__ == "__main__":
|
|
success = test_app_start()
|
|
sys.exit(0 if success else 1) |