Skip to main content
This is a pre-production deployment of Warehouse. Changes made here affect the production instance of PyPI (pypi.python.org).
Help us improve Python packaging - Donate today!

A VCR imitation for python-requests

Project Description

betamax

Betamax is a VCR imitation for requests. This will make mocking out requests much easier. Tested on Travis CI.

Example Use

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') as vcr:
            resp = self.session.get(
                'https://api.github.com/repos/sigmavirus24/github3.py'
                )
            assert resp.json()['owner'] != {}

VCR Cassette Compatiblity

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.

History

0.1.5 - 2013-09-27

  • Make sure what we pass to base64.b64decode is a bytes object

0.1.4 - 2013-09-27

  • Do not try to sanitize something that may not exist.

0.1.3 - 2013-09-27

  • Fix issue when response has a Content-Encoding of gzip and we need to preserve the original bytes of the message.

0.1.2 - 2013-09-21

  • Fix issues with how requests parses cookies out of responses
  • Fix unicode issues with Response#text (trying to use Response#json raises exception because it cannot use string decoding on a unicode string)

0.1.1 - 2013-09-19

  • Fix issue where there is a unicode character not in range(128)

0.1.0 - 2013-09-17

  • Initial Release
  • Support for VCR generated cassettes (JSON only)
  • Support for re_record_interval
  • Support for the once, all, new_episodes, all cassette modes
  • Support for filtering sensitive data
  • Support for the following methods of request matching:
    • Method
    • URI
    • Host
    • Path
    • Query String
    • Body
    • Headers
Release History

Release History

History Node

0.8.0

History Node

0.7.2

History Node

0.7.1

History Node

0.7.0

History Node

0.6.0

History Node

0.5.1

History Node

0.5.0

History Node

0.4.2

History Node

0.4.1

History Node

0.4.0

History Node

0.3.2

History Node

0.3.1

History Node

0.3.0

History Node

0.2.0

History Node

0.1.6

This version
History Node

0.1.5

History Node

0.1.4

History Node

0.1.3

History Node

0.1.2

History Node

0.1.1

History Node

0.1.0

History Node

0.0.0

Download Files

Download Files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

File Name & Checksum SHA256 Checksum Help Version File Type Upload Date
betamax-0.1.5-py27-none-any.whl (15.4 kB) Copy SHA256 Checksum SHA256 2.7 Wheel Sep 28, 2013
betamax-0.1.5.tar.gz (11.1 kB) Copy SHA256 Checksum SHA256 Source Sep 28, 2013

Supported By

WebFaction WebFaction Technical Writing Elastic Elastic Search Pingdom Pingdom Monitoring Dyn Dyn DNS Sentry Sentry Error Logging CloudAMQP CloudAMQP RabbitMQ Heroku Heroku PaaS Kabu Creative Kabu Creative UX & Design Fastly Fastly CDN DigiCert DigiCert EV Certificate Rackspace Rackspace Cloud Servers DreamHost DreamHost Log Hosting