function main_v4
A test function that validates email template rendering by testing multiple HTML email templates with sample data structures for document review and approval workflows.
/tf/active/vicechatdev/test_comprehensive_templates.py
45 - 113
moderate
Purpose
This function serves as a comprehensive test suite for email template placeholder resolution in a Controlled Document Management System (CDocs). It validates that review and approval email templates correctly render with their respective data structures, ensuring that all placeholders are properly replaced with actual values. The function tests four different email templates: review_requested, approval_requested, document_updated, and approval_completed, using appropriate test data for each scenario.
Source Code
def main():
"""Test both review and approval templates with their respective data structures."""
print("Testing Email Template Placeholder Resolution...")
# Test data for review notifications (like the working example)
review_data = {
'doc_number': 'EXPENSE_NOTE_003',
'title': 'double clone testing custom doc number',
'doc_type': 'FORM',
'version_number': '0.2',
'due_date': '2025-07-07T23:59:59.999999',
'document_url': 'https://cdocs.vicebio.com/document/test-uid-123',
'app_name': 'Controlled Document Management System',
'app_url': 'https://cdocs.vicebio.com',
'current_year': 2025,
'sender_name': 'CDocs System',
'cdocs_app_url': 'https://cdocs.vicebio.com',
'message': 'You have been requested to review this document.',
'instructions': 'testing if templates work'
}
# Test data for approval notifications (should now work with the fix)
approval_data = {
'doc_number': 'DOC-001',
'title': 'Test Document for Approval',
'doc_type': 'SOP',
'version_number': '1.0',
'due_date': 'June 30, 2025',
'status': 'PENDING_APPROVAL',
'document_url': 'https://cdocs.vicebio.com/document/test-uid-123',
'approval_url': 'https://cdocs.vicebio.com/approval/approval-uid-456',
'app_name': 'Controlled Document Management System',
'app_url': 'https://cdocs.vicebio.com',
'current_year': 2025,
'sender_name': 'CDocs System',
'cdocs_app_url': 'https://cdocs.vicebio.com',
'message': 'You have been requested to approve this document.',
'instructions': 'with updated templates'
}
templates_to_test = [
('/tf/active/CDocs/templates/email/review_requested.html', review_data, 'Review Requested'),
('/tf/active/CDocs/templates/email/approval_requested.html', approval_data, 'Approval Requested'),
('/tf/active/CDocs/templates/email/document_updated.html', approval_data, 'Document Updated'),
('/tf/active/CDocs/templates/email/approval_completed.html', approval_data, 'Approval Completed'),
]
all_passed = True
for template_path, test_data, template_name in templates_to_test:
if os.path.exists(template_path):
success = test_template_with_data(template_path, test_data, template_name)
if not success:
all_passed = False
else:
print(f"❌ {template_name}: Template file not found: {template_path}")
all_passed = False
print("\n" + "="*60)
if all_passed:
print("✅ ALL TESTS PASSED - Templates should render correctly!")
print("\nKey findings:")
print("- Review templates work because they get document data via 'details'")
print("- Approval templates now work because we fixed the controller")
print("- Both follow the same data structure with doc_number, title, etc.")
else:
print("❌ SOME TESTS FAILED - Check the issues above")
return all_passed
Return Value
Returns a boolean value (all_passed) indicating whether all template tests passed successfully. Returns True if all templates exist and render without issues, False if any template is missing or fails validation.
Dependencies
osre
Required Imports
import os
import re
Usage Example
# Assuming test_template_with_data function is defined
import os
import re
def test_template_with_data(template_path, data, name):
# Implementation of template testing logic
with open(template_path, 'r') as f:
template_content = f.read()
# Validate placeholders are resolved
return True
# Run the main test function
if __name__ == '__main__':
result = main()
if result:
print('All email templates validated successfully')
else:
print('Some templates failed validation')
Best Practices
- Ensure all template files exist at the specified paths before running this function
- The function depends on an external 'test_template_with_data' function which must be implemented separately
- Template paths are hardcoded and specific to the /tf/active/CDocs directory structure
- Test data structures should match the actual data structures used in production for accurate validation
- The function prints detailed output to console for debugging and validation purposes
- Both review_data and approval_data dictionaries contain overlapping fields (doc_number, title, etc.) but serve different workflow purposes
- The function validates that templates work with different data structures (review vs approval workflows)
- Consider making template paths configurable via parameters or environment variables for better reusability
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function test_fixes 80.5% similar
-
function check_fixes 66.4% similar
-
function test_template_with_data 63.1% similar
-
function test_web_ui 53.1% similar
-
function test_complex_url_hyperlink 51.1% similar