Debian Codegraph @

PKG-INFO

raw
1 Metadata-Version: 2.1
2 Name: betamax
3 Version: 0.9.0
4 Summary: A VCR imitation for python-requests
5 Home-page: https://github.com/sigmavirus24/betamax
6 Author: Ian Stapleton Cordasco
7 Author-email: [email protected]
8 License: Apache-2.0
9 Classifier: Development Status :: 5 - Production/Stable
10 Classifier: Intended Audience :: Developers
11 Classifier: License :: OSI Approved :: Apache Software License
12 Classifier: Programming Language :: Python
13 Classifier: Programming Language :: Python :: 3
14 Classifier: Programming Language :: Python :: 3 :: Only
15 Classifier: Programming Language :: Python :: 3.8
16 Classifier: Programming Language :: Python :: 3.9
17 Classifier: Programming Language :: Python :: 3.10
18 Classifier: Programming Language :: Python :: 3.11
19 Classifier: Programming Language :: Python :: Implementation :: CPython
20 Classifier: Programming Language :: Python :: Implementation :: PyPy
21 Classifier: Topic :: Software Development :: Libraries :: Python Modules
22 Classifier: Topic :: Software Development :: Quality Assurance
23 Requires-Python: >=3.8.1
24 Description-Content-Type: text/x-rst
25 License-File: LICENSE
26 Requires-Dist: requests>=2.0
27
28 betamax
29 =======
30
31 Betamax is a VCR_ imitation for requests. This will make mocking out requests
32 much easier. It is tested on `Travis CI`_.
33
34 Put in a more humorous way: "Betamax records your HTTP interactions so the NSA
35 does not have to."
36
37 Example Use
38 -----------
39
40 .. code-block:: python
41
42 from betamax import Betamax
43 from requests import Session
44 from unittest import TestCase
45
46 with Betamax.configure() as config:
47 config.cassette_library_dir = 'tests/fixtures/cassettes'
48
49
50 class TestGitHubAPI(TestCase):
51 def setUp(self):
52 self.session = Session()
53 self.headers.update(...)
54
55 # Set the cassette in a line other than the context declaration
56 def test_user(self):
57 with Betamax(self.session) as vcr:
58 vcr.use_cassette('user')
59 resp = self.session.get('https://api.github.com/user',
60 auth=('user', 'pass'))
61 assert resp.json()['login'] is not None
62
63 # Set the cassette in line with the context declaration
64 def test_repo(self):
65 with Betamax(self.session).use_cassette('repo'):
66 resp = self.session.get(
67 'https://api.github.com/repos/sigmavirus24/github3.py'
68 )
69 assert resp.json()['owner'] != {}
70
71 What does it even do?
72 ---------------------
73
74 If you are unfamiliar with VCR_, you might need a better explanation of what
75 Betamax does.
76
77 Betamax intercepts every request you make and attempts to find a matching
78 request that has already been intercepted and recorded. Two things can then
79 happen:
80
81 1. If there is a matching request, it will return the response that is
82 associated with it.
83 2. If there is **not** a matching request and it is allowed to record new
84 responses, it will make the request, record the response and return the
85 response.
86
87 Recorded requests and corresponding responses - also known as interactions -
88 are stored in files called cassettes. (An example cassette can be seen in
89 the `examples section of the documentation`_.) The directory you store your
90 cassettes in is called your library, or your `cassette library`_.
91
92 VCR Cassette Compatibility
93 --------------------------
94
95 Betamax can use any VCR-recorded cassette as of this point in time. The only
96 caveat is that python-requests returns a URL on each response. VCR does not
97 store that in a cassette now but we will. Any VCR-recorded cassette used to
98 playback a response will unfortunately not have a URL attribute on responses
99 that are returned. This is a minor annoyance but not something that can be
100 fixed.
101
102 .. _VCR: https://github.com/vcr/vcr
103 .. _Travis CI: https://travis-ci.org/sigmavirus24/betamax
104 .. _examples section of the documentation:
105 http://betamax.readthedocs.org/en/latest/api.html#examples
106 .. _cassette library:
107 http://betamax.readthedocs.org/en/latest/cassettes.html