mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
Removed requests usage from test
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import vcr
|
import vcr
|
||||||
import six.moves.http_client as httplib
|
import six.moves.http_client as httplib
|
||||||
from six.moves.urllib.request import urlopen, Request
|
|
||||||
|
|
||||||
from assertions import assert_is_json
|
from assertions import assert_is_json
|
||||||
|
|
||||||
@@ -51,24 +50,31 @@ def test_multiple_headers(tmpdir, httpbin):
|
|||||||
|
|
||||||
def test_original_decoded_response_is_not_modified(tmpdir, httpbin):
|
def test_original_decoded_response_is_not_modified(tmpdir, httpbin):
|
||||||
testfile = str(tmpdir.join('decoded_response.yml'))
|
testfile = str(tmpdir.join('decoded_response.yml'))
|
||||||
url = httpbin.url + '/gzip'
|
host, port = httpbin.host, httpbin.port
|
||||||
request = Request(url)
|
|
||||||
outside = urlopen(request)
|
conn = httplib.HTTPConnection(host, port)
|
||||||
|
conn.request('GET', '/gzip')
|
||||||
|
outside = conn.getresponse()
|
||||||
|
|
||||||
with vcr.use_cassette(testfile, decode_compressed_response=True):
|
with vcr.use_cassette(testfile, decode_compressed_response=True):
|
||||||
inside = urlopen(request)
|
conn = httplib.HTTPConnection(host, port)
|
||||||
|
conn.request('GET', '/gzip')
|
||||||
|
inside = conn.getresponse()
|
||||||
|
|
||||||
# Assert that we do not modify the original response while appending
|
# Assert that we do not modify the original response while appending
|
||||||
# to the casssette.
|
# to the casssette.
|
||||||
assert 'gzip' == inside.headers['content-encoding']
|
assert 'gzip' == inside.headers['content-encoding']
|
||||||
|
|
||||||
# They should be the same response.
|
# They should effectively be the same response.
|
||||||
assert inside.headers.items() == outside.headers.items()
|
assert inside.headers.items() == outside.getheaders()
|
||||||
assert inside.read() == outside.read()
|
assert inside.read() == outside.read()
|
||||||
|
|
||||||
# Even though the above are raw bytes, the JSON data should have been
|
# Even though the above are raw bytes, the JSON data should have been
|
||||||
# decoded and saved to the cassette.
|
# decoded and saved to the cassette.
|
||||||
with vcr.use_cassette(testfile):
|
with vcr.use_cassette(testfile):
|
||||||
inside = urlopen(request)
|
conn = httplib.HTTPConnection(host, port)
|
||||||
|
conn.request('GET', '/gzip')
|
||||||
|
inside = conn.getresponse()
|
||||||
|
|
||||||
assert 'content-encoding' not in inside.headers
|
assert 'content-encoding' not in inside.headers
|
||||||
assert_is_json(inside.read())
|
assert_is_json(inside.read())
|
||||||
|
|||||||
Reference in New Issue
Block a user