Ver Fonte

add email and webhook tests

brid há 1 ano atrás
pai
commit
f008d6416e
2 ficheiros alterados com 74 adições e 0 exclusões
  1. 41 0
      tests/test_smtp.py
  2. 33 0
      tests/test_webhook.py

+ 41 - 0
tests/test_smtp.py

@@ -0,0 +1,41 @@
+import smtplib
+import os
+from dotenv import load_dotenv
+
+load_dotenv()
+
+# Get email settings from environment variables
+username = os.getenv("MAIL_USERNAME")
+password = os.getenv("MAIL_PASSWORD")
+server = os.getenv("MAIL_SERVER")
+port = int(os.getenv("MAIL_PORT", "587"))
+
+print(f"Testing connection to {server}:{port} with username {username}")
+
+try:
+    # Attempt to connect
+    smtp = smtplib.SMTP(server, port)
+    smtp.ehlo()
+    
+    # Start TLS if needed
+    if os.getenv("MAIL_STARTTLS") == "True":
+        smtp.starttls()
+        smtp.ehlo()
+    
+    # Try to login
+    smtp.login(username, password)
+    print("Login successful!")
+    
+    # Send a test email
+    from_addr = os.getenv("MAIL_FROM")
+    to_addr = "example@noreply.com"
+    message = f"From: {from_addr}\nTo: {to_addr}\nSubject: SMTP Test\n\nThis is a test email to verify SMTP connection."
+    
+    smtp.sendmail(from_addr, to_addr, message)
+    print("Test email sent successfully!")
+    
+    smtp.quit()
+    
+except Exception as e:
+    print(f"Error: {e}")
+

+ 33 - 0
tests/test_webhook.py

@@ -0,0 +1,33 @@
+from fastapi import FastAPI, Request
+import uvicorn
+import logging
+
+# Configure logging
+logging.basicConfig(
+    level=logging.INFO,
+    format="%(asctime)s - %(name)s - %(levelname)s - %(message)s",
+    handlers=[
+        logging.FileHandler("webhook_test.log"),
+        logging.StreamHandler()
+    ]
+)
+
+logger = logging.getLogger("webhook-test")
+
+app = FastAPI()
+
+@app.post("/test-webhook")
+async def test_webhook(request: Request):
+    body = await request.body()
+    headers = dict(request.headers)
+    
+    logger.info("Webhook received!")
+    logger.info(f"Headers: {headers}")
+    logger.info(f"Body: {body.decode()}")
+    
+    return {"status": "success"}
+
+if __name__ == "__main__":
+    logger.info("Starting webhook test server on port 8000")
+    uvicorn.run(app, host="0.0.0.0", port=8000)
+