@@ -204,26 +204,6 @@ def deserialize(cassette_string: str) -> dict:
204
204
return cassette_dict
205
205
206
206
207
- class VCRRemoveAllHeaders :
208
- """
209
- A class responsible for removing all headers from requests and responses.
210
- This can be useful for scenarios where headers are not needed for matching or comparison
211
- in VCR (Virtual Cassette Recorder) interactions, such as when recording or replaying HTTP requests.
212
- """
213
-
214
- @staticmethod
215
- def remove_all_request_headers (request ):
216
- # Save only what's necessary for matching
217
- request .headers = {}
218
- return request
219
-
220
- @staticmethod
221
- def remove_all_response_headers (response ):
222
- # Save only what's necessary for matching
223
- response ["headers" ] = {}
224
- return response
225
-
226
-
227
207
class BaseVCR :
228
208
"""
229
209
A base class for configuring VCR (Virtual Cassette Recorder)
@@ -234,7 +214,37 @@ class BaseVCR:
234
214
It also handles cassette directory configuration.
235
215
"""
236
216
217
+ class VCRRemoveAllHeaders :
218
+ """
219
+ A class responsible for removing all headers from requests and responses.
220
+ This can be useful for scenarios where headers are not needed for matching or comparison
221
+ in VCR (Virtual Cassette Recorder) interactions, such as when recording or replaying HTTP requests.
222
+ """
223
+
224
+ @staticmethod
225
+ def remove_all_request_headers (request ):
226
+ # Save only what's necessary for matching
227
+ request .headers = {}
228
+ return request
229
+
230
+ @staticmethod
231
+ def remove_all_response_headers (response ):
232
+ # Save only what's necessary for matching
233
+ response ["headers" ] = {}
234
+ return response
235
+
237
236
_CASSETTES_DIR = None
237
+ _BASE_CONFIG = {
238
+ # More config options can be found at:
239
+ # https://vcrpy.readthedocs.io/en/latest/configuration.html#configuration
240
+ "record_mode" : "once" , # (default: "once", "always", "none", "new_episodes")
241
+ "serializer" : "pretty-yaml" , # (default: "yaml")
242
+ "decode_compressed_response" : True , # Decode compressed responses
243
+ # (optional) Replace the Authorization request header with "**REDACTED**" in cassettes
244
+ # "filter_headers": [("authorization", "**REDACTED**")],
245
+ "before_record_request" : VCRRemoveAllHeaders .remove_all_request_headers ,
246
+ "before_record_response" : VCRRemoveAllHeaders .remove_all_response_headers ,
247
+ }
238
248
239
249
@pytest .fixture (scope = "module" )
240
250
def vcr (self , vcr ):
@@ -263,17 +273,7 @@ def vcr_config(self):
263
273
264
274
:returns: a dictionary with VCR configuration options
265
275
"""
266
- return {
267
- # More config options can be found at:
268
- # https://vcrpy.readthedocs.io/en/latest/configuration.html#configuration
269
- "record_mode" : "once" , # (default: "once", "always", "none", "new_episodes")
270
- "serializer" : "pretty-yaml" , # (default: "yaml")
271
- "decode_compressed_response" : True , # Decode compressed responses
272
- # (optional) Replace the Authorization request header with "**REDACTED**" in cassettes
273
- # "filter_headers": [("authorization", "**REDACTED**")],
274
- "before_record_request" : VCRRemoveAllHeaders .remove_all_request_headers ,
275
- "before_record_response" : VCRRemoveAllHeaders .remove_all_response_headers ,
276
- }
276
+ return self ._BASE_CONFIG
277
277
278
278
@pytest .fixture (scope = "module" )
279
279
def vcr_cassette_dir (self , request ):
@@ -290,5 +290,5 @@ def vcr_cassette_dir(self, request):
290
290
"""
291
291
# Set self._CASSETTES_DIR or use the default directory path based on the test module name
292
292
return self ._CASSETTES_DIR or os .path .join (
293
- "tests/cassettes " , request .module .__name__
293
+ "tests/vcr_cassettes " , request .module .__name__
294
294
)
0 commit comments