mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-08 16:53:23 +00:00
committed by
Jair Henrique
parent
f3f66086a1
commit
eb59d871b4
@@ -106,6 +106,18 @@ def test_decompress_gzip(tmpdir, httpbin):
|
||||
assert_is_json(decoded_response)
|
||||
|
||||
|
||||
def test_decomptess_empty_body(tmpdir, httpbin):
|
||||
url = httpbin.url + "/gzip"
|
||||
request = Request(url, headers={"Accept-Encoding": ["gzip, deflate"]}, method="HEAD")
|
||||
cass_file = str(tmpdir.join("gzip_empty_response.yaml"))
|
||||
with vcr.use_cassette(cass_file, decode_compressed_response=True):
|
||||
response = urlopen(request).read()
|
||||
with vcr.use_cassette(cass_file) as cass:
|
||||
decoded_response = urlopen(request).read()
|
||||
assert_cassette_has_one_response(cass)
|
||||
assert decoded_response == response
|
||||
|
||||
|
||||
def test_decompress_deflate(tmpdir, httpbin):
|
||||
url = httpbin.url + "/deflate"
|
||||
request = Request(url, headers={"Accept-Encoding": ["gzip, deflate"]})
|
||||
|
||||
@@ -150,6 +150,8 @@ def decode_response(response):
|
||||
"""Returns decompressed body according to encoding using zlib.
|
||||
to (de-)compress gzip format, use wbits = zlib.MAX_WBITS | 16
|
||||
"""
|
||||
if not body:
|
||||
return ""
|
||||
if encoding == "gzip":
|
||||
return zlib.decompress(body, zlib.MAX_WBITS | 16)
|
||||
else: # encoding == 'deflate'
|
||||
|
||||
Reference in New Issue
Block a user