1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00

Add support for calling httplib.send().

This commit changes the whole core internal flow of requests.
Now, requests are actually physically made lazily when a response
is requested.  This allows the entire request to be sent at once.

Otherwise, it would be impossible to compare whether requests have
already been recorded, since httplib.send() allows you to effectively
stream requests over HTTP.
This commit is contained in:
Kevin McCarthy
2013-09-15 10:47:24 -10:00
parent 07774ae6dd
commit 5ce67dc023
4 changed files with 125 additions and 13 deletions

View File

@@ -3,6 +3,8 @@ requests = pytest.importorskip("requests")
import vcr
import httplib
def test_domain_redirect():
'''Ensure that redirects across domains are considered unique'''
@@ -15,3 +17,31 @@ def test_domain_redirect():
# Ensure that we've now served two responses. One for the original
# redirect, and a second for the actual fetch
assert len(cass) == 2
def test_flickr_multipart_upload():
"""
The python-flickr-api project does a multipart
upload that confuses vcrpy
"""
def _pretend_to_be_flickr_library():
content_type, body = "text/plain", "HELLO WORLD"
h = httplib.HTTPConnection("httpbin.org")
headers = {
"Content-Type": content_type,
"content-length": str(len(body))
}
h.request("POST", "/post/", headers=headers)
h.send(body)
r = h.getresponse()
data = r.read()
h.close()
with vcr.use_cassette('fixtures/vcr_cassettes/flickr.json') as cass:
_pretend_to_be_flickr_library()
assert len(cass) == 1
with vcr.use_cassette('fixtures/vcr_cassettes/flickr.json') as cass:
assert len(cass) == 1
_pretend_to_be_flickr_library()
assert cass.play_count == 1