CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-indico

Comprehensive web-based event management and conference lifecycle management platform.

Pending
Overview
Eval results
Files

testing-utilities.mddocs/

Testing Utilities

Indico provides comprehensive testing infrastructure including pytest integration, extensive fixture systems, and utilities for creating parameterized tests. The testing framework supports both core development and plugin testing with realistic data and proper application context.

Capabilities

Pytest Integration

Indico includes a pytest plugin that automatically configures the testing environment and provides access to all testing fixtures.

# Pytest plugin is automatically registered via entry point
# No explicit import needed - fixtures are available when using pytest

Configuration in pyproject.toml:

[project.entry-points."pytest11"]
indico = "indico.testing.pytest_plugin"

Test Utilities

Core testing utility functions for creating parameterized tests and handling test data.

def bool_matrix(template, mask, expect):
    """
    Create boolean matrix for parameterized tests.
    
    Generates test parameter combinations based on a template with boolean
    placeholders, applying a mask to filter combinations, and mapping results
    to expected outcomes.
    
    Parameters:
    - template: str or callable, test parameter template
    - mask: dict, mask to apply to boolean combinations  
    - expect: dict, expected results for each combination
    
    Returns:
    list: List of pytest parameter tuples for @pytest.mark.parametrize
    """

Usage example:

import pytest
from indico.testing.util import bool_matrix

# Create parameterized test cases
test_cases = bool_matrix(
    template="user={user_exists}, admin={is_admin}",
    mask={'user_exists': True, 'is_admin': [True, False]},
    expect={
        (True, True): 'admin_access',
        (True, False): 'user_access'
    }
)

@pytest.mark.parametrize("params,expected", test_cases)
def test_access_control(params, expected):
    # Test implementation
    pass

Core Fixtures

Essential fixtures for application testing and database operations.

Application Context Fixtures

# Available automatically when using Indico's pytest plugin

def app():
    """Flask application instance with test configuration."""

def request_context():
    """Flask request context for testing."""

def db():
    """Database session for testing."""

User and Authentication Fixtures

def dummy_user():
    """Create a test user instance."""

def create_user():
    """Factory function for creating test users."""

def dummy_admin():
    """Create a test admin user."""

Event and Content Fixtures

def dummy_event():
    """Create a test event instance."""

def create_event():
    """Factory function for creating test events."""

def dummy_category():
    """Create a test category."""

def create_category():
    """Factory function for creating test categories."""

Contribution and Session Fixtures

def dummy_contribution():
    """Create a test contribution."""

def create_contribution():
    """Factory function for creating test contributions."""

def dummy_session():
    """Create a test session."""

def create_session():
    """Factory function for creating test sessions."""

Room Booking Fixtures

def dummy_room():
    """Create a test room."""

def create_room():
    """Factory function for creating test rooms."""

def dummy_reservation():
    """Create a test room reservation."""

def create_reservation():
    """Factory function for creating reservations."""

Abstract and Submission Fixtures

def dummy_abstract(): 
    """Create a test abstract submission."""

def create_abstract():
    """Factory function for creating test abstracts."""

Cache Fixtures

Fixtures for testing caching functionality and cache-dependent features.

def redis_proc():
    """Redis process fixture for cache testing."""

def redis():
    """Redis client fixture."""

Testing Best Practices

Using Fixtures in Tests

def test_user_creation(create_user, db):
    """Test user creation with fixtures."""
    user = create_user(email='test@example.com', first_name='Test')
    db.session.add(user)
    db.session.commit()
    
    assert user.email == 'test@example.com'
    assert user.first_name == 'Test'

def test_event_management(dummy_event, dummy_user):
    """Test event management functionality."""
    event = dummy_event
    user = dummy_user
    
    # Test event operations
    assert event.title
    assert event.creator == user

Parameterized Testing

@pytest.mark.parametrize("user_type,access_level", [
    ('admin', 'full'),
    ('manager', 'limited'), 
    ('user', 'read_only')
])
def test_access_levels(user_type, access_level, create_user):
    """Test different user access levels."""
    user = create_user(user_type=user_type)
    # Test access level logic
    pass

Plugin Testing

def test_plugin_functionality(app, dummy_event):
    """Test plugin functionality."""
    from my_plugin import MyPlugin
    
    plugin = MyPlugin(app.extensions['indico_plugins'])
    plugin.init()
    
    # Test plugin behavior
    result = plugin.process_event(dummy_event)
    assert result is not None

Email Testing Utilities

Utilities for testing email functionality in events and notifications.

# Email testing utilities are available in indico.testing.util
# Specific functions for email validation and testing

Data Processing Helpers

YAML and JSON processing helpers for test data management.

# YAML and JSON processing utilities available in indico.testing.util
# Functions for loading and processing test data files

Test Configuration

The pytest plugin automatically configures:

  • Test database setup and teardown
  • Application context management
  • Fixture registration and dependency injection
  • Test-specific configuration overrides
  • Cleanup after test execution

Running Tests

# Run all tests
pytest

# Run specific test file
pytest tests/core/test_plugins.py

# Run tests with coverage
pytest --cov=indico

# Run tests for specific plugin
pytest tests/plugins/test_my_plugin.py

Install with Tessl CLI

npx tessl i tessl/pypi-indico

docs

cli-commands.md

index.md

plugin-development.md

testing-utilities.md

tile.json