🔍 Code Extractor

function test_configuration_v3

Maturity: 42

A test function that validates the presence and loading of required Microsoft 365 and SMTP configuration settings from a settings module.

File:
/tf/active/vicechatdev/email-forwarder/test_imports.py
Lines:
52 - 75
Complexity:
simple

Purpose

This function serves as a configuration validation utility, typically used during application startup or testing phases. It checks that all critical Microsoft 365 OAuth credentials (client ID, secret, tenant ID, sender email) and SMTP server settings (host, port) are properly loaded and accessible. The function provides visual feedback by printing check marks for successfully loaded settings and X marks for missing ones, making it useful for debugging configuration issues.

Source Code

def test_configuration():
    """Test configuration loading."""
    print("\nTesting configuration...")
    
    import config.settings as settings
    
    required_settings = [
        'MS365_CLIENT_ID',
        'MS365_CLIENT_SECRET', 
        'MS365_TENANT_ID',
        'MS365_SENDER_EMAIL',
        'SMTP_LISTEN_HOST',
        'SMTP_LISTEN_PORT'
    ]
    
    for setting in required_settings:
        value = getattr(settings, setting, None)
        if value:
            print(f"✓ {setting}: {value[:10]}..." if len(str(value)) > 10 else f"✓ {setting}: {value}")
        else:
            print(f"✗ {setting}: Not set")
            return False
    
    return True

Return Value

Returns a boolean value: True if all required configuration settings are present and loaded successfully, False if any required setting is missing or not set. The function performs early return (False) as soon as it encounters a missing setting.

Dependencies

  • config.settings

Required Imports

import config.settings as settings

Usage Example

# Ensure config/settings.py exists with required settings
# Example config/settings.py:
# MS365_CLIENT_ID = 'your-client-id'
# MS365_CLIENT_SECRET = 'your-client-secret'
# MS365_TENANT_ID = 'your-tenant-id'
# MS365_SENDER_EMAIL = 'sender@example.com'
# SMTP_LISTEN_HOST = '0.0.0.0'
# SMTP_LISTEN_PORT = 25

# Run the configuration test
if test_configuration():
    print("Configuration is valid, proceeding with application startup")
else:
    print("Configuration validation failed, please check settings")
    sys.exit(1)

Best Practices

  • Run this function during application initialization to fail fast if configuration is incomplete
  • Ensure the config.settings module is properly structured and accessible in the Python path
  • The function truncates displayed values to 10 characters for security (prevents full credential exposure in logs)
  • Consider using this in CI/CD pipelines to validate configuration before deployment
  • The function prints to stdout, so capture or redirect output appropriately in production environments
  • This is a synchronous function suitable for startup validation but not for runtime configuration checks

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function validate_config 76.8% similar

    Validates the presence of required Microsoft 365 configuration settings and raises an error if any are missing.

    From: /tf/active/vicechatdev/email-forwarder/src/config/settings.py
  • function test_configuration_v1 72.5% similar

    Validates that all required configuration variables (Azure AD credentials, OpenAI API key, and domain) are properly set and not using placeholder values.

    From: /tf/active/vicechatdev/find_email/test_vendor_extractor.py
  • function test_configuration_v2 72.4% similar

    A test function that validates configuration settings by calling settings.validate_config() and prints the result with success/failure indicators.

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

    A test function that validates configuration settings by importing and calling the Config.validate_config() method, printing the result and returning a boolean status.

    From: /tf/active/vicechatdev/SPFCsync/test_connections.py
  • function test_config_loading 67.9% similar

    A test function that validates configuration loading by instantiating a Config object and verifying access to key configuration parameters across FileCloud, LLM, and output settings.

    From: /tf/active/vicechatdev/contract_validity_analyzer/test_implementation.py
← Back to Browse