mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-11 10:03:00 +00:00
make it work with gzipped data
This commit is contained in:
committed by
Kevin McCarthy
parent
b8024de1b8
commit
79d26ebb43
@@ -139,3 +139,15 @@ def test_redirect(tmpdir, do_request, yml):
|
|||||||
assert {k: v for k, v in cassette_response.request.headers.items()} == {
|
assert {k: v for k, v in cassette_response.request.headers.items()} == {
|
||||||
k: v for k, v in response.request.headers.items()
|
k: v for k, v in response.request.headers.items()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
def test_work_with_gzipped_data(tmpdir, do_request, yml):
|
||||||
|
with vcr.use_cassette(yml):
|
||||||
|
response = do_request()("GET", "https://httpbin.org/gzip")
|
||||||
|
|
||||||
|
with vcr.use_cassette(yml) as cassette:
|
||||||
|
cassette_response = do_request()("GET", "https://httpbin.org/gzip")
|
||||||
|
|
||||||
|
assert "gzip" in cassette_response.json()["headers"]["Accept-Encoding"]
|
||||||
|
assert cassette_response.read()
|
||||||
|
assert cassette.play_count == 1
|
||||||
|
|||||||
@@ -27,15 +27,19 @@ def _to_serialized_response(httpx_reponse):
|
|||||||
|
|
||||||
|
|
||||||
@patch("httpx.Response.close", MagicMock())
|
@patch("httpx.Response.close", MagicMock())
|
||||||
|
@patch("httpx.Response.read", MagicMock())
|
||||||
def _from_serialized_response(request, serialized_response, history=None):
|
def _from_serialized_response(request, serialized_response, history=None):
|
||||||
return httpx.Response(
|
content = serialized_response.get("content").encode()
|
||||||
|
response = httpx.Response(
|
||||||
status_code=serialized_response.get("status_code"),
|
status_code=serialized_response.get("status_code"),
|
||||||
request=request,
|
request=request,
|
||||||
http_version=serialized_response.get("http_version"),
|
http_version=serialized_response.get("http_version"),
|
||||||
headers=serialized_response.get("headers"),
|
headers=serialized_response.get("headers"),
|
||||||
content=serialized_response.get("content"),
|
content=content,
|
||||||
history=history or [],
|
history=history or [],
|
||||||
)
|
)
|
||||||
|
response._content = content
|
||||||
|
return response
|
||||||
|
|
||||||
|
|
||||||
def _make_vcr_request(httpx_request, **kwargs):
|
def _make_vcr_request(httpx_request, **kwargs):
|
||||||
|
|||||||
Reference in New Issue
Block a user