fix(config): harden bootstrap logic and add email E2E test
Harden bootstrap_db_config to prioritize .env settings for core infrastructure (DB/SMTP) and only use DB values if placeholders are detected or values have explicitly changed. Added test_e2e_email_send.py for functional SMTP verification.
This commit is contained in:
48
tests/e2e/test_e2e_email_send.py
Normal file
48
tests/e2e/test_e2e_email_send.py
Normal file
@@ -0,0 +1,48 @@
|
||||
import requests
|
||||
import json
|
||||
import time
|
||||
|
||||
# --- Configuration ---
|
||||
API_BASE = "https://dev-api.oneskyit.com/util/email"
|
||||
API_KEY = "PMM4n50teUCaOMMTN8qOJA" # Agent API Key
|
||||
ACCOUNT_ID = "_XY7DXtc9MY" # Standard Test Account
|
||||
|
||||
def test_email_send_live():
|
||||
"""
|
||||
End-to-End test for the email send utility.
|
||||
Verifies that the API can successfully authenticate with SMTP and dispatch an email.
|
||||
"""
|
||||
print("\n--- Testing Live Email Send via API ---")
|
||||
print(f"Target: {API_BASE}/send")
|
||||
|
||||
payload = {
|
||||
"from_email": "noreply@oneskyit.com",
|
||||
"from_name": "Aether API Monitor",
|
||||
"to_email": "scott.idem+devtest@oneskyit.com",
|
||||
"to_name": "Scott Idem (Dev Test)",
|
||||
"subject": f"Aether E2E Test: {time.strftime('%Y-%m-%d %H:%M:%S')}",
|
||||
"body_html": "<h3>Aether API Status Check</h3><p>This email confirms that the SMTP subsystem is operational and prioritizing correctly.</p><p>Environment: <b>Development</b></p>",
|
||||
"body_text": "Aether API Status Check: SMTP subsystem is operational."
|
||||
}
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"X-Aether-API-Key": API_KEY,
|
||||
"x-account-id": ACCOUNT_ID
|
||||
}
|
||||
|
||||
start_time = time.time()
|
||||
resp = requests.post(f"{API_BASE}/send", headers=headers, json=payload)
|
||||
duration = time.time() - start_time
|
||||
|
||||
print(f"Status Code: {resp.status_code}")
|
||||
print(f"Response: {resp.text}")
|
||||
print(f"Duration: {duration:.2f}s")
|
||||
|
||||
if resp.status_code == 200:
|
||||
print("[✅ PASS] Email successfully dispatched.")
|
||||
else:
|
||||
print("[❌ FAIL] Email failed to send. Check FastAPI logs for SMTP errors.")
|
||||
|
||||
if __name__ == "__main__":
|
||||
test_email_send_live()
|
||||
@@ -1,29 +0,0 @@
|
||||
import sys
|
||||
import os
|
||||
import logging
|
||||
|
||||
# Add current directory to path
|
||||
sys.path.append(os.getcwd())
|
||||
|
||||
# Configure logging
|
||||
logging.basicConfig(level=logging.DEBUG)
|
||||
|
||||
try:
|
||||
from app.lib_email import send_email
|
||||
print("Successfully imported send_email.")
|
||||
|
||||
print("Running send_email in TEST mode...")
|
||||
result = send_email(
|
||||
from_email="test@example.com",
|
||||
to_email="test@example.com",
|
||||
subject="Test Email",
|
||||
body_html="<p>Test</p>",
|
||||
test=True
|
||||
)
|
||||
|
||||
print(f"Result: {result}")
|
||||
|
||||
except Exception as e:
|
||||
print(f"Error during email test: {e}")
|
||||
import traceback
|
||||
traceback.print_exc()
|
||||
Reference in New Issue
Block a user