/usr/lib/python3/dist-packages/betamax/configure.py is in python3-betamax 0.8.0-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 | from .cassette import Cassette
class Configuration(object):
"""This object acts as a proxy to configure different parts of Betamax.
You should only ever encounter this object when configuring the library as
a whole. For example:
.. code::
with Betamax.configure() as config:
config.cassette_library_dir = 'tests/cassettes/'
config.default_cassette_options['record_mode'] = 'once'
config.default_cassette_options['match_requests_on'] = ['uri']
config.define_cassette_placeholder('<URI>', 'http://httpbin.org')
config.preserve_exact_body_bytes = True
"""
CASSETTE_LIBRARY_DIR = 'vcr/cassettes'
def __enter__(self):
return self
def __exit__(self, *args):
pass
def __setattr__(self, prop, value):
if prop == 'preserve_exact_body_bytes':
self.default_cassette_options[prop] = True
else:
super(Configuration, self).__setattr__(prop, value)
def before_playback(self, tag=None, callback=None):
"""Register a function to call before playing back an interaction.
Example usage:
.. code-block:: python
def before_playback(interaction, cassette):
pass
with Betamax.configure() as config:
config.before_playback(callback=before_playback)
:param str tag:
Limits the interactions passed to the function based on the
interaction's tag (currently unsupported).
:param callable callback:
The function which either accepts just an interaction or an
interaction and a cassette and mutates the interaction before
returning.
"""
Cassette.hooks['before_playback'].append(callback)
def before_record(self, tag=None, callback=None):
"""Register a function to call before recording an interaction.
Example usage:
.. code-block:: python
def before_record(interaction, cassette):
pass
with Betamax.configure() as config:
config.before_record(callback=before_record)
:param str tag:
Limits the interactions passed to the function based on the
interaction's tag (currently unsupported).
:param callable callback:
The function which either accepts just an interaction or an
interaction and a cassette and mutates the interaction before
returning.
"""
Cassette.hooks['before_record'].append(callback)
@property
def cassette_library_dir(self):
"""Retrieve and set the directory to store the cassettes in."""
return Configuration.CASSETTE_LIBRARY_DIR
@cassette_library_dir.setter
def cassette_library_dir(self, value):
Configuration.CASSETTE_LIBRARY_DIR = value
@property
def default_cassette_options(self):
"""Retrieve and set the default cassette options.
The options include:
- ``match_requests_on``
- ``placeholders``
- ``re_record_interval``
- ``record_mode``
- ``preserve_exact_body_bytes``
Other options will be ignored.
"""
return Cassette.default_cassette_options
@default_cassette_options.setter
def default_cassette_options(self, value):
Cassette.default_cassette_options = value
def define_cassette_placeholder(self, placeholder, replace):
"""Define a placeholder value for some text.
This also will replace the placeholder text with the text you wish it
to use when replaying interactions from cassettes.
:param str placeholder: (required), text to be used as a placeholder
:param str replace: (required), text to be replaced or replacing the
placeholder
"""
self.default_cassette_options['placeholders'].append({
'placeholder': placeholder,
'replace': replace,
})
|