function run_all_tests
Orchestrates a comprehensive test suite for the Vendor Email Extractor system, verifying configuration, authentication, mailbox access, email search, and LLM connectivity.
/tf/active/vicechatdev/find_email/test_vendor_extractor.py
206 - 258
moderate
Purpose
This function serves as a setup verification tool that runs a series of sequential tests to ensure all components of the Vendor Email Extractor system are properly configured and operational. It validates configuration settings, Microsoft Graph API authentication, mailbox access permissions, email search functionality, and OpenAI LLM connectivity. The function provides detailed console output with visual indicators (ā /ā) and exits early if critical tests fail, ensuring users can identify and fix issues before attempting to extract vendor emails.
Source Code
def run_all_tests():
"""Run all tests"""
print("\n" + "="*60)
print("VENDOR EMAIL EXTRACTOR - SETUP VERIFICATION")
print("="*60)
# Test 1: Configuration
if not test_configuration():
print("\nā ļø Fix configuration issues before continuing")
sys.exit(1)
# Create extractor
extractor = VendorEmailExtractor(
tenant_id=TENANT_ID,
client_id=CLIENT_ID,
client_secret=CLIENT_SECRET,
openai_api_key=OPENAI_API_KEY,
domain=DOMAIN
)
# Test 2: Authentication
if not test_authentication(extractor):
print("\nā ļø Fix authentication issues before continuing")
sys.exit(1)
# Test 3: Mailbox Access
mailbox_ok = test_mailbox_access(extractor)
# Test 4: Email Search
search_ok = test_email_search(extractor)
# Test 5: LLM Connectivity
llm_ok = test_llm_connectivity(extractor)
# Summary
print("\n" + "="*60)
print("TEST SUMMARY")
print("="*60)
print(f"Configuration: ā
")
print(f"Authentication: ā
")
print(f"Mailbox Access: {'ā
' if mailbox_ok else 'ā'}")
print(f"Email Search: {'ā
' if search_ok else 'ā'}")
print(f"LLM Analysis: {'ā
' if llm_ok else 'ā'}")
if mailbox_ok and search_ok and llm_ok:
print("\nš All tests passed! You're ready to extract vendor emails.")
print("\nNext steps:")
print("1. python vendor_email_extractor.py # Run with default test")
print("2. python extract_vendor_batch.py # Process your vendor list")
else:
print("\nā ļø Some tests failed. Please fix the issues above.")
print("="*60 + "\n")
Return Value
This function does not return a value. It exits the program with sys.exit(1) if critical tests (configuration or authentication) fail, or completes execution after displaying a comprehensive test summary with pass/fail status for all components.
Dependencies
syspathlibvendor_email_extractorvendor_email_config
Required Imports
import sys
from pathlib import Path
from vendor_email_extractor import VendorEmailExtractor
from vendor_email_config import TENANT_ID
from vendor_email_config import CLIENT_ID
from vendor_email_config import CLIENT_SECRET
from vendor_email_config import OPENAI_API_KEY
from vendor_email_config import DOMAIN
Usage Example
# Ensure all configuration is set in vendor_email_config.py
# Ensure all test helper functions are defined in the same module
# Run the complete test suite
run_all_tests()
# Expected output:
# ============================================================
# VENDOR EMAIL EXTRACTOR - SETUP VERIFICATION
# ============================================================
# [Test results displayed with ā
/ā indicators]
# ============================================================
# TEST SUMMARY
# ============================================================
# Configuration: ā
# Authentication: ā
# Mailbox Access: ā
# Email Search: ā
# LLM Analysis: ā
#
# š All tests passed! You're ready to extract vendor emails.
# ============================================================
Best Practices
- Run this function before attempting to use the vendor email extraction system in production
- Ensure all configuration values in vendor_email_config.py are properly set before running
- The function exits with sys.exit(1) on critical failures, so it should be run as a standalone script rather than imported into other modules
- All five test helper functions (test_configuration, test_authentication, test_mailbox_access, test_email_search, test_llm_connectivity) must be defined in the same module
- Review console output carefully to identify which specific component is failing if tests do not pass
- Critical tests (configuration and authentication) cause immediate exit if they fail, as subsequent tests depend on them
- Non-critical tests (mailbox, search, LLM) continue even if they fail to provide a complete diagnostic picture
- Follow the 'Next steps' instructions displayed after successful test completion
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function main_v42 73.5% similar
-
function main_v22 72.7% similar
-
function test_llm_connectivity 70.2% similar
-
function main_v27 69.9% similar
-
function main_v40 69.1% similar