mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Enable brotli decompression if it is available (#620)
* Enable brotli decompression if it is available * Apply PR feedback
This commit is contained in:
@@ -7,6 +7,7 @@ from urllib.request import Request, urlopen
|
||||
import pytest
|
||||
|
||||
import vcr
|
||||
from vcr.filters import brotli
|
||||
|
||||
from ..assertions import assert_cassette_has_one_response, assert_is_json_bytes
|
||||
|
||||
@@ -138,6 +139,22 @@ def test_decompress_deflate(tmpdir, httpbin):
|
||||
assert_is_json_bytes(decoded_response)
|
||||
|
||||
|
||||
def test_decompress_brotli(tmpdir, httpbin):
|
||||
if brotli is None:
|
||||
# XXX: this is never true, because brotlipy is installed with "httpbin"
|
||||
pytest.skip("Brotli is not installed")
|
||||
|
||||
url = httpbin.url + "/brotli"
|
||||
request = Request(url, headers={"Accept-Encoding": ["gzip, deflate, br"]})
|
||||
cass_file = str(tmpdir.join("brotli_response.yaml"))
|
||||
with vcr.use_cassette(cass_file, decode_compressed_response=True):
|
||||
urlopen(request)
|
||||
with vcr.use_cassette(cass_file) as cass:
|
||||
decoded_response = urlopen(url).read()
|
||||
assert_cassette_has_one_response(cass)
|
||||
assert_is_json_bytes(decoded_response)
|
||||
|
||||
|
||||
def test_decompress_regular(tmpdir, httpbin):
|
||||
"""Test that it doesn't try to decompress content that isn't compressed"""
|
||||
url = httpbin.url + "/get"
|
||||
|
||||
Reference in New Issue
Block a user