test_invitation.py
1 import os 2 import sys 3 import json 4 5 # Add project root to path 6 ENVOY_ROOT = os.path.dirname(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) 7 sys.path.append(ENVOY_ROOT) 8 9 from src.invitation.dispatcher import InvitationDispatcher, INVITATION_LOG_PATH 10 11 def test_invitation_flow(): 12 print("--- ENVOY Invitation System Test ---") 13 14 # We'll use a test email address 15 test_email = "test-normie@example.com" 16 test_name = "Alice Normie" 17 18 dispatcher = InvitationDispatcher() 19 20 print(f"Testing dispatcher with: {test_email}") 21 22 try: 23 # Send the invitation (this will use the mock if creds are missing or agentmail is not installed) 24 dispatcher.send_invitation(test_email, test_name) 25 26 # Check if the log was updated 27 if os.path.exists(INVITATION_LOG_PATH): 28 print(f"✓ Log file found at {INVITATION_LOG_PATH}") 29 with open(INVITATION_LOG_PATH, "r") as f: 30 logs = f.readlines() 31 last_log = json.loads(logs[-1]) 32 if last_log["recipient"] == test_email: 33 print("✓ Last log entry matches the test recipient.") 34 else: 35 print("✗ Log entry mismatch.") 36 else: 37 print("✗ Log file not found.") 38 39 except Exception as e: 40 print(f"✗ Test failed with error: {e}") 41 42 if __name__ == "__main__": 43 test_invitation_flow()