@@ -15,9 +15,11 @@ def test_vcr_use_cassette():
1515 'vcr.cassette.Cassette.load' ,
1616 return_value = mock .MagicMock (inject = False )
1717 ) as mock_cassette_load :
18+
1819 @test_vcr .use_cassette ('test' )
1920 def function ():
2021 pass
22+
2123 assert mock_cassette_load .call_count == 0
2224 function ()
2325 assert mock_cassette_load .call_args [1 ]['record_mode' ] is record_mode
@@ -38,9 +40,11 @@ def function():
3840
3941def test_vcr_before_record_request_params ():
4042 base_path = 'http://httpbin.org/'
43+
4144 def before_record_cb (request ):
4245 if request .path != '/get' :
4346 return request
47+
4448 test_vcr = VCR (filter_headers = ('cookie' ,), before_record_request = before_record_cb ,
4549 ignore_hosts = ('www.test.com' ,), ignore_localhost = True ,
4650 filter_query_parameters = ('foo' ,))
@@ -53,8 +57,12 @@ def before_record_cb(request):
5357 assert cassette .filter_request (
5458 Request ('GET' , base_path + '?foo=bar' , '' ,
5559 {'cookie' : 'test' , 'other' : 'fun' })).headers == {'other' : 'fun' }
56- assert cassette .filter_request (Request ('GET' , base_path + '?foo=bar' , '' ,
57- {'cookie' : 'test' , 'other' : 'fun' })).headers == {'other' : 'fun' }
60+ assert cassette .filter_request (
61+ Request (
62+ 'GET' , base_path + '?foo=bar' , '' ,
63+ {'cookie' : 'test' , 'other' : 'fun' }
64+ )
65+ ).headers == {'other' : 'fun' }
5866
5967 assert cassette .filter_request (Request ('GET' , 'http://www.test.com' + '?foo=bar' , '' ,
6068 {'cookie' : 'test' , 'other' : 'fun' })) is None
@@ -103,6 +111,7 @@ class Test(object):
103111
104112def test_inject_cassette ():
105113 vcr = VCR (inject_cassette = True )
114+
106115 @vcr .use_cassette ('test' , record_mode = 'once' )
107116 def with_cassette_injected (cassette ):
108117 assert cassette .record_mode == 'once'
@@ -117,9 +126,11 @@ def without_cassette_injected():
117126
118127def test_with_current_defaults ():
119128 vcr = VCR (inject_cassette = True , record_mode = 'once' )
129+
120130 @vcr .use_cassette ('test' , with_current_defaults = False )
121131 def changing_defaults (cassette , checks ):
122132 checks (cassette )
133+
123134 @vcr .use_cassette ('test' , with_current_defaults = True )
124135 def current_defaults (cassette , checks ):
125136 checks (cassette )
@@ -141,54 +152,66 @@ def assert_record_mode_all(cassette):
141152def test_cassette_library_dir_with_decoration_and_no_explicit_path ():
142153 library_dir = '/libary_dir'
143154 vcr = VCR (inject_cassette = True , cassette_library_dir = library_dir )
155+
144156 @vcr .use_cassette ()
145157 def function_name (cassette ):
146158 assert cassette ._path == os .path .join (library_dir , 'function_name' )
159+
147160 function_name ()
148161
149162
150163def test_cassette_library_dir_with_decoration_and_explicit_path ():
151164 library_dir = '/libary_dir'
152165 vcr = VCR (inject_cassette = True , cassette_library_dir = library_dir )
166+
153167 @vcr .use_cassette (path = 'custom_name' )
154168 def function_name (cassette ):
155169 assert cassette ._path == os .path .join (library_dir , 'custom_name' )
170+
156171 function_name ()
157172
158173
159174def test_cassette_library_dir_with_decoration_and_super_explicit_path ():
160175 library_dir = '/libary_dir'
161176 vcr = VCR (inject_cassette = True , cassette_library_dir = library_dir )
177+
162178 @vcr .use_cassette (path = os .path .join (library_dir , 'custom_name' ))
163179 def function_name (cassette ):
164180 assert cassette ._path == os .path .join (library_dir , 'custom_name' )
181+
165182 function_name ()
166183
167184
168185def test_cassette_library_dir_with_path_transformer ():
169186 library_dir = '/libary_dir'
170187 vcr = VCR (inject_cassette = True , cassette_library_dir = library_dir ,
171188 path_transformer = lambda path : path + '.json' )
189+
172190 @vcr .use_cassette ()
173191 def function_name (cassette ):
174192 assert cassette ._path == os .path .join (library_dir , 'function_name.json' )
193+
175194 function_name ()
176195
177196
178197def test_use_cassette_with_no_extra_invocation ():
179198 vcr = VCR (inject_cassette = True , cassette_library_dir = '/' )
199+
180200 @vcr .use_cassette
181201 def function_name (cassette ):
182202 assert cassette ._path == os .path .join ('/' , 'function_name' )
203+
183204 function_name ()
184205
185206
186207def test_path_transformer ():
187208 vcr = VCR (inject_cassette = True , cassette_library_dir = '/' ,
188209 path_transformer = lambda x : x + '_test' )
210+
189211 @vcr .use_cassette
190212 def function_name (cassette ):
191213 assert cassette ._path == os .path .join ('/' , 'function_name_test' )
214+
192215 function_name ()
193216
194217
@@ -203,10 +226,12 @@ def function_name(cassette):
203226
204227def test_ensure_suffix ():
205228 vcr = VCR (inject_cassette = True , path_transformer = VCR .ensure_suffix ('.yaml' ))
229+
206230 @vcr .use_cassette
207231 def function_name (cassette ):
208232 assert cassette ._path == os .path .join (os .path .dirname (__file__ ),
209233 'function_name.yaml' )
234+
210235 function_name ()
211236
212237
@@ -217,7 +242,7 @@ def test_additional_matchers():
217242 def function_defaults (cassette ):
218243 assert set (cassette ._match_on ) == set ([vcr .matchers ['uri' ]])
219244
220- @vcr .use_cassette (additional_matchers = ('body' ))
245+ @vcr .use_cassette (additional_matchers = ('body' , ))
221246 def function_additional (cassette ):
222247 assert set (cassette ._match_on ) == set ([vcr .matchers ['uri' ], vcr .matchers ['body' ]])
223248
0 commit comments