106 lines
3.6 KiB
Python
106 lines
3.6 KiB
Python
#!/usr/bin/env python
|
|
"""
|
|
Test script for async email functionality
|
|
"""
|
|
|
|
import os
|
|
import sys
|
|
import django
|
|
|
|
# Setup Django
|
|
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'NorahUniversity.settings')
|
|
django.setup()
|
|
|
|
from django.contrib.auth.models import User
|
|
from recruitment.email_service import send_bulk_email
|
|
from recruitment.models import JobPosting, Candidate
|
|
|
|
def test_async_email():
|
|
"""Test async email sending functionality"""
|
|
|
|
print("🧪 Testing Async Email Functionality")
|
|
print("=" * 50)
|
|
|
|
try:
|
|
# Get a test user
|
|
test_user = User.objects.first()
|
|
if not test_user:
|
|
print("❌ No users found in database. Please create a user first.")
|
|
return
|
|
|
|
# Get a test job and candidate
|
|
test_job = JobPosting.objects.first()
|
|
test_candidate = Candidate.objects.first()
|
|
|
|
if not test_job or not test_candidate:
|
|
print("❌ No test job or candidate found. Please create some test data first.")
|
|
return
|
|
|
|
print(f"📧 Test User: {test_user.email}")
|
|
print(f"💼 Test Job: {test_job.title}")
|
|
print(f"👤 Test Candidate: {test_candidate.name}")
|
|
|
|
# Test synchronous email sending
|
|
print("\n1. Testing Synchronous Email Sending...")
|
|
try:
|
|
sync_result = send_bulk_email(
|
|
subject="Test Synchronous Email",
|
|
message="This is a test synchronous email from the ATS system.",
|
|
recipient_list=[test_user.email],
|
|
async_task=False
|
|
)
|
|
print(f" ✅ Sync result: {sync_result}")
|
|
except Exception as e:
|
|
print(f" ❌ Sync error: {e}")
|
|
|
|
# Test asynchronous email sending
|
|
print("\n2. Testing Asynchronous Email Sending...")
|
|
try:
|
|
async_result = send_bulk_email(
|
|
subject="Test Asynchronous Email",
|
|
message="This is a test asynchronous email from the ATS system.",
|
|
recipient_list=[test_user.email],
|
|
async_task=True
|
|
)
|
|
print(f" ✅ Async result: {async_result}")
|
|
except Exception as e:
|
|
print(f" ❌ Async error: {e}")
|
|
|
|
print("\n3. Testing Email Service Status...")
|
|
|
|
# Check Django Q configuration
|
|
try:
|
|
import django_q
|
|
from django_q.models import Task
|
|
pending_tasks = Task.objects.count()
|
|
print(f" 📊 Django Q Status: Installed, {pending_tasks} tasks in queue")
|
|
except ImportError:
|
|
print(" ⚠️ Django Q not installed")
|
|
except Exception as e:
|
|
print(f" 📊 Django Q Status: Installed but error checking status: {e}")
|
|
|
|
# Check email backend configuration
|
|
from django.conf import settings
|
|
email_backend = getattr(settings, 'EMAIL_BACKEND', 'not configured')
|
|
print(f" 📧 Email Backend: {email_backend}")
|
|
|
|
email_host = getattr(settings, 'EMAIL_HOST', 'not configured')
|
|
print(f" 🌐 Email Host: {email_host}")
|
|
|
|
email_port = getattr(settings, 'EMAIL_PORT', 'not configured')
|
|
print(f" 🔌 Email Port: {email_port}")
|
|
|
|
print("\n✅ Async email functionality test completed!")
|
|
print("💡 If emails are not being received, check:")
|
|
print(" - Email server configuration in settings.py")
|
|
print(" - Django Q cluster status (python manage.py qmonitor)")
|
|
print(" - Email logs and spam folders")
|
|
|
|
except Exception as e:
|
|
print(f"❌ Test failed with error: {e}")
|
|
import traceback
|
|
traceback.print_exc()
|
|
|
|
if __name__ == "__main__":
|
|
test_async_email()
|