https://github.com/techservicesillinois/vcrpy-cleaner
Sensitive data cleaners for network cassettes captured by the VCR.py testing library.
https://github.com/techservicesillinois/vcrpy-cleaner
Last synced: 2 months ago
JSON representation
Sensitive data cleaners for network cassettes captured by the VCR.py testing library.
- Host: GitHub
- URL: https://github.com/techservicesillinois/vcrpy-cleaner
- Owner: techservicesillinois
- Created: 2023-01-12T20:17:21.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2025-11-13T19:39:13.000Z (7 months ago)
- Last Synced: 2025-11-13T21:07:49.909Z (7 months ago)
- Language: Python
- Size: 39.1 KB
- Stars: 0
- Watchers: 8
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
README
# VCR Cleaner
See `def test_if_uri_contains_two_different_scrubs` in `test_filters.py` for usage.
```python
import vcr
from vcr_cleaner import CleanYAMLSerializer
from vcr_cleaner.cleaners.jwt_token import clean_token
from vcr_cleaner.filters import if_uri_contains
yaml_cleaner = CleanYAMLSerializer()
# Register an included function
yaml_cleaner.register_cleaner(if_uri_contains('/api/auth', clean_token))
# Define cleaner functions
def clean_bad_word(request: dict, response: dict):
response['body']['string'] = response['body']['string'].replace('shid', '')
def clean_long_response(request: dict, response: dict):
response['body'] = "{'when all your test needs':'is this bit'}"
# Register custom cleaner functions
yaml_cleaner.register_cleaner(if_uri_contains('/api/foulmouth', clean_bad_word))
yaml_cleaner.register_cleaner(if_uri_contains('/api/returns_so_so_many_records',
clean_long_response))
my_vcr = vcr.VCR(
cassette_library_dir='cassettes',
record_mode='once',
filter_headers=[('Authorization', 'Bearer FAKE_TOKEN')],
match_on=['uri', 'method'],
)
my_vcr.register_serializer("yaml_cleaner", yaml_cleaner)
```