🔍 Code Extractor

function test_basic_functionality

Maturity: 43

A test function that validates the basic functionality of an EmailHandler instance without sending actual emails, checking initialization, stats retrieval, and rate limiter operation.

File:
/tf/active/vicechatdev/email-forwarder/test_imports.py
Lines:
77 - 97
Complexity:
simple

Purpose

This function serves as a unit test to verify that the EmailHandler component can be instantiated correctly and that its core methods (get_stats, rate_limiter.can_send) are operational. It's designed for development and CI/CD pipelines to ensure the email forwarding system's basic components are working before attempting actual email operations.

Source Code

def test_basic_functionality():
    """Test basic functionality without sending actual emails."""
    print("\nTesting basic functionality...")
    
    try:
        from forwarder.email_handler import EmailHandler
        handler = EmailHandler()
        print("✓ EmailHandler instance created successfully")
        
        # Check stats
        stats = handler.get_stats()
        print(f"✓ Initial stats: {stats}")
        
        # Test rate limiter
        can_send = handler.rate_limiter.can_send()
        print(f"✓ Rate limiter check: {can_send}")
        
        return True
    except Exception as e:
        print(f"✗ Basic functionality test failed: {e}")
        return False

Return Value

Returns a boolean value: True if all basic functionality tests pass (EmailHandler instantiation, stats retrieval, and rate limiter check succeed), False if any exception occurs during testing. The function also prints status messages to stdout indicating success (✓) or failure (✗) for each test step.

Dependencies

  • forwarder.email_handler
  • config.settings
  • utils.logger

Required Imports

from forwarder.email_handler import EmailHandler

Usage Example

# Run the test function
result = test_basic_functionality()
if result:
    print("All basic functionality tests passed")
else:
    print("Basic functionality tests failed")

# Expected output:
# Testing basic functionality...
# ✓ EmailHandler instance created successfully
# ✓ Initial stats: {'sent': 0, 'failed': 0}
# ✓ Rate limiter check: True

Best Practices

  • This function should be run in a test environment, not in production
  • Ensure all required configuration files and modules are available before running
  • The function prints to stdout, so capture output if running in automated test suites
  • This is a smoke test - it doesn't validate actual email sending functionality
  • Consider wrapping this in a proper test framework (pytest, unittest) for better integration
  • The function catches all exceptions broadly - consider more specific exception handling for production code

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function test_email_handler 82.7% similar

    A test function that initializes an EmailHandler instance and verifies it can retrieve statistics, printing success or failure messages.

    From: /tf/active/vicechatdev/email-forwarder/test_service.py
  • class TestEmailHandler 68.8% similar

    A unit test class that validates the functionality of the EmailHandler class, specifically testing email forwarding success and failure scenarios using mocked O365Client dependencies.

    From: /tf/active/vicechatdev/email-forwarder/tests/test_email_handler.py
  • function send_test_email 66.5% similar

    Sends a test email via SMTP to verify email forwarding service functionality, creating a MIME multipart message with customizable sender, recipient, subject, and body content.

    From: /tf/active/vicechatdev/email-forwarder/send_test_email.py
  • function test_smtp_basic 65.0% similar

    Tests basic SMTP server connectivity by attempting to establish a connection to a local SMTP server on port 2525 and performing an EHLO handshake.

    From: /tf/active/vicechatdev/email-forwarder/service_status.py
  • function send_test_email_v1 63.9% similar

    Sends a test email to a local SMTP server (127.0.0.1:2525) to verify email forwarding functionality and service connectivity.

    From: /tf/active/vicechatdev/email-forwarder/test_e2e.py
← Back to Browse