51 lines
1.8 KiB
Python
51 lines
1.8 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify local connection works
|
|
"""
|
|
|
|
import requests
|
|
import time
|
|
import json
|
|
|
|
def test_local_connection():
|
|
"""Test the local server connection"""
|
|
|
|
print("🧪 Testing local Email Alerts server...")
|
|
|
|
# Wait for server to start
|
|
print("⏳ Waiting for server to start...")
|
|
time.sleep(3)
|
|
|
|
try:
|
|
# Test 1: Check if server is running
|
|
print("\n1️⃣ Testing server availability...")
|
|
response = requests.get("http://localhost:5237/", timeout=5)
|
|
if response.status_code == 200:
|
|
print("✅ Server is running and accessible")
|
|
else:
|
|
print(f"❌ Server returned status code: {response.status_code}")
|
|
return
|
|
|
|
# Test 2: Test connection endpoint
|
|
print("\n2️⃣ Testing connection endpoint...")
|
|
response = requests.get("http://localhost:5237/test_connection", timeout=10)
|
|
|
|
if response.status_code == 200:
|
|
data = response.json()
|
|
if data.get('status') == 'success':
|
|
print("✅ Connection test successful!")
|
|
print(f"📧 Found {data.get('email_count', 0)} emails")
|
|
print(f"💬 Message: {data.get('message', '')}")
|
|
else:
|
|
print("❌ Connection test failed:")
|
|
print(f" Error: {data.get('message', 'Unknown error')}")
|
|
else:
|
|
print(f"❌ Connection endpoint returned status code: {response.status_code}")
|
|
|
|
except requests.exceptions.ConnectionError:
|
|
print("❌ Could not connect to server. Make sure it's running on port 5237")
|
|
except Exception as e:
|
|
print(f"❌ Test failed: {str(e)}")
|
|
|
|
if __name__ == "__main__":
|
|
test_local_connection() |