Mockgun
Testing without a real ShotGrid instance
Mockgun
Mockgun is a testing utility that simulates a ShotGrid instance in memory. ShotGrid MCP Server includes an enhanced version of Mockgun that provides additional functionality and better compatibility with the ShotGrid API.
Why Use Mockgun?
Mockgun provides several benefits for development and testing:
- No ShotGrid Instance Required: Develop and test without connecting to a real ShotGrid instance.
- Faster Testing: In-memory operations are much faster than API calls.
- Controlled Environment: Create a consistent, predictable testing environment.
- No Side Effects: Test operations that would modify data without affecting real data.
- Offline Development: Develop and test without an internet connection.
Using Mockgun
Basic Setup
To use Mockgun, set use_mockgun=True
when creating your server:
With Schema Files
For more realistic testing, provide schema files:
Creating Test Data
You can create test data in Mockgun just like you would with the real ShotGrid API:
Using Startup Handlers
A convenient way to create test data is with startup handlers:
Enhanced Mockgun Features
ShotGrid MCP Server’s Mockgun implementation includes several enhancements over the standard Mockgun:
Field Hopping Support
Mockgun supports “field hopping” (dot notation) in filters:
Advanced Filters
Mockgun supports a wide range of filter operators:
Batch Operations
Mockgun supports batch operations for creating, updating, and deleting entities:
Schema Validation
Mockgun validates entity types and fields against the schema:
Testing with Mockgun
Unit Testing
Mockgun is particularly useful for unit testing:
Integration Testing
For integration testing with MCP clients:
Best Practices
-
Use Real Schema: For the most accurate testing, use schema files exported from your production ShotGrid instance.
-
Create Realistic Test Data: Set up test data that closely resembles your production data.
-
Test Edge Cases: Use Mockgun to test error conditions and edge cases that would be difficult to test with a real ShotGrid instance.
-
Reset Between Tests: Create a fresh Mockgun instance for each test to ensure a clean state.
-
Validate Against Real ShotGrid: Periodically validate your tests against a real ShotGrid instance to ensure Mockgun’s behavior matches.
Next Steps
Now that you understand Mockgun, you can:
- Learn about optimized queries that work with both Mockgun and real ShotGrid
- Explore batch operations for efficient data manipulation
- See how to handle errors in a consistent way