-
Notifications
You must be signed in to change notification settings - Fork 71
feat: SDKE-528 Implement Script To Preprocess Request Recordings #452
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: SDKE-528 Implement Script To Preprocess Request Recordings #452
Conversation
- Add response body files for identify, log event, and config endpoints - Add mapping files for v1 identify, v2 log event, and v4 config
Script extracts JSON request bodies from WireMock mapping files and saves them as separate files for easier test data management.
- Add replace_field_value() function to recursively replace single field values - Add replace_fields_from_list() function to replace multiple fields from a list - Both functions support custom replacement values with default unit.ignore
- Add DEFAULT_REPLACE_FIELDS constant with 16 known dynamic fields
- Add --replace command line parameter to enable field replacement
- When enabled, replaces dynamic fields (IDs, timestamps, device info) with ${json-unit.ignore}
- Update script documentation and help text
- Add detailed steps for recording API requests with test code - Document extract_request_body.py and update_mapping_from_extracted.py scripts - Explain workflow for editing and maintaining test request bodies - Add best practices for recording only relevant API calls - Document benefits of the new workflow (dynamic field replacement, easier maintenance) - Clarify that recorded mappings need to be filtered to keep only relevant ones
nickolas-dimitrakas
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Co-authored-by: Nickolas Dimitrakas <[email protected]>
| - `wiremock-recordings/mappings/*.json` - API request/response mappings | ||
| - `wiremock-recordings/__files/*` - Response body files | ||
|
|
||
| ### `extract_request_body.py` - Extract Request Body from WireMock Mapping |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we add python as well to the Prerequisites?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We don’t need to list Python in the prerequisites because macOS already includes a system Python installation out of the box. Since the script is lightweight and doesn’t rely on any external libraries, it will run fine with the default Python that comes pre-installed on every Mac
Background
This change improves the integration testing workflow by adding automated preprocessing capabilities for WireMock request recordings. Previously, recorded API request bodies contained dynamic fields (timestamps, device IDs, UUIDs) that changed on every test run, requiring manual editing of mapping files. This made test maintenance time-consuming and error-prone.
What Has Changed
extract_request_body.pyscript:replace_field_value()- recursively replaces single field values in JSONreplace_fields_from_list()- replaces multiple fields from a predefined list--replacecommand line parameter to enable automatic replacement of 16 known dynamic fields${json-unit.ignore}placeholderslog_eventandidentifymappingsBenefits
Checklist
Additional Notes
The
--replaceparameter uses a default list of 16 dynamic fields commonly found in mParticle API requests. This list can be extended as needed for future test cases.Reference Issue (For employees only. Ignore if you are an outside contributor)