+import json
+
+
def assert_cassette_empty(cass):
assert len(cass) == 0
assert cass.play_count == 0
def assert_cassette_has_one_response(cass):
assert len(cass) == 1
assert cass.play_count == 1
+
+
+def assert_is_json(a_string):
+ try:
+ json.loads(a_string)
+ except Exception:
+ assert False
+ assert True
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")
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)
self.status = recorded_response['status']['code']
self.version = None
self._content = StringIO(self.recorded_response['body']['string'])
+ self.closed = False
# We are skipping the header parsing (they have already been parsed
# at this point) and directly adding the headers to the header
return self._content.read(*args, **kwargs)
def close(self):
+ self.closed = True
return True
def isclosed(self):
# Urllib3 seems to call this because it actually uses
# the weird chunking support in httplib
- return True
+ return self.closed
def getheaders(self):
return self.recorded_response['headers'].iteritems()