function test_configuration_v1
Validates that all required configuration variables (Azure AD credentials, OpenAI API key, and domain) are properly set and not using placeholder values.
/tf/active/vicechatdev/find_email/test_vendor_extractor.py
31 - 75
simple
Purpose
This function performs a comprehensive validation check of configuration settings required for the vendor email extraction system. It verifies that Azure AD authentication credentials (TENANT_ID, CLIENT_ID, CLIENT_SECRET), OpenAI API key, and domain settings are configured with actual values rather than placeholder defaults. The function provides clear visual feedback with checkmarks for valid configurations and error messages for missing or invalid settings, making it useful as a pre-flight check before running the main application.
Source Code
def test_configuration():
"""Test that configuration is properly set"""
print("\n" + "="*60)
print("TESTING CONFIGURATION")
print("="*60)
errors = []
# Check Tenant ID
if not TENANT_ID or TENANT_ID == "your-tenant-id-here":
errors.append("ā TENANT_ID not configured")
else:
print(f"ā TENANT_ID: {TENANT_ID}")
# Check Client ID
if not CLIENT_ID or CLIENT_ID == "your-client-id-here":
errors.append("ā CLIENT_ID not configured")
else:
print(f"ā CLIENT_ID: {CLIENT_ID}")
# Check Client Secret
if not CLIENT_SECRET or CLIENT_SECRET == "your-client-secret-here":
errors.append("ā CLIENT_SECRET not configured")
else:
print(f"ā CLIENT_SECRET: {'*' * 20} (hidden)")
# Check OpenAI API Key
if not OPENAI_API_KEY:
errors.append("ā OPENAI_API_KEY not configured")
else:
print(f"ā OPENAI_API_KEY: {'*' * 20} (hidden)")
# Check Domain
if not DOMAIN:
errors.append("ā DOMAIN not configured")
else:
print(f"ā DOMAIN: {DOMAIN}")
if errors:
print("\n" + "\n".join(errors))
print("\nā ļø Please fix configuration errors and try again")
return False
print("\nā
Configuration looks good!")
return True
Return Value
Returns a boolean value: True if all configuration variables are properly set with non-placeholder values, False if any configuration errors are detected. The function also prints detailed status information to stdout, including which configurations passed validation and which failed.
Required Imports
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 vendor_email_config.py exists with required variables
# Example vendor_email_config.py:
# TENANT_ID = "12345678-1234-1234-1234-123456789abc"
# CLIENT_ID = "87654321-4321-4321-4321-cba987654321"
# CLIENT_SECRET = "your-secret-value"
# OPENAI_API_KEY = "sk-proj-..."
# DOMAIN = "example.com"
from vendor_email_config import TENANT_ID, CLIENT_ID, CLIENT_SECRET, OPENAI_API_KEY, DOMAIN
def test_configuration():
# ... function code ...
pass
# Run the configuration test
if __name__ == "__main__":
config_valid = test_configuration()
if config_valid:
print("Proceeding with application startup...")
else:
print("Cannot start application due to configuration errors")
sys.exit(1)
Best Practices
- Run this function before initializing the main application to catch configuration errors early
- Never log or display the actual values of CLIENT_SECRET or OPENAI_API_KEY in production environments
- Ensure the vendor_email_config.py file is included in .gitignore to prevent credential exposure
- Consider using environment variables instead of a config file for better security in production
- The function checks for common placeholder values ('your-tenant-id-here', etc.) to catch incomplete configuration
- Use the boolean return value to conditionally proceed with application execution or exit gracefully
Tags
Similar Components
AI-powered semantic similarity - components with related functionality:
-
function check_configuration_v1 77.4% similar
-
function test_configuration_v3 72.5% similar
-
function validate_config 70.2% similar
-
function test_config 70.0% similar
-
function test_authentication 69.1% similar