189 lines
5.3 KiB
Python
189 lines
5.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Simple test to verify email refactoring migrations work.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# Add project root to path
|
|
sys.path.insert(0, "/home/ismail/projects/ats/kaauh_ats")
|
|
|
|
|
|
def test_basic_imports():
|
|
"""Test basic imports without Django setup."""
|
|
print("Testing basic imports...")
|
|
|
|
try:
|
|
from recruitment.dto.email_dto import (
|
|
EmailConfig,
|
|
BulkEmailConfig,
|
|
EmailTemplate,
|
|
EmailPriority,
|
|
EmailResult,
|
|
)
|
|
|
|
print("✓ Email DTO imports successful")
|
|
except Exception as e:
|
|
print(f"✗ Email DTO import failed: {e}")
|
|
return False
|
|
|
|
try:
|
|
from recruitment.email_templates import EmailTemplates
|
|
|
|
print("✓ Email templates import successful")
|
|
except Exception as e:
|
|
print(f"✗ Email templates import failed: {e}")
|
|
return False
|
|
|
|
try:
|
|
from recruitment.services.email_service import UnifiedEmailService
|
|
|
|
print("✓ Email service import successful")
|
|
except Exception as e:
|
|
print(f"✗ Email service import failed: {e}")
|
|
return False
|
|
|
|
return True
|
|
|
|
|
|
def test_email_config_creation():
|
|
"""Test EmailConfig creation and validation."""
|
|
print("\nTesting EmailConfig creation...")
|
|
|
|
try:
|
|
from recruitment.dto.email_dto import EmailConfig, EmailPriority
|
|
|
|
# Valid config
|
|
config = EmailConfig(
|
|
to_email="test@example.com",
|
|
subject="Test Subject",
|
|
template_name="emails/test.html",
|
|
context={"name": "Test User"},
|
|
)
|
|
print("✓ Valid EmailConfig created successfully")
|
|
|
|
# Test validation
|
|
try:
|
|
invalid_config = EmailConfig(
|
|
to_email="", subject="", template_name="emails/test.html"
|
|
)
|
|
print("✗ EmailConfig validation failed - should have raised ValueError")
|
|
return False
|
|
except ValueError:
|
|
print("✓ EmailConfig validation working correctly")
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ EmailConfig creation test failed: {e}")
|
|
return False
|
|
|
|
|
|
def test_template_manager():
|
|
"""Test EmailTemplates functionality."""
|
|
print("\nTesting EmailTemplates...")
|
|
|
|
try:
|
|
from recruitment.email_templates import EmailTemplates
|
|
|
|
# Test base context
|
|
base_context = EmailTemplates.get_base_context()
|
|
if isinstance(base_context, dict) and "company_name" in base_context:
|
|
print("✓ Base context generation working")
|
|
else:
|
|
print("✗ Base context generation failed")
|
|
return False
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ EmailTemplates test failed: {e}")
|
|
return False
|
|
|
|
|
|
def test_service_instantiation():
|
|
"""Test UnifiedEmailService instantiation."""
|
|
print("\nTesting UnifiedEmailService instantiation...")
|
|
|
|
try:
|
|
from recruitment.services.email_service import UnifiedEmailService
|
|
|
|
service = UnifiedEmailService()
|
|
print("✓ UnifiedEmailService instantiated successfully")
|
|
|
|
# Test that methods exist
|
|
if hasattr(service, "send_email") and hasattr(service, "send_bulk_emails"):
|
|
print("✓ Core methods are available")
|
|
else:
|
|
print("✗ Core methods missing")
|
|
return False
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ Service instantiation test failed: {e}")
|
|
return False
|
|
|
|
|
|
def test_legacy_function_compatibility():
|
|
"""Test that legacy functions are still accessible."""
|
|
print("\nTesting legacy function compatibility...")
|
|
|
|
try:
|
|
from recruitment.email_service import EmailService as LegacyEmailService
|
|
from recruitment.utils import send_interview_email
|
|
|
|
# Test that functions are accessible
|
|
if callable(LegacyEmailService) and callable(send_interview_email):
|
|
print("✓ Legacy functions are accessible")
|
|
else:
|
|
print("✗ Legacy functions not accessible")
|
|
return False
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ Legacy compatibility test failed: {e}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
"""Run all migration tests."""
|
|
print("=" * 60)
|
|
print("Email Refactoring Migration Tests")
|
|
print("=" * 60)
|
|
|
|
tests = [
|
|
test_basic_imports,
|
|
test_email_config_creation,
|
|
test_template_manager,
|
|
test_service_instantiation,
|
|
test_legacy_function_compatibility,
|
|
]
|
|
|
|
passed = 0
|
|
total = len(tests)
|
|
|
|
for test in tests:
|
|
if test():
|
|
passed += 1
|
|
|
|
print("\n" + "=" * 60)
|
|
print(f"Migration Test Results: {passed}/{total} tests passed")
|
|
|
|
if passed == total:
|
|
print("🎉 All migration tests passed!")
|
|
print("\nPhase 2 Summary:")
|
|
print("✅ Background email tasks created")
|
|
print("✅ Key functions migrated to new service")
|
|
print("✅ Legacy functions still accessible")
|
|
print("✅ Template integration working")
|
|
print("✅ Service instantiation successful")
|
|
print("\nReady for Phase 3: Integration and Testing")
|
|
return True
|
|
else:
|
|
print("❌ Some migration tests failed. Check errors above.")
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1)
|