#!/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()