🔍 Code Extractor

function main_v100

Maturity: 38

Tests uploading a PDF document to a specific folder ('Myfolder') on a reMarkable device and verifies the upload by syncing and checking folder contents.

File:
/tf/active/vicechatdev/e-ink-llm/cloudtest/test_folder_upload.py
Lines:
8 - 87
Complexity:
complex

Purpose

This function serves as a comprehensive integration test for the reMarkable upload functionality. It initializes the upload test suite, verifies a target folder exists in the database, creates a test PDF, uploads it to the specified folder, saves HTTP logs, performs a replica sync to verify the upload, and displays the folder contents. It's designed to validate the entire upload-to-folder workflow end-to-end.

Source Code

def main():
    print("📁 TESTING UPLOAD TO MYFOLDER")
    print("=" * 50)
    
    # Initialize the same way as test_uploads.py
    from test_uploads import RemarkableUploadTests
    test_suite = RemarkableUploadTests(enable_raw_logging=True)
    
    # Myfolder UUID from the logs
    myfolder_uuid = "65aabcb0-94de-4e73-bb44-5f1e304c45a5"
    
    print(f"🎯 Target folder: Myfolder (UUID: {myfolder_uuid})")
    
    # Verify the folder exists in our database
    if myfolder_uuid not in test_suite.uploader.database['nodes']:
        print(f"❌ Myfolder UUID not found in database")
        return False
    
    folder_node = test_suite.uploader.database['nodes'][myfolder_uuid]
    print(f"✅ Found folder: {folder_node['name']}")
    print(f"   Type: {folder_node['node_type']}")
    print(f"   Parent: {folder_node.get('metadata', {}).get('parent', 'root')}")
    
    # Create a test PDF using the same method as test_uploads.py
    test_pdf_path = test_suite.test_create_test_pdf()
    
    # Generate unique name for this test
    test_name = f"FolderTest_{int(time.time())}"
    
    print(f"📄 Uploading PDF: {test_name}")
    print(f"   Source file: {test_pdf_path}")
    print(f"   Target folder: Myfolder")
    
    # Upload to the folder using the same method as test_uploads.py
    try:
        success = test_suite.uploader.upload_pdf_document(
            str(test_pdf_path), 
            test_name, 
            parent_uuid=myfolder_uuid
        )
        
        if success:
            print(f"✅ Upload to folder completed successfully!")
            print(f"🔄 The document should now appear in Myfolder on your device")
            
            # Save raw logs like test_uploads.py does
            log_file = test_suite.save_raw_logs()
            if log_file:
                print(f"📝 Raw HTTP logs saved to: {log_file}")
            
            # Run a quick sync to verify
            print(f"🔄 Running replica sync to verify...")
            from local_replica_v2 import RemarkableReplicaBuilder
            replica_builder = RemarkableReplicaBuilder(test_suite.session)
            replica_builder.build_complete_replica()
            
            # Check if it's in the folder
            test_suite.uploader._load_database()
            
            folder_contents = []
            for uuid, node in test_suite.uploader.database['nodes'].items():
                if node.get('metadata', {}).get('parent') == myfolder_uuid:
                    folder_contents.append({
                        'name': node['name'],
                        'uuid': uuid,
                        'type': node['node_type']
                    })
            
            print(f"📁 Myfolder contents after upload:")
            for item in folder_contents:
                print(f"   📄 {item['name']} ({item['type']}) - {item['uuid'][:8]}...")
            
            return True
        else:
            print(f"❌ Upload failed")
            return False
            
    except Exception as e:
        print(f"❌ Upload error: {e}")
        return False

Return Value

Returns a boolean value: True if the upload to the folder completed successfully and verification passed, False if the folder UUID was not found, upload failed, or an exception occurred during the process. The function may also return None implicitly if the folder verification fails early.

Dependencies

  • auth
  • upload_manager
  • pathlib
  • time
  • test_uploads
  • local_replica_v2

Required Imports

from auth import RemarkableAuth
from upload_manager import RemarkableUploadManager
from pathlib import Path
import time

Conditional/Optional Imports

These imports are only needed under specific conditions:

from test_uploads import RemarkableUploadTests

Condition: always required - imported at function start

Required (conditional)
from local_replica_v2 import RemarkableReplicaBuilder

Condition: required for replica sync verification after upload

Required (conditional)

Usage Example

if __name__ == '__main__':
    # Run the folder upload test
    result = main()
    if result:
        print('Test passed: Document successfully uploaded to folder')
    else:
        print('Test failed: Upload or verification unsuccessful')
    
    # The function handles all setup internally:
    # - Initializes test suite with raw logging
    # - Creates test PDF
    # - Uploads to specific folder UUID
    # - Verifies upload through sync
    # - Displays folder contents

Best Practices

  • This function is designed as a standalone test and should not be used in production code
  • The hardcoded folder UUID ('65aabcb0-94de-4e73-bb44-5f1e304c45a5') is specific to a test environment and should be replaced for different use cases
  • The function performs side effects including creating files, uploading to cloud services, and saving logs
  • Ensure proper authentication is configured before running this function
  • The function uses enable_raw_logging=True which may generate large log files
  • Consider wrapping the function call in proper error handling when integrating into larger test suites
  • The function relies on test_uploads.py infrastructure, so that module must be properly configured
  • Network connectivity to reMarkable cloud services is required for successful execution
  • The function performs a full replica sync which may take time depending on the device's content

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function main_v15 87.9% similar

    A test function that uploads a PDF document to reMarkable cloud, syncs the local replica, and validates the upload with detailed logging and metrics.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/test_raw_upload.py
  • function main_v104 86.1% similar

    A test function that uploads a PDF document to a reMarkable tablet folder using the folder's hash value as the parent identifier instead of its UUID, then verifies the upload through replica synchronization.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/test_hash_parent_upload.py
  • function main_v26 85.3% similar

    Command-line test function that uploads a PDF document to a reMarkable device, with optional parent folder specification via command-line argument.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/final_uploads.py
  • function main_v6 84.3% similar

    Integration test function that validates the fixed upload implementation for reMarkable cloud sync by creating a test PDF document, uploading it with corrected metadata patterns, and verifying its successful appearance in the reMarkable ecosystem.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/test_fixed_upload.py
  • function test_quick_upload_v1 80.2% similar

    A test function that performs a quick upload of a PDF document to a reMarkable tablet without performing a full synchronization.

    From: /tf/active/vicechatdev/e-ink-llm/cloudtest/quick_upload_test.py
← Back to Browse