๐Ÿ” Code Extractor

function test_web_ui

Maturity: 48

Integration test function that validates a Flask web UI for meeting minutes generation by testing file upload, generation, and regeneration endpoints with sample transcript and PowerPoint files.

File:
/tf/active/vicechatdev/leexi/test_ui.py
Lines:
13 - 110
Complexity:
moderate

Purpose

This function performs end-to-end testing of a web-based meeting minutes generation service. It verifies server health, uploads test files (transcript and PowerPoint), generates meeting minutes using specified AI models and instructions, and tests the regeneration feature with modified instructions. The function provides detailed console feedback about each step's success or failure, making it useful for development, CI/CD pipelines, and manual testing scenarios.

Source Code

def test_web_ui():
    """Test the web UI with sample files"""
    
    base_url = "http://localhost:5000"
    
    # Check if server is running
    try:
        response = requests.get(f"{base_url}/health")
        if response.status_code == 200:
            print("โœ… Server is running")
        else:
            print("โŒ Server health check failed")
            return
    except requests.exceptions.ConnectionError:
        print("โŒ Cannot connect to server. Make sure Flask app is running.")
        return
    
    # Prepare test data
    test_files = {
        'transcript': 'leexi-20250618-transcript-development_team_meeting.md',
        'powerpoint': '2025 06 18 Development Team meeting.pptx'
    }
    
    # Check if test files exist
    missing_files = []
    for file_type, filename in test_files.items():
        if not Path(filename).exists():
            missing_files.append(filename)
    
    if missing_files:
        print(f"โŒ Missing test files: {missing_files}")
        print("Please ensure these files are in the current directory")
        return
    
    print("๐Ÿงช Testing web UI with sample data...")
    
    # Prepare form data
    data = {
        'meeting_title': 'Demo Meeting - Web UI Test',
        'model': 'gpt-4o',
        'user_instructions': 'Focus on action items and technical decisions. Use pharmaceutical industry terminology.'
    }
    
    # Prepare files
    files = {}
    if Path(test_files['transcript']).exists():
        files['transcript'] = open(test_files['transcript'], 'rb')
    
    if Path(test_files['powerpoint']).exists():
        files['powerpoint'] = open(test_files['powerpoint'], 'rb')
    
    try:
        print("๐Ÿ“ค Sending request to generate meeting minutes...")
        response = requests.post(f"{base_url}/generate", data=data, files=files)
        
        if response.status_code == 200:
            result = response.json()
            if result.get('success'):
                print("โœ… Meeting minutes generated successfully!")
                print(f"๐Ÿ“„ Report saved to: {result.get('report_path')}")
                print(f"๐Ÿ†” Session ID: {result.get('session_id')}")
                
                # Test regeneration
                print("\n๐Ÿ”„ Testing regeneration with modified instructions...")
                regen_data = {
                    'session_id': result.get('session_id'),
                    'new_instructions': 'Emphasize regulatory compliance and timeline impacts.',
                    'new_model': 'gpt-4o'
                }
                
                regen_response = requests.post(f"{base_url}/regenerate", data=regen_data)
                if regen_response.status_code == 200:
                    regen_result = regen_response.json()
                    if regen_result.get('success'):
                        print("โœ… Regeneration successful!")
                        print(f"๐Ÿ“„ New report saved to: {regen_result.get('report_path')}")
                    else:
                        print(f"โŒ Regeneration failed: {regen_result.get('error')}")
                else:
                    print(f"โŒ Regeneration request failed: {regen_response.status_code}")
                
            else:
                print(f"โŒ Generation failed: {result.get('error')}")
        else:
            print(f"โŒ Request failed: {response.status_code}")
            print(response.text)
    
    except Exception as e:
        print(f"โŒ Error during testing: {str(e)}")
    
    finally:
        # Close file handles
        for file_handle in files.values():
            if hasattr(file_handle, 'close'):
                file_handle.close()
    
    print("\n๐ŸŽฏ Test completed!")
    print(f"๐ŸŒ Web UI available at: {base_url}")

Return Value

This function does not return any value (implicitly returns None). It outputs test results directly to the console using print statements, indicating success (โœ…) or failure (โŒ) of various test steps including server connectivity, file availability, generation, and regeneration operations.

Dependencies

  • requests
  • pathlib

Required Imports

import requests
from pathlib import Path

Usage Example

# Ensure Flask server is running first
# Place required test files in current directory:
# - leexi-20250618-transcript-development_team_meeting.md
# - 2025 06 18 Development Team meeting.pptx

import requests
from pathlib import Path

# Run the test
test_web_ui()

# Expected output:
# โœ… Server is running
# ๐Ÿงช Testing web UI with sample data...
# ๐Ÿ“ค Sending request to generate meeting minutes...
# โœ… Meeting minutes generated successfully!
# ๐Ÿ“„ Report saved to: [path]
# ๐Ÿ†” Session ID: [id]
# ๐Ÿ”„ Testing regeneration with modified instructions...
# โœ… Regeneration successful!
# ๐Ÿ“„ New report saved to: [path]
# ๐ŸŽฏ Test completed!
# ๐ŸŒ Web UI available at: http://localhost:5000

Best Practices

  • Ensure the Flask server is running before executing this test function
  • Place the required test files in the current working directory before running
  • The function properly closes file handles in a finally block to prevent resource leaks
  • Server health check is performed first to fail fast if the service is unavailable
  • File existence is validated before attempting uploads to provide clear error messages
  • The function tests both initial generation and regeneration workflows for comprehensive coverage
  • Consider parameterizing the base_url, test files, and model selection for more flexible testing
  • In production testing, consider adding timeout parameters to requests to prevent hanging
  • The function uses emoji indicators for easy visual parsing of test results in console output

Similar Components

AI-powered semantic similarity - components with related functionality:

  • function generate_minutes 70.6% similar

    Flask route handler that processes uploaded meeting transcripts and optional supporting documents to generate structured meeting minutes using AI, with configurable output styles and validation.

    From: /tf/active/vicechatdev/leexi/app.py
  • function test_multiple_file_upload 67.2% similar

    A test function that validates multiple file upload functionality to a Flask application endpoint by sending a transcript file and multiple previous report files.

    From: /tf/active/vicechatdev/leexi/test_flask_upload.py
  • function regenerate_minutes 62.2% similar

    Flask route handler that regenerates meeting minutes from a previous session using modified instructions, model selection, and configuration parameters.

    From: /tf/active/vicechatdev/leexi/app.py
  • function test_upload_modalities 60.1% similar

    Integration test function that validates FileCloud upload functionality by testing both new file creation and existing file update scenarios.

    From: /tf/active/vicechatdev/SPFCsync/test_upload_modalities.py
  • function test_frontend_files 60.0% similar

    A test function that validates the presence of model selection functionality in frontend files (HTML, JavaScript, and CSS) for a document chat application.

    From: /tf/active/vicechatdev/docchat/test_model_selection.py
โ† Back to Browse