šŸ” Code Extractor

function run_all_tests

Maturity: 46

Orchestrates a comprehensive test suite for the Vendor Email Extractor system, verifying configuration, authentication, mailbox access, email search, and LLM connectivity.

File:
/tf/active/vicechatdev/find_email/test_vendor_extractor.py
Lines:
206 - 258
Complexity:
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

  • sys
  • pathlib
  • vendor_email_extractor
  • vendor_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

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function main_v42 73.5% similar

    Orchestrates and executes a test suite for an email forwarder service, running multiple test functions sequentially and reporting results.

    From: /tf/active/vicechatdev/email-forwarder/test_service.py
  • function main_v22 72.7% similar

    Orchestrates and executes a comprehensive test suite for a Contract Validity Analyzer system, running tests for configuration, FileCloud connection, document processing, LLM client, and full analyzer functionality.

    From: /tf/active/vicechatdev/contract_validity_analyzer/test_implementation.py
  • function test_llm_connectivity 70.2% similar

    Tests the connectivity and functionality of an OpenAI LLM integration by analyzing a mock email with vendor information extraction.

    From: /tf/active/vicechatdev/find_email/test_vendor_extractor.py
  • function main_v27 69.9% similar

    Demonstrates example usage of the VendorEmailExtractor class by searching for vendor emails across Office 365 mailboxes and displaying results.

    From: /tf/active/vicechatdev/find_email/vendor_email_extractor.py
  • function main_v40 69.1% similar

    Test orchestration function that executes a comprehensive test suite for DocChat's multi-LLM model selection feature and reports results.

    From: /tf/active/vicechatdev/docchat/test_model_selection.py
← Back to Browse