163 lines
4.3 KiB
Python
163 lines
4.3 KiB
Python
#!/usr/bin/env python3
|
|
"""
|
|
Test script to verify email refactoring foundation setup.
|
|
"""
|
|
|
|
import sys
|
|
import os
|
|
|
|
# Add project root to path
|
|
sys.path.insert(0, "/home/ismail/projects/ats/kaauh_ats")
|
|
|
|
|
|
def test_imports():
|
|
"""Test that all new modules can be imported."""
|
|
print("Testing 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():
|
|
"""Test EmailConfig validation."""
|
|
print("\nTesting EmailConfig...")
|
|
|
|
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")
|
|
|
|
# Invalid config (missing required fields)
|
|
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 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
|
|
|
|
# Test interview context
|
|
class MockCandidate:
|
|
def __init__(self):
|
|
self.full_name = "Test Candidate"
|
|
self.name = "Test Candidate"
|
|
self.email = "test@example.com"
|
|
self.phone = "123-456-7890"
|
|
|
|
class MockJob:
|
|
def __init__(self):
|
|
self.title = "Test Job"
|
|
self.department = "IT"
|
|
|
|
candidate = MockCandidate()
|
|
job = MockJob()
|
|
|
|
interview_context = EmailTemplates.build_interview_context(candidate, job)
|
|
if (
|
|
isinstance(interview_context, dict)
|
|
and "candidate_name" in interview_context
|
|
and "job_title" in interview_context
|
|
):
|
|
print("✓ Interview context generation working")
|
|
else:
|
|
print("✗ Interview context generation failed")
|
|
return False
|
|
|
|
return True
|
|
except Exception as e:
|
|
print(f"✗ EmailTemplates test failed: {e}")
|
|
return False
|
|
|
|
|
|
def main():
|
|
"""Run all tests."""
|
|
print("=" * 50)
|
|
print("Email Refactoring Foundation Tests")
|
|
print("=" * 50)
|
|
|
|
tests = [
|
|
test_imports,
|
|
test_email_config,
|
|
test_template_manager,
|
|
]
|
|
|
|
passed = 0
|
|
total = len(tests)
|
|
|
|
for test in tests:
|
|
if test():
|
|
passed += 1
|
|
|
|
print("\n" + "=" * 50)
|
|
print(f"Results: {passed}/{total} tests passed")
|
|
|
|
if passed == total:
|
|
print("🎉 All foundation tests passed!")
|
|
return True
|
|
else:
|
|
print("❌ Some tests failed. Check the errors above.")
|
|
return False
|
|
|
|
|
|
if __name__ == "__main__":
|
|
success = main()
|
|
sys.exit(0 if success else 1)
|