Giter Club home page Giter Club logo

vcrpy's Introduction

#VCR.py

This is a proof-of-concept start at a Python version of Ruby's VCR library.

Build Status

##What it is supposed to do Simplify testing by recording all HTTP interactions and saving them to "cassette" files, which are just yaml files. Then when you run your tests again, they all just hit the text files instead of the internet. This speeds up your tests and lets you work offline.

##Compatibility Notes This should work with Python 2.6 and 2.7. It also seems to work with pypy.

Currently I've only tested this (a little bit) with urllib2. It's known to NOT WORK with urllib.

##How to use it

import vcr
import urllib2

with vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml'):
    response = urllib2.urlopen('http://www.iana.org/domains/example/').read()
    assert 'Example Domains' in response

Run this test once, and VCR.py will record the http request to fixtures/vcr_cassettes/synopsis.yml. Run it again, and VCR.py will replay the response from iana.org when the http request is made. This test is now fast (no real HTTP requests are made anymore), deterministic (the test will continue to pass, even if you are offline, or iana.org goes down for maintenance) and accurate (the response will contain the same headers and body you get from a real request).

##Ruby VCR compatibility I'm not trying to match the format of the YAML files. Cassettes generated by Ruby's VCR are not compatible with VCR.py. The API is similar but VCR.py doesn't have nearly as many features.

##Known Issues

  • Probably only works with urllib2.
  • Loading a HTTPS url and then a HTTP url in the same cassette will cause the second load to use the data from the HTTPS version of the URL: Issue #3
  • Loading urls that do a 301/302 redirect don't work: Issue #4
  • I haven't tested PUT/DELETE requests

##Similar libraries in Python Neither of these really implement the API I want, but I have cribbed some code from them.

#License This library uses the MIT license

vcrpy's People

Contributors

kevin1024 avatar msabramo avatar sriprasanna avatar

Watchers

 avatar James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.