šŸ” Code Extractor

function main_v8

Maturity: 46

Main test function that validates SharePoint Graph API integration, tests the Graph client connection, and verifies FileCloud sync functionality.

File:
/tf/active/vicechatdev/SPFCsync/test_graph_client.py
Lines:
99 - 145
Complexity:
moderate

Purpose

This function serves as the primary entry point for testing the SharePoint to FileCloud synchronization application. It validates configuration, tests the Graph API client connection to SharePoint, verifies document retrieval, and tests the full sync integration with FileCloud. It provides detailed console output with status indicators and next steps for deployment.

Source Code

def main():
    """Main test function."""
    print("SharePoint Graph API Integration Test")
    print("=" * 60)
    print(f"Test time: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
    print()
    
    try:
        # Load configuration
        from config import Config
        Config.validate_config()
        Config.setup_logging()
        
        print("āœ… Configuration loaded successfully")
        print(f"SharePoint Site: {Config.SHAREPOINT_SITE_URL}")
        print(f"FileCloud Server: {Config.FILECLOUD_SERVER_URL}")
        print()
        
        # Test Graph client
        graph_success, doc_count = test_graph_client()
        
        if graph_success:
            print(f"\nšŸŽ‰ Graph API client test PASSED! Found {doc_count} documents.")
            
            # Test full sync integration
            sync_success = test_filecloud_integration()
            
            if sync_success:
                print("\nšŸŽ‰ Full sync integration test PASSED!")
                print("\nāœ… The sync application is ready to use with Graph API!")
                print("\nNext steps:")
                print("1. Run a test sync: python main.py --once")
                print("2. Monitor the logs for any issues")
                print("3. Set up continuous sync: python main.py")
                return 0
            else:
                print("\nāŒ Sync integration test failed.")
                return 1
        else:
            print("\nāŒ Graph API client test failed.")
            return 1
            
    except Exception as e:
        print(f"āŒ Test failed with exception: {e}")
        import traceback
        traceback.print_exc()
        return 1

Return Value

Returns an integer exit code: 0 for successful completion of all tests (Graph API client test and sync integration test both passed), 1 for any failure (configuration error, Graph API test failure, sync integration failure, or exception). This follows standard Unix exit code conventions.

Dependencies

  • datetime
  • os
  • sys
  • traceback
  • sharepoint_graph_client
  • config
  • sync_service

Required Imports

from datetime import datetime

Conditional/Optional Imports

These imports are only needed under specific conditions:

from config import Config

Condition: imported inside try block during configuration loading phase

Required (conditional)
import traceback

Condition: imported inside except block for error handling and stack trace printing

Required (conditional)

Usage Example

if __name__ == '__main__':
    exit_code = main()
    sys.exit(exit_code)

Best Practices

  • This function should be called as the main entry point for testing the sync application before production use
  • Ensure all configuration files and credentials are properly set up before running
  • The function provides clear console output with emoji indicators for easy status identification
  • Returns proper exit codes (0 for success, 1 for failure) suitable for CI/CD pipelines
  • Includes comprehensive error handling with stack trace printing for debugging
  • Follow the 'Next steps' instructions printed on successful completion
  • This is a test function and should not be used for production synchronization - use the actual sync commands instead
  • The function depends on test_graph_client() and test_filecloud_integration() helper functions being defined in the same module

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function main_v13 85.5% similar

    Main test function that validates SharePoint folder structure connectivity and configuration, comparing actual folders against expected structure.

    From: /tf/active/vicechatdev/SPFCsync/test_folder_structure.py
  • function main_v21 84.0% similar

    Orchestrates and executes a comprehensive test suite for SharePoint to FileCloud synchronization service, running configuration, connection, and operation tests.

    From: /tf/active/vicechatdev/SPFCsync/test_connections.py
  • function test_filecloud_integration 83.1% similar

    Integration test function that verifies the SharePoint Graph API client works correctly with FileCloud synchronization service by creating a sync service instance and testing document retrieval.

    From: /tf/active/vicechatdev/SPFCsync/test_graph_client.py
  • function main_v25 81.7% similar

    Entry point function that tests SharePoint REST API connectivity by loading configuration, validating settings, and executing connection tests.

    From: /tf/active/vicechatdev/SPFCsync/test_rest_client.py
  • function test_graph_client 80.9% similar

    A test function that validates the SharePoint Graph API client by testing authentication, document listing, and file download capabilities.

    From: /tf/active/vicechatdev/SPFCsync/test_graph_client.py
← Back to Browse