mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
fix: usage of io-like interface with VCR.py (#906)
* fix: usage of io-like interface with VCR.py * Update tests/integration/test_aiohttp.py Co-authored-by: Jair Henrique <jair.henrique@gmail.com> --------- Co-authored-by: Jair Henrique <jair.henrique@gmail.com>
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import io
|
||||||
import logging
|
import logging
|
||||||
import ssl
|
import ssl
|
||||||
import urllib.parse
|
import urllib.parse
|
||||||
@@ -462,3 +463,19 @@ def test_filter_query_parameters(tmpdir, httpbin):
|
|||||||
cassette_content = f.read()
|
cassette_content = f.read()
|
||||||
assert "password" not in cassette_content
|
assert "password" not in cassette_content
|
||||||
assert "secret" not in cassette_content
|
assert "secret" not in cassette_content
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.online
|
||||||
|
def test_use_cassette_with_io(tmpdir, caplog, httpbin):
|
||||||
|
url = httpbin.url + "/post"
|
||||||
|
|
||||||
|
# test without cassettes
|
||||||
|
data = io.BytesIO(b"hello")
|
||||||
|
_, response_json = request("POST", url, output="json", data=data)
|
||||||
|
assert response_json["data"] == "hello"
|
||||||
|
|
||||||
|
# test with cassettes
|
||||||
|
data = io.BytesIO(b"hello")
|
||||||
|
with vcr.use_cassette(str(tmpdir.join("post.yaml"))):
|
||||||
|
_, response_json = request("POST", url, output="json", data=data)
|
||||||
|
assert response_json["data"] == "hello"
|
||||||
|
|||||||
@@ -20,7 +20,12 @@ class Request:
|
|||||||
self._was_file = hasattr(body, "read")
|
self._was_file = hasattr(body, "read")
|
||||||
self._was_iter = _is_nonsequence_iterator(body)
|
self._was_iter = _is_nonsequence_iterator(body)
|
||||||
if self._was_file:
|
if self._was_file:
|
||||||
self.body = body.read()
|
if hasattr(body, "tell"):
|
||||||
|
tell = body.tell()
|
||||||
|
self.body = body.read()
|
||||||
|
body.seek(tell)
|
||||||
|
else:
|
||||||
|
self.body = body.read()
|
||||||
elif self._was_iter:
|
elif self._was_iter:
|
||||||
self.body = list(body)
|
self.body = list(body)
|
||||||
else:
|
else:
|
||||||
|
|||||||
Reference in New Issue
Block a user