function main_v29
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 notification templates correctly render with their respective data structures, ensuring all placeholders are properly resolved. 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
# Ensure 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 test_template_with_data() which must be implemented separately to perform actual template validation
- Template paths are hardcoded to /tf/active/CDocs/templates/email/ - modify these if your directory structure differs
- Test data structures should match the actual data structures used in production for accurate validation
- The function prints detailed output to console - capture stdout if you need to log results
- Both review_data and approval_data dictionaries contain overlapping fields (doc_number, title, etc.) which should be consistent across all templates
- Consider parameterizing template paths and URLs for better reusability across different environments
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function test_fixes 82.0% similar
-
function check_fixes 68.3% similar
-
function test_basic_functionality 61.6% similar
-
function test_template_with_data 60.3% similar
-
function get_email_templates 58.8% similar