1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-11 18:06:10 +00:00

Updated README

This commit is contained in:
Max Shytikov
2014-04-11 01:37:17 +02:00
parent 96d8782d08
commit a042cb3824

View File

@@ -92,20 +92,26 @@ Note: Per-cassette overrides take precedence over the global config.
## Request matching ## Request matching
Request matching is configurable and allows you to change which requests VCR Request matching is configurable and allows you to change which requests VCR
considers identical. The default behavior is `['url', method']` which means considers identical. The default behavior is
that requests with both the same URL and method (ie POST or GET) are considered `['method', 'scheme', 'host', 'port', 'path', 'query']` which means that
requests with both the same URL and method (ie POST or GET) are considered
identical. identical.
This can be configured by changing the `match_on` setting. This can be configured by changing the `match_on` setting.
The following options are available : The following options are available :
* method (for example, POST or GET) * method (for example, POST or GET)
* url (the full URL, including the protocol) * uri (the full URI.)
* host (the hostname of the server receiving the request) * host (the hostname of the server receiving the request)
* path (excluding the hostname) * port (the port of the server receiving the request)
* body (the entire request body) * path (the path of the request)
* headers (the headers of the request) * query (the query string of the request)
* body (the entire request body)
* headers (the headers of the request)
Backwards compatible matchers:
* url (the `uri` alias)
If these options don't work for you, you can also register your own request If these options don't work for you, you can also register your own request
matcher. This is described in the Advanced section of this README. matcher. This is described in the Advanced section of this README.
@@ -163,8 +169,8 @@ with vcr.use_cassette('fixtures/vcr_cassettes/synopsis.yaml') as cass:
response = urllib2.urlopen('http://www.zombo.com/').read() response = urllib2.urlopen('http://www.zombo.com/').read()
# cass should have 1 request inside it # cass should have 1 request inside it
assert len(cass) == 1 assert len(cass) == 1
# the request url should have been http://www.zombo.com/ # the request uri should have been http://www.zombo.com/
assert cass.requests[0].url == 'http://www.zombo.com/' assert cass.requests[0].uri == 'http://www.zombo.com/'
``` ```
The `Cassette` object exposes the following properties which I consider part of The `Cassette` object exposes the following properties which I consider part of
@@ -177,17 +183,23 @@ the API. The fields are as follows:
back back
* `responses_of(request)`: Access the responses that match a given request * `responses_of(request)`: Access the responses that match a given request
The `Request` object has the following properties The `Request` object has the following properties:
* `url`: The full url of the request, including the protocol. Example: * `uri`: The full uri of the request. Example: "https://google.com/?q=vcrpy"
"http://www.google.com/" * `scheme`: The scheme used to make the request (http or https)
* `path`: The path of the request. For example "/" or "/home.html"
* `host`: The host of the request, for example "www.google.com" * `host`: The host of the request, for example "www.google.com"
* `port`: The port the request was made on * `port`: The port the request was made on
* `path`: The path of the request. For example "/" or "/home.html"
* `query`: The parsed query string of the request. Sorted list of name, value pairs.
* `method` : The method used to make the request, for example "GET" or "POST" * `method` : The method used to make the request, for example "GET" or "POST"
* `protocol`: The protocol used to make the request (http or https)
* `body`: The body of the request, usually empty except for POST / PUT / etc * `body`: The body of the request, usually empty except for POST / PUT / etc
Backwards compatible properties:
* `url`: The `uri` alias
* `protocol`: The `scheme` alias
## Register your own serializer ## Register your own serializer
Don't like JSON or YAML? That's OK, VCR.py can serialize to any format you Don't like JSON or YAML? That's OK, VCR.py can serialize to any format you
@@ -239,7 +251,7 @@ Finally, register your method with VCR to use your new request matcher.
import vcr import vcr
def jurassic_matcher(r1, r2): def jurassic_matcher(r1, r2):
return r1.url == r2.url and 'JURASSIC PARK' in r1.body return r1.uri == r2.uri and 'JURASSIC PARK' in r1.body
my_vcr = vcr.VCR() my_vcr = vcr.VCR()
my_vcr.register_matcher('jurassic', jurassic_matcher) my_vcr.register_matcher('jurassic', jurassic_matcher)