mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-10 09:35:34 +00:00
style changes in test_vcr.py
This commit is contained in:
@@ -15,9 +15,11 @@ def test_vcr_use_cassette():
|
|||||||
'vcr.cassette.Cassette.load',
|
'vcr.cassette.Cassette.load',
|
||||||
return_value=mock.MagicMock(inject=False)
|
return_value=mock.MagicMock(inject=False)
|
||||||
) as mock_cassette_load:
|
) as mock_cassette_load:
|
||||||
|
|
||||||
@test_vcr.use_cassette('test')
|
@test_vcr.use_cassette('test')
|
||||||
def function():
|
def function():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
assert mock_cassette_load.call_count == 0
|
assert mock_cassette_load.call_count == 0
|
||||||
function()
|
function()
|
||||||
assert mock_cassette_load.call_args[1]['record_mode'] is record_mode
|
assert mock_cassette_load.call_args[1]['record_mode'] is record_mode
|
||||||
@@ -38,9 +40,11 @@ def test_vcr_use_cassette():
|
|||||||
|
|
||||||
def test_vcr_before_record_request_params():
|
def test_vcr_before_record_request_params():
|
||||||
base_path = 'http://httpbin.org/'
|
base_path = 'http://httpbin.org/'
|
||||||
|
|
||||||
def before_record_cb(request):
|
def before_record_cb(request):
|
||||||
if request.path != '/get':
|
if request.path != '/get':
|
||||||
return request
|
return request
|
||||||
|
|
||||||
test_vcr = VCR(filter_headers=('cookie',), before_record_request=before_record_cb,
|
test_vcr = VCR(filter_headers=('cookie',), before_record_request=before_record_cb,
|
||||||
ignore_hosts=('www.test.com',), ignore_localhost=True,
|
ignore_hosts=('www.test.com',), ignore_localhost=True,
|
||||||
filter_query_parameters=('foo',))
|
filter_query_parameters=('foo',))
|
||||||
@@ -53,8 +57,12 @@ def test_vcr_before_record_request_params():
|
|||||||
assert cassette.filter_request(
|
assert cassette.filter_request(
|
||||||
Request('GET', base_path + '?foo=bar', '',
|
Request('GET', base_path + '?foo=bar', '',
|
||||||
{'cookie': 'test', 'other': 'fun'})).headers == {'other': 'fun'}
|
{'cookie': 'test', 'other': 'fun'})).headers == {'other': 'fun'}
|
||||||
assert cassette.filter_request(Request('GET', base_path + '?foo=bar', '',
|
assert cassette.filter_request(
|
||||||
{'cookie': 'test', 'other': 'fun'})).headers == {'other': 'fun'}
|
Request(
|
||||||
|
'GET', base_path + '?foo=bar', '',
|
||||||
|
{'cookie': 'test', 'other': 'fun'}
|
||||||
|
)
|
||||||
|
).headers == {'other': 'fun'}
|
||||||
|
|
||||||
assert cassette.filter_request(Request('GET', 'http://www.test.com' + '?foo=bar', '',
|
assert cassette.filter_request(Request('GET', 'http://www.test.com' + '?foo=bar', '',
|
||||||
{'cookie': 'test', 'other': 'fun'})) is None
|
{'cookie': 'test', 'other': 'fun'})) is None
|
||||||
@@ -103,6 +111,7 @@ def test_custom_patchers():
|
|||||||
|
|
||||||
def test_inject_cassette():
|
def test_inject_cassette():
|
||||||
vcr = VCR(inject_cassette=True)
|
vcr = VCR(inject_cassette=True)
|
||||||
|
|
||||||
@vcr.use_cassette('test', record_mode='once')
|
@vcr.use_cassette('test', record_mode='once')
|
||||||
def with_cassette_injected(cassette):
|
def with_cassette_injected(cassette):
|
||||||
assert cassette.record_mode == 'once'
|
assert cassette.record_mode == 'once'
|
||||||
@@ -117,9 +126,11 @@ def test_inject_cassette():
|
|||||||
|
|
||||||
def test_with_current_defaults():
|
def test_with_current_defaults():
|
||||||
vcr = VCR(inject_cassette=True, record_mode='once')
|
vcr = VCR(inject_cassette=True, record_mode='once')
|
||||||
|
|
||||||
@vcr.use_cassette('test', with_current_defaults=False)
|
@vcr.use_cassette('test', with_current_defaults=False)
|
||||||
def changing_defaults(cassette, checks):
|
def changing_defaults(cassette, checks):
|
||||||
checks(cassette)
|
checks(cassette)
|
||||||
|
|
||||||
@vcr.use_cassette('test', with_current_defaults=True)
|
@vcr.use_cassette('test', with_current_defaults=True)
|
||||||
def current_defaults(cassette, checks):
|
def current_defaults(cassette, checks):
|
||||||
checks(cassette)
|
checks(cassette)
|
||||||
@@ -141,27 +152,33 @@ def test_with_current_defaults():
|
|||||||
def test_cassette_library_dir_with_decoration_and_no_explicit_path():
|
def test_cassette_library_dir_with_decoration_and_no_explicit_path():
|
||||||
library_dir = '/libary_dir'
|
library_dir = '/libary_dir'
|
||||||
vcr = VCR(inject_cassette=True, cassette_library_dir=library_dir)
|
vcr = VCR(inject_cassette=True, cassette_library_dir=library_dir)
|
||||||
|
|
||||||
@vcr.use_cassette()
|
@vcr.use_cassette()
|
||||||
def function_name(cassette):
|
def function_name(cassette):
|
||||||
assert cassette._path == os.path.join(library_dir, 'function_name')
|
assert cassette._path == os.path.join(library_dir, 'function_name')
|
||||||
|
|
||||||
function_name()
|
function_name()
|
||||||
|
|
||||||
|
|
||||||
def test_cassette_library_dir_with_decoration_and_explicit_path():
|
def test_cassette_library_dir_with_decoration_and_explicit_path():
|
||||||
library_dir = '/libary_dir'
|
library_dir = '/libary_dir'
|
||||||
vcr = VCR(inject_cassette=True, cassette_library_dir=library_dir)
|
vcr = VCR(inject_cassette=True, cassette_library_dir=library_dir)
|
||||||
|
|
||||||
@vcr.use_cassette(path='custom_name')
|
@vcr.use_cassette(path='custom_name')
|
||||||
def function_name(cassette):
|
def function_name(cassette):
|
||||||
assert cassette._path == os.path.join(library_dir, 'custom_name')
|
assert cassette._path == os.path.join(library_dir, 'custom_name')
|
||||||
|
|
||||||
function_name()
|
function_name()
|
||||||
|
|
||||||
|
|
||||||
def test_cassette_library_dir_with_decoration_and_super_explicit_path():
|
def test_cassette_library_dir_with_decoration_and_super_explicit_path():
|
||||||
library_dir = '/libary_dir'
|
library_dir = '/libary_dir'
|
||||||
vcr = VCR(inject_cassette=True, cassette_library_dir=library_dir)
|
vcr = VCR(inject_cassette=True, cassette_library_dir=library_dir)
|
||||||
|
|
||||||
@vcr.use_cassette(path=os.path.join(library_dir, 'custom_name'))
|
@vcr.use_cassette(path=os.path.join(library_dir, 'custom_name'))
|
||||||
def function_name(cassette):
|
def function_name(cassette):
|
||||||
assert cassette._path == os.path.join(library_dir, 'custom_name')
|
assert cassette._path == os.path.join(library_dir, 'custom_name')
|
||||||
|
|
||||||
function_name()
|
function_name()
|
||||||
|
|
||||||
|
|
||||||
@@ -169,26 +186,32 @@ def test_cassette_library_dir_with_path_transformer():
|
|||||||
library_dir = '/libary_dir'
|
library_dir = '/libary_dir'
|
||||||
vcr = VCR(inject_cassette=True, cassette_library_dir=library_dir,
|
vcr = VCR(inject_cassette=True, cassette_library_dir=library_dir,
|
||||||
path_transformer=lambda path: path + '.json')
|
path_transformer=lambda path: path + '.json')
|
||||||
|
|
||||||
@vcr.use_cassette()
|
@vcr.use_cassette()
|
||||||
def function_name(cassette):
|
def function_name(cassette):
|
||||||
assert cassette._path == os.path.join(library_dir, 'function_name.json')
|
assert cassette._path == os.path.join(library_dir, 'function_name.json')
|
||||||
|
|
||||||
function_name()
|
function_name()
|
||||||
|
|
||||||
|
|
||||||
def test_use_cassette_with_no_extra_invocation():
|
def test_use_cassette_with_no_extra_invocation():
|
||||||
vcr = VCR(inject_cassette=True, cassette_library_dir='/')
|
vcr = VCR(inject_cassette=True, cassette_library_dir='/')
|
||||||
|
|
||||||
@vcr.use_cassette
|
@vcr.use_cassette
|
||||||
def function_name(cassette):
|
def function_name(cassette):
|
||||||
assert cassette._path == os.path.join('/', 'function_name')
|
assert cassette._path == os.path.join('/', 'function_name')
|
||||||
|
|
||||||
function_name()
|
function_name()
|
||||||
|
|
||||||
|
|
||||||
def test_path_transformer():
|
def test_path_transformer():
|
||||||
vcr = VCR(inject_cassette=True, cassette_library_dir='/',
|
vcr = VCR(inject_cassette=True, cassette_library_dir='/',
|
||||||
path_transformer=lambda x: x + '_test')
|
path_transformer=lambda x: x + '_test')
|
||||||
|
|
||||||
@vcr.use_cassette
|
@vcr.use_cassette
|
||||||
def function_name(cassette):
|
def function_name(cassette):
|
||||||
assert cassette._path == os.path.join('/', 'function_name_test')
|
assert cassette._path == os.path.join('/', 'function_name_test')
|
||||||
|
|
||||||
function_name()
|
function_name()
|
||||||
|
|
||||||
|
|
||||||
@@ -203,10 +226,12 @@ def test_cassette_name_generator_defaults_to_using_module_function_defined_in():
|
|||||||
|
|
||||||
def test_ensure_suffix():
|
def test_ensure_suffix():
|
||||||
vcr = VCR(inject_cassette=True, path_transformer=VCR.ensure_suffix('.yaml'))
|
vcr = VCR(inject_cassette=True, path_transformer=VCR.ensure_suffix('.yaml'))
|
||||||
|
|
||||||
@vcr.use_cassette
|
@vcr.use_cassette
|
||||||
def function_name(cassette):
|
def function_name(cassette):
|
||||||
assert cassette._path == os.path.join(os.path.dirname(__file__),
|
assert cassette._path == os.path.join(os.path.dirname(__file__),
|
||||||
'function_name.yaml')
|
'function_name.yaml')
|
||||||
|
|
||||||
function_name()
|
function_name()
|
||||||
|
|
||||||
|
|
||||||
@@ -217,7 +242,7 @@ def test_additional_matchers():
|
|||||||
def function_defaults(cassette):
|
def function_defaults(cassette):
|
||||||
assert set(cassette._match_on) == set([vcr.matchers['uri']])
|
assert set(cassette._match_on) == set([vcr.matchers['uri']])
|
||||||
|
|
||||||
@vcr.use_cassette(additional_matchers=('body'))
|
@vcr.use_cassette(additional_matchers=('body',))
|
||||||
def function_additional(cassette):
|
def function_additional(cassette):
|
||||||
assert set(cassette._match_on) == set([vcr.matchers['uri'], vcr.matchers['body']])
|
assert set(cassette._match_on) == set([vcr.matchers['uri'], vcr.matchers['body']])
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user