mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Use mock for patching http connection objects.
This commit is contained in:
@@ -6,21 +6,19 @@ from vcr import VCR
|
||||
def test_vcr_use_cassette():
|
||||
filter_headers = mock.Mock()
|
||||
test_vcr = VCR(filter_headers=filter_headers)
|
||||
with mock.patch('vcr.cassette.Cassette.__init__', return_value=None) as mock_cassette_init, \
|
||||
mock.patch('vcr.cassette.Cassette._load'), \
|
||||
mock.patch('vcr.cassette.Cassette.__exit__'):
|
||||
with mock.patch('vcr.cassette.Cassette.load') as mock_cassette_load:
|
||||
@test_vcr.use_cassette('test')
|
||||
def function():
|
||||
pass
|
||||
assert mock_cassette_init.call_count == 0
|
||||
assert mock_cassette_load.call_count == 0
|
||||
function()
|
||||
assert mock_cassette_init.call_args[1]['filter_headers'] is filter_headers
|
||||
assert mock_cassette_load.call_args[1]['filter_headers'] is filter_headers
|
||||
|
||||
# Make sure that calls to function now use cassettes with the
|
||||
# new filter_header_settings
|
||||
test_vcr.filter_headers = ('a',)
|
||||
function()
|
||||
assert mock_cassette_init.call_args[1]['filter_headers'] == test_vcr.filter_headers
|
||||
assert mock_cassette_load.call_args[1]['filter_headers'] == test_vcr.filter_headers
|
||||
|
||||
# Ensure that explicitly provided arguments still supercede
|
||||
# those on the vcr.
|
||||
|
||||
Reference in New Issue
Block a user