AI-powered Locust load test generator from API documentation
Project description
DevDox AI Locust
AI-powered Locust load test generator from API documentation
DevDox AI Locust automatically generates comprehensive Locust load testing scripts from your API documentation (OpenAPI/Swagger specs). Using advanced AI capabilities, it creates realistic test scenarios, handles complex authentication flows, and generates production-ready performance tests.
[0.1.8] - 2025-11-18
๐ What's New in 0.1.8
๐ Smart Authentication Integration:
- Seamless integration with existing
base_workflow.pyauthentication patterns - Automatic detection and reuse of existing authentication methods
- Zero duplication of authentication logic across test files
- Smart 401 response handling with automatic re-authentication
- Configurable authentication retry mechanisms
๐ Comprehensive Test Scenario Framework:
- Weighted scenario distribution for realistic load patterns:
- 60% Positive scenarios (happy path, valid data)
- 25% Negative scenarios (validation errors, missing fields)
- 10% Edge cases (boundary testing, unicode characters)
- 4% State-dependent scenarios (concurrent operations, duplicates)
- 1% Security scenarios (injection attacks, vulnerability detection)
- Enhanced test data generators supporting all scenario types
- Security vulnerability detection with immediate alerting for critical issues
โจ Features
- ๐ค AI-Enhanced Generation: Uses Together AI to create intelligent, realistic load test scenarios
- ๐ OpenAPI/Swagger Support: Automatically parses OpenAPI 3.0 and Swagger 2.0 specifications
- ๐ง Production-Ready Code: Generates clean, maintainable Locust test files
- ๐ฏ Smart Test Scenarios: Creates CRUD workflows, authentication flows, and error handling
- ๐ Realistic Data: Generates appropriate test data using Faker
- ๐ ๏ธ Template-Based: Highly customizable Jinja2 templates for different testing needs
- ๐ Hybrid Approach: Combines rule-based generation with AI enhancement
- ๐ Comprehensive Coverage: Handles various HTTP methods, content types, and response scenarios
- โก Asynchronous Processing: Fast, non-blocking test generation with async/await
๐ Quick Start
Installation
# Install from PyPI (when published)
pip install devdox-ai-locust
# Or install from source
git clone https://github.com/montymobile1/devdox-ai-locust.git
cd devdox-ai-locust
pip install -e .
Prerequisites
- Python 3.12+ - Required for modern async/await syntax and type hints
- Together AI API Key - For AI-enhanced generation capabilities
Configuration
- Get your Together AI API key from Together AI
- Set up your environment:
# Copy example environment file
cp .env.example .env
# Edit .env and add your API key
echo "API_KEY=your_together_ai_api_key_here" > .env
Basic Usage
# Generate from OpenAPI URL
devdox_ai_locust generate --openapi-url https://api.example.com/openapi.json --output ./tests
# Generate with custom configuration
devdox_ai_locust generate \
https://petstore3.swagger.io/api/v3/openapi.json \
--output ./petstore-tests \
--together-api-key your_api_key \
# Generate with db integration
devdox_ai_locust generate \
https://petstore3.swagger.io/api/v3/openapi.json \
--output ./petstore-tests \
--db-type mongo \
๐ Installation with Inputs
Add this step to your GitHub Actions workflow:
- name: DevDox Locust Test Generator
uses: montymobile1/devdox-ai-locust@v0.1.6
with:
swagger_url: "https://portal-api.devdox.ai/openapi.json"
output: "generated_tests"
users: "15"
spawn_rate: "3"
run_time: "10m"
together_api_key: ${{ secrets.TOGETHER_API_KEY }}
## ๐ Documentation
### Command Line Interface
```bash
devdox_ai_locust generate [OPTIONS] SWAGGER_URL
| Option | Short | Type | Description | Default |
|---|---|---|---|---|
--output |
-o |
Path | Output directory for generated tests | output |
--users |
-u |
Integer | Number of simulated users | 10 |
--spawn-rate |
-r |
Float | User spawn rate (users/second) | 2 |
--run-time |
-t |
String | Test duration (e.g., 5m, 1h) | 5m |
--host |
-H |
String | Target host URL | None |
--auth/--no-auth |
Boolean | Include authentication | True |
|
--dry-run |
Flag | Generate without running | False |
|
--custom-requirement |
String | Custom AI instructions | None | |
--together-api-key |
String | Together AI API key | From env |
Generated Test Structure
locust_tests/
โโโ locust.py # Main Locust test file
โโโ config.py # Test configuration
โโโ test_data.py # Test data generators
โโโ utils.py # Utility functions
โโโ requirements.txt # Python dependencies
โโโ .env.example # Environment variables template
โโโ README.md # Test documentation
โโโ workflows/
โ โโโ user_workflow.py # User-related test scenarios
โ โโโ auth_workflow.py # Authentication workflows
โ โโโ crud_workflow.py # CRUD operation workflows
โโโ data/
โโโ users.json # Sample user data
โโโ test_cases.json # Predefined test cases
๐ง Advanced Usage
Custom Templates
Create custom Jinja2 templates for specialized test generation:
# custom_template.py.j2
from locust import HttpUser, task, between
class {{ class_name }}User(HttpUser):
wait_time = between(1, 3)
def on_start(self):
"""Setup method called before tasks"""
self.token = self.login()
{% for endpoint in endpoints %}
@task({{ endpoint.weight | default(1) }})
def {{ endpoint.method_name }}(self):
"""{{ endpoint.description }}"""
# Custom task implementation
{{ endpoint.ai_generated_code | indent(8) }}
{% endfor %}
Programmatic Usage
from devdox_ai_locust import HybridLocustGenerator
from devdox_ai_locust.config import Settings
# Initialize generator
config = Settings()
generator = HybridLocustGenerator(config)
# Generate from OpenAPI spec
async def generate_tests():
files, workflows = await generator.generate_from_url(
"https://api.example.com/openapi.json",
output_dir="./tests",
ai_enhanced=True
)
print(f"Generated {len(files)} test files")
print(f"Created {len(workflows)} workflows")
# Run generation
import asyncio
asyncio.run(generate_tests())
๐งช Development
Setup Development Environment
# Clone repository
git clone https://github.com/montymobile1/devdox-ai-locust.git
cd devdox-ai-locust
# Create virtual environment
python -m venv venv
source venv/bin/activate # On Windows: venv\Scripts\activate
# Install in development mode
pip install -e ".[dev,test,ai]"
# Install pre-commit hooks
pre-commit install
Running Tests
# Use the test runner script
coverage run -m pytest tests/
Project Structure
src/devdox_ai_locust/
โโโ __init__.py
โโโ cli.py # Command line interface
โโโ config.py # Configuration management
โโโ locust_generator.py # Basic test generation
โโโ hybrid_loctus_generator.py # AI-enhanced generation
โโโ templates/ # Jinja2 templates
โ โโโ locust.py.j2
โ โโโ config.py.j2
โ โโโ workflow.py.j2
โโโ schemas/ # Data models and validation
โ โโโ processing_result.py
โ โโโ endpoint_schema.py
โโโ utils/ # Utility modules
โ โโโ swagger_utils.py
โ โโโ open_ai_parser.py
โ โโโ file_creation.py
โโโ prompt/ # AI prompt templates
โโโ system_prompts.py
โโโ enhancement_prompts.py
Development Workflow
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Make your changes
- Add tests for new functionality
- Run the test suite (
make test) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
Code Standards
- Python 3.12+ with type hints
- Black for code formatting
- isort for import sorting
- pytest for testing
- mypy for type checking
- Pre-commit hooks for quality gates
๐ Requirements
System Requirements
- Python: 3.12 or higher
- Memory: 512MB RAM minimum, 1GB recommended
- Storage: 100MB for installation, additional space for generated tests
Dependencies
Core Dependencies
locust- Load testing frameworkclick- CLI frameworkpyyaml- YAML parsingrequests- HTTP clientpydantic- Data validationjinja2- Template enginerich- Rich text outputfaker- Test data generation
AI Dependencies
langchain-together- Together AI integrationtogether- Together AI Python client
Development Dependencies
pytest- Testing frameworkblack- Code formattermypy- Type checkerpre-commit- Git hooks
๐ Examples
Example 1: E-commerce API
# Generate tests for an e-commerce API
devdox_ai_locust generate \
https://api.shop.example.com/v1/openapi.json \
--output ./ecommerce-tests
# The generator will create:
# - Product browsing scenarios
# - Shopping cart workflows
# - Checkout and payment flows
# - User registration and login
# - Order management tests
โ FAQ
Q: What API specification formats are supported? A: We support OpenAPI 3.0+ and Swagger 2.0 specifications in JSON and YAML formats.
Q: Do I need an AI API key? A: Yes, for AI-enhanced generation you need a Together AI API key. Basic generation works without AI.
Q: Can I customize the generated test templates?
A: Absolutely! You can provide custom Jinja2 templates using the --template-dir option.
Q: How do I handle authentication in generated tests? A: The generator automatically detects authentication schemes from your OpenAPI spec and creates appropriate test flows.
Q: Can I run tests against different environments? A: Yes, use environment variables or configuration files to specify different target hosts and settings.
Q: What if my API has complex business logic? A: The AI enhancement feature analyzes your API patterns and generates realistic business workflows, not just individual endpoint tests.
๐ Troubleshooting
Common Issues
Import Errors
# Ensure proper installation
pip install -e .
# Check Python path
python -c "import devdox_ai_locust; print('OK')"
API Key Issues
# Verify API key is set
echo $API_KEY
# Test API connectivity
python -c "from together import Together; print(Together(api_key='your_key').models.list())"
Template Errors
# Validate your OpenAPI spec
# Use online validators like swagger.io/tools/swagger-editor/
# Check template syntax
# Ensure custom templates use valid Jinja2 syntax
๐ License
This project is licensed under the Apache License 2.0 - see the LICENSE file for details.
๐ Acknowledgments
- Locust - The amazing load testing framework that powers our generated tests
- Together AI - Providing the AI capabilities for intelligent test generation
- OpenAPI Initiative - For standardizing API documentation
- Python Community - For the excellent libraries and tools
Made with โค๏ธ by the DevDox team
Transform your API documentation into powerful load tests with the magic of AI! ๐
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file devdox_ai_locust-0.1.8.tar.gz.
File metadata
- Download URL: devdox_ai_locust-0.1.8.tar.gz
- Upload date:
- Size: 98.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a8b051a66f42cdda4fa6d24a0007f82e50b21c19ce796923b39c6008ed6cc81b
|
|
| MD5 |
bda7c9e59574a660b7aea08ecf01547f
|
|
| BLAKE2b-256 |
ca2d47ecd90de8806aa62eca167349ce1af1976f6df36df325af91f77cc96df9
|
File details
Details for the file devdox_ai_locust-0.1.8-py3-none-any.whl.
File metadata
- Download URL: devdox_ai_locust-0.1.8-py3-none-any.whl
- Upload date:
- Size: 81.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9c49dad9df2cc81919cf25b162a9a43d0e0fbb64b5ba496a5f74a0a740fb25dd
|
|
| MD5 |
5d3644d442d9deb38013b3e8edd3ea75
|
|
| BLAKE2b-256 |
27e396bc9949e867564687ca0b7babc58ad0bff87787ed0f0aa95f46dd041246
|