betamax


Namebetamax JSON
Version 0.9.0 PyPI version JSON
download
home_pagehttps://github.com/sigmavirus24/betamax
SummaryA VCR imitation for python-requests
upload_time2024-02-08 13:13:37
maintainer
docs_urlNone
authorIan Stapleton Cordasco
requires_python>=3.8.1
licenseApache-2.0
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            betamax
=======

Betamax is a VCR_ imitation for requests. This will make mocking out requests
much easier. It is tested on `Travis CI`_.

Put in a more humorous way: "Betamax records your HTTP interactions so the NSA
does not have to."

Example Use
-----------

.. code-block:: python

    from betamax import Betamax
    from requests import Session
    from unittest import TestCase

    with Betamax.configure() as config:
        config.cassette_library_dir = 'tests/fixtures/cassettes'


    class TestGitHubAPI(TestCase):
        def setUp(self):
            self.session = Session()
            self.headers.update(...)

        # Set the cassette in a line other than the context declaration
        def test_user(self):
            with Betamax(self.session) as vcr:
                vcr.use_cassette('user')
                resp = self.session.get('https://api.github.com/user',
                                        auth=('user', 'pass'))
                assert resp.json()['login'] is not None

        # Set the cassette in line with the context declaration
        def test_repo(self):
            with Betamax(self.session).use_cassette('repo'):
                resp = self.session.get(
                    'https://api.github.com/repos/sigmavirus24/github3.py'
                    )
                assert resp.json()['owner'] != {}

What does it even do?
---------------------

If you are unfamiliar with VCR_, you might need a better explanation of what
Betamax does.

Betamax intercepts every request you make and attempts to find a matching
request that has already been intercepted and recorded. Two things can then
happen:

1. If there is a matching request, it will return the response that is
   associated with it.
2. If there is **not** a matching request and it is allowed to record new
   responses, it will make the request, record the response and return the
   response.

Recorded requests and corresponding responses - also known as interactions -
are stored in files called cassettes. (An example cassette can be seen in
the `examples section of the documentation`_.) The directory you store your
cassettes in is called your library, or your `cassette library`_.

VCR Cassette Compatibility
--------------------------

Betamax can use any VCR-recorded cassette as of this point in time. The only
caveat is that python-requests returns a URL on each response. VCR does not
store that in a cassette now but we will. Any VCR-recorded cassette used to
playback a response will unfortunately not have a URL attribute on responses
that are returned. This is a minor annoyance but not something that can be
fixed.

.. _VCR: https://github.com/vcr/vcr
.. _Travis CI: https://travis-ci.org/sigmavirus24/betamax
.. _examples section of the documentation:
    http://betamax.readthedocs.org/en/latest/api.html#examples
.. _cassette library:
    http://betamax.readthedocs.org/en/latest/cassettes.html

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/sigmavirus24/betamax",
    "name": "betamax",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.8.1",
    "maintainer_email": "",
    "keywords": "",
    "author": "Ian Stapleton Cordasco",
    "author_email": "graffatcolmingov@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/c2/a2/b5a47f7c57ef30337503bf7ea959e498a314018eb74dd833d4bd4a689e03/betamax-0.9.0.tar.gz",
    "platform": null,
    "description": "betamax\n=======\n\nBetamax is a VCR_ imitation for requests. This will make mocking out requests\nmuch easier. It is tested on `Travis CI`_.\n\nPut in a more humorous way: \"Betamax records your HTTP interactions so the NSA\ndoes not have to.\"\n\nExample Use\n-----------\n\n.. code-block:: python\n\n    from betamax import Betamax\n    from requests import Session\n    from unittest import TestCase\n\n    with Betamax.configure() as config:\n        config.cassette_library_dir = 'tests/fixtures/cassettes'\n\n\n    class TestGitHubAPI(TestCase):\n        def setUp(self):\n            self.session = Session()\n            self.headers.update(...)\n\n        # Set the cassette in a line other than the context declaration\n        def test_user(self):\n            with Betamax(self.session) as vcr:\n                vcr.use_cassette('user')\n                resp = self.session.get('https://api.github.com/user',\n                                        auth=('user', 'pass'))\n                assert resp.json()['login'] is not None\n\n        # Set the cassette in line with the context declaration\n        def test_repo(self):\n            with Betamax(self.session).use_cassette('repo'):\n                resp = self.session.get(\n                    'https://api.github.com/repos/sigmavirus24/github3.py'\n                    )\n                assert resp.json()['owner'] != {}\n\nWhat does it even do?\n---------------------\n\nIf you are unfamiliar with VCR_, you might need a better explanation of what\nBetamax does.\n\nBetamax intercepts every request you make and attempts to find a matching\nrequest that has already been intercepted and recorded. Two things can then\nhappen:\n\n1. If there is a matching request, it will return the response that is\n   associated with it.\n2. If there is **not** a matching request and it is allowed to record new\n   responses, it will make the request, record the response and return the\n   response.\n\nRecorded requests and corresponding responses - also known as interactions -\nare stored in files called cassettes. (An example cassette can be seen in\nthe `examples section of the documentation`_.) The directory you store your\ncassettes in is called your library, or your `cassette library`_.\n\nVCR Cassette Compatibility\n--------------------------\n\nBetamax can use any VCR-recorded cassette as of this point in time. The only\ncaveat is that python-requests returns a URL on each response. VCR does not\nstore that in a cassette now but we will. Any VCR-recorded cassette used to\nplayback a response will unfortunately not have a URL attribute on responses\nthat are returned. This is a minor annoyance but not something that can be\nfixed.\n\n.. _VCR: https://github.com/vcr/vcr\n.. _Travis CI: https://travis-ci.org/sigmavirus24/betamax\n.. _examples section of the documentation:\n    http://betamax.readthedocs.org/en/latest/api.html#examples\n.. _cassette library:\n    http://betamax.readthedocs.org/en/latest/cassettes.html\n",
    "bugtrack_url": null,
    "license": "Apache-2.0",
    "summary": "A VCR imitation for python-requests",
    "version": "0.9.0",
    "project_urls": {
        "Homepage": "https://github.com/sigmavirus24/betamax"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "ac8084dfae1dea86beb985c9aeaf907a7c98e1dd9de2156c8dd2e336d868f38a",
                "md5": "23f888268727aa9b4561172b08a5f315",
                "sha256": "880d6da87eaf7e61c42bdc4240f0ac04ab5365bd7f2798784c18d37d8cf747bc"
            },
            "downloads": -1,
            "filename": "betamax-0.9.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "23f888268727aa9b4561172b08a5f315",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": ">=3.8.1",
            "size": 33418,
            "upload_time": "2024-02-08T13:13:23",
            "upload_time_iso_8601": "2024-02-08T13:13:23.888943Z",
            "url": "https://files.pythonhosted.org/packages/ac/80/84dfae1dea86beb985c9aeaf907a7c98e1dd9de2156c8dd2e336d868f38a/betamax-0.9.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "c2a2b5a47f7c57ef30337503bf7ea959e498a314018eb74dd833d4bd4a689e03",
                "md5": "cd7f35054a5a308072996e874473f620",
                "sha256": "82316e1679bc6879e3c83318d016b54b7c9225ff08c4462de4813e22038d5f94"
            },
            "downloads": -1,
            "filename": "betamax-0.9.0.tar.gz",
            "has_sig": false,
            "md5_digest": "cd7f35054a5a308072996e874473f620",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8.1",
            "size": 79957,
            "upload_time": "2024-02-08T13:13:37",
            "upload_time_iso_8601": "2024-02-08T13:13:37.546212Z",
            "url": "https://files.pythonhosted.org/packages/c2/a2/b5a47f7c57ef30337503bf7ea959e498a314018eb74dd833d4bd4a689e03/betamax-0.9.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-02-08 13:13:37",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "sigmavirus24",
    "github_project": "betamax",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "betamax"
}
        
Elapsed time: 0.18077s