webhooks-samples
webhooks-samples copied to clipboard
Add comprehensive Python testing infrastructure
Add Python Testing Infrastructure
Summary
This PR establishes a comprehensive testing infrastructure for the webhook samples repository, enabling developers to easily write and run tests for all Python components.
Changes Made
Package Management
- Set up Poetry as the package manager with
pyproject.toml - Migrated dependencies from existing
requirements.txtfiles to Poetry extras:azure: Azure Functions dependenciesslack: Slack bot dependenciesflask: Flask web server dependenciesall: All optional dependencies
Testing Configuration
- pytest configuration with:
- Coverage reporting (80% threshold, HTML/XML reports)
- Custom markers:
unit,integration,slow - Strict configuration for robust testing
- Coverage source paths for
Developer/andsample-workflows/
Testing Infrastructure
-
Directory structure:
tests/ ├── __init__.py ├── conftest.py # Shared fixtures ├── unit/ │ └── __init__.py └── integration/ └── __init__.py -
Comprehensive fixtures in
conftest.py:temp_dir: Temporary directory for test filesmock_config: Mock configuration settingssample_webhook_payload: Sample ArcGIS webhook datamock_azure_function_context/request: Azure Functions mocksmock_flask_app: Flask application mocksmock_requests_session: HTTP requests mocksmock_slack_client: Slack client mocksmock_environment_variables: Test environment setupjson_file: JSON file creation helpermock_hash_validator: Webhook security validation mocks
Development Dependencies
pytest ^7.4.0: Main testing frameworkpytest-cov ^4.1.0: Coverage reportingpytest-mock ^3.11.1: Enhanced mocking utilities
Additional Setup
- Updated .gitignore with testing artifacts, build files, and Claude Code settings
- Validation tests to verify infrastructure functionality
- Poetry.lock included for reproducible builds
Usage Instructions
Installing Dependencies
# Install all dependencies
poetry install
# Install with specific extras
poetry install -E azure
poetry install -E slack
poetry install -E flask
poetry install -E all
Running Tests
# Run all tests
poetry run pytest
# Run with verbose output
poetry run pytest -v
# Run specific test types
poetry run pytest -m unit
poetry run pytest -m integration
poetry run pytest -m slow
# Run with coverage
poetry run pytest --cov
# Run without coverage
poetry run pytest --no-cov
Coverage Reports
- Terminal: Shows missing line coverage
- HTML:
htmlcov/index.html - XML:
coverage.xmlfor CI/CD integration
Validation
The infrastructure includes comprehensive validation tests (tests/test_infrastructure_validation.py) that verify:
- ✅ pytest functionality and markers
- ✅ All shared fixtures work correctly
- ✅ Project structure is properly set up
- ✅ Coverage configuration is functional
- ✅ Environment variable mocking
- ✅ Sample data fixtures
Test Results: All 16 validation tests pass successfully.
Notes
- Optional dependencies are organized as Poetry extras to avoid conflicts between different sample implementations
- Coverage threshold set to 80% but can be adjusted per project needs
- Markers allow selective test execution (unit vs integration vs slow tests)
- Fixtures provide comprehensive mocking for all webhook sample types (Azure, Slack, Flask)
- No actual unit tests were written for existing code - this PR only provides the infrastructure
Next Steps
Developers can now:
- Write unit tests for existing webhook listeners
- Add integration tests for end-to-end scenarios
- Use provided fixtures to mock external dependencies
- Run tests with confidence using the established patterns