mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
Merge pull request #721 from kevin1024/issue-714-response-raw-stream-urllib3-v2
Make response.raw.stream() work for urllib3 v2 (fixes #714)
This commit is contained in:
@@ -144,6 +144,17 @@ def test_redirects(tmpdir, httpbin_both):
|
||||
assert cass.play_count == 2
|
||||
|
||||
|
||||
def test_raw_stream(tmpdir, httpbin):
|
||||
expected_response = requests.get(httpbin.url, stream=True)
|
||||
expected_content = b"".join(expected_response.raw.stream())
|
||||
|
||||
for _ in range(2): # one for recording, one for cassette reply
|
||||
with vcr.use_cassette(str(tmpdir.join("raw_stream.yaml"))):
|
||||
actual_response = requests.get(httpbin.url, stream=True)
|
||||
actual_content = b"".join(actual_response.raw.stream())
|
||||
assert actual_content == expected_content
|
||||
|
||||
|
||||
def test_cross_scheme(tmpdir, httpbin_secure, httpbin):
|
||||
"""Ensure that requests between schemes are treated separately"""
|
||||
# First fetch a url under http, and then again under https and then
|
||||
|
||||
@@ -170,6 +170,13 @@ class VCRHTTPResponse(HTTPResponse):
|
||||
def drain_conn(self):
|
||||
pass
|
||||
|
||||
def stream(self, amt=65536, decode_content=None):
|
||||
while True:
|
||||
b = self._content.read(amt)
|
||||
yield b
|
||||
if not b:
|
||||
break
|
||||
|
||||
|
||||
class VCRConnection:
|
||||
# A reference to the cassette that's currently being patched in
|
||||
|
||||
Reference in New Issue
Block a user