ktosiek / pytest-vcr

Py.test integration with VCR.py
MIT License
150 stars 25 forks source link

vcr_config fixture doesn't filter DELETE request #30

Open gegnew opened 4 years ago

gegnew commented 4 years ago

It's possible that I've done something wrong, but I've overridden the vcr config in conftest.py as below:

@pytest.fixture(scope='module')
def vcr_config():
    """Pytest hook for vcr config"""
    return {
        'filter_headers': ['Cookie'],
        'before_record_response': scrub_header('set-cookie',
                                               repl='safetoken'),
        'cassette_library_dir': 'tests/cassettes'
                        }

Where scrub_header replaces headers as such:

def scrub_header(string, repl=''):
    """Remove secrets from stored vcr cassettes"""
    def before_record_response(response):
        response['headers'][string] = repl
        return response
    return before_record_response

This works great for every other request method (works for GET, POST, PATCH, PUT), but those headers are not removed before the delete request .yaml is saved.

Note that headers are removed by two methods: 1) 'filter_headers' is passed to vcr to remove "Cookie" 2) the 'set-cookie' header is replaced with 'safetoken' in before_record_response Interestingly, neither of these methods works for the delete request.

Thoughts?