1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-09 01:03:24 +00:00

Fix Requests so it can gunzip the request body

I wasn't emulating the stateful file-object in my response stub,
so urllib3 wasn't decompressing gzipped bodies properly.  This
should fix that problem.

Thanks @bryanhelmig for the motivation to dig into this.
This commit is contained in:
Kevin McCarthy
2013-11-09 17:33:33 -10:00
parent d33b19b5bb
commit b0a13ba690
3 changed files with 35 additions and 2 deletions

View File

@@ -5,7 +5,11 @@
import os
import pytest
import vcr
from assertions import assert_cassette_empty, assert_cassette_has_one_response
from assertions import (
assert_cassette_empty,
assert_cassette_has_one_response,
assert_is_json
)
requests = pytest.importorskip("requests")
@@ -117,3 +121,19 @@ def test_cross_scheme(tmpdir, scheme):
requests.get('http://httpbin.org/')
assert cass.play_count == 0
assert len(cass) == 2
def test_gzip(tmpdir, scheme):
'''
Ensure that requests (actually urllib3) is able to automatically decompress
the response body
'''
url = scheme + '://httpbin.org/gzip'
response = requests.get(url)
with vcr.use_cassette(str(tmpdir.join('gzip.yaml'))) as cass:
response = requests.get(url)
assert_is_json(response.content)
with vcr.use_cassette(str(tmpdir.join('gzip.yaml'))) as cass:
assert_is_json(response.content)