#!/usr/bin/env python3
"""
Comprehensive email template testing script.
Tests both welcome (free tier) and upgrade (pro tier) email templates.
"""
import asyncio
import sys
from pathlib import Path
# Add project root to path
sys.path.insert(0, str(Path(__file__).parent))
from dotenv import load_dotenv
load_dotenv()
from congress_api.core.services.email_service import email_service
from congress_api.core.auth.auth import SubscriptionTier
async def test_email_templates(test_email: str, test_type: str = "both"):
"""Test email templates"""
print(f"π§ͺ Testing email templates for: {test_email}")
print(f"π€ From: KeyMaker <keymaker@congressmcp.lawgiver.ai>")
print("-" * 60)
results = []
if test_type in ["both", "welcome", "free"]:
print("\nπ§ Testing FREE tier welcome email...")
try:
success = await email_service.send_welcome_email(
email=test_email,
api_key="lawgiver_free_test12345_WelcomeDemo789",
tier=SubscriptionTier.FREE,
user_name="Test User"
)
if success:
print("β
FREE tier welcome email sent successfully!")
results.append("β
FREE welcome email")
else:
print("β Failed to send FREE tier welcome email")
results.append("β FREE welcome email")
except Exception as e:
print(f"β Error sending FREE tier welcome email: {str(e)}")
results.append("β FREE welcome email (error)")
if test_type in ["both", "upgrade", "pro"]:
print("\nπ Testing PRO tier upgrade email...")
try:
success = await email_service.send_upgrade_email(
email=test_email,
new_api_key="lawgiver_pro_test12345_UpgradeDemo789",
new_tier=SubscriptionTier.PRO,
user_name="Test User"
)
if success:
print("β
PRO tier upgrade email sent successfully!")
results.append("β
PRO upgrade email")
else:
print("β Failed to send PRO tier upgrade email")
results.append("β PRO upgrade email")
except Exception as e:
print(f"β Error sending PRO tier upgrade email: {str(e)}")
results.append("β PRO upgrade email (error)")
print("\n" + "=" * 60)
print("π¬ EMAIL TEMPLATE TEST RESULTS:")
print("=" * 60)
for result in results:
print(f" {result}")
print(f"\nπ§ Check your inbox at: {test_email}")
print("π‘ If you don't see the emails, check your spam folder")
# Check what templates contain
print("\nπ EMAIL TEMPLATE FEATURES TESTED:")
print("-" * 60)
if test_type in ["both", "welcome", "free"]:
print("π FREE TIER WELCOME EMAIL:")
print(" β’ 500 API calls per month")
print(" β’ Basic tools: Bills, Members, Committees")
print(" β’ Congress information and search")
print(" β’ Email support (no community support)")
print(" β’ Setup Guide link (not documentation)")
print(" β’ support@congressmcp.lawgiver.ai contact")
if test_type in ["both", "upgrade", "pro"]:
print("β PRO TIER UPGRADE EMAIL:")
print(" β’ 5,000 API calls per month")
print(" β’ Access to all 23+ tool categories")
print(" β’ All congressional data types")
print(" β’ Standard email support")
print(" β’ support@congressmcp.lawgiver.ai contact")
return len([r for r in results if "β
" in r]) == len(results)
if __name__ == "__main__":
if len(sys.argv) < 2:
print("Usage: python test_email_templates.py <email_address> [type]")
print("Types: welcome, upgrade, both (default)")
print("Example: python test_email_templates.py alex@example.com both")
sys.exit(1)
test_email = sys.argv[1]
test_type = sys.argv[2] if len(sys.argv) > 2 else "both"
if test_type not in ["welcome", "free", "upgrade", "pro", "both"]:
print(f"β Invalid test type: {test_type}")
print("Valid types: welcome, upgrade, both")
sys.exit(1)
# Basic email validation
import re
if not re.match(r'^[^\s@]+@[^\s@]+\.[^\s@]+$', test_email):
print(f"β Invalid email format: {test_email}")
sys.exit(1)
try:
result = asyncio.run(test_email_templates(test_email, test_type))
sys.exit(0 if result else 1)
except KeyboardInterrupt:
print("\nβΉοΈ Test cancelled")
sys.exit(1)