Cassette is a testing tool that stores external HTTP request in YAML file.
Project description
[‘########n’, ‘cassetten’, ‘########n’, ‘n’, ‘- The first time you run your tests, cassette will store all then’, ‘ external requests response in a YAML file.n’, ‘- Next time you run your tests, cassette will fetch those responsesn’, ‘ from the YAML file. You can now run your tests while being offline.n’, ‘n’, ‘.. code:: pythonn’, ‘n’, ‘ import urllib2n’, ‘n’, ‘ import cassetten’, ‘n’, ‘n’, ‘ def test_get_root_domains():n’, ‘ “””Get the root domains.”””n’, ‘n’, ‘ with cassette.play(“data/responses.yaml”):n’, ‘n’, ‘ # If the request is not already stored in responses.yaml, cassetten’, ‘ # will request the URL and store its response in the file.n’, ‘ r = urllib2.urlopen(”http://www.internic.net/domain/named.root”)n’, ‘n’, ‘ # This time, the request response must be in the file. The externaln’, ‘ # request is not made. cassette retrieves the response from then’, ‘ # file.n’, ‘ r = urllib2.urlopen(”http://www.internic.net/domain/named.root”)n’, ‘n’, ‘ assert “A.ROOT-SERVERS.NET” in r.read(10000)n’, ‘n’, ‘Installationn’, ‘============n’, ‘n’, ‘Locally:n’, ‘n’, ‘::n’, ‘n’, ‘ $ python setup.py developn’, ‘n’, ‘Via PyPi:n’, ‘n’, ‘::n’, ‘n’, ‘ $ pip install cassetten’, ‘n’, ‘Usagen’, ‘=====n’, ‘n’, ‘cassette provides a play context:n’, ‘n’, ‘.. code:: pythonn’, ‘n’, ‘ import cassetten’, ‘n’, ‘ with cassette.play(“./data/responses.yaml”):n’, ‘ urllib2.urlopen(“http://…”)n’, ‘n’, ‘Any urllib2.urlopen request happening in this context will gon’, “through cassette’s mocked version of urlopen.n”, ‘n’, ‘You can also setup the context manually:n’, ‘n’, ‘.. code:: pythonn’, ‘n’, ‘ import cassetten’, ‘n’, ‘ cassette.insert(“./data/responses.yaml”)n’, ‘ urllib2.urlopen(“http://…”)n’, ‘ cassette.eject()n’, ‘n’, ‘Running cassette testsn’, ‘======================n’, ‘n’, ‘Install requirements:n’, ‘n’, ‘::n’, ‘n’, ‘ $ pip install -r requirements-dev.txtn’, ‘n’, ‘Run tests:n’, ‘n’, ‘::n’, ‘n’, ‘ $ fab testn’, ‘n’, ‘Similar librariesn’, ‘=================n’, ‘n’, ‘- vcrpy: great library but youn’, ‘ can store only one request per YAML file…n’, ‘- vcr: in Rubyn’, ‘n’, ‘Limitationsn’, ‘===========n’, ‘n’, ‘This package should be considered alpha:n’, ‘n’, ‘- Only tested with urllib2n’, ‘- Should not work with urllib and requestsn’, ‘- The format used is not compatible with vcr or vcrpyn’, ‘- Only tested with Python 2.7n’, ‘- File format may change.n’, ‘n’, ‘Licensen’, ‘=======n’, ‘n’, ‘cassette is available under the MIT License.n’]
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.