def test_recording_gzipped_responses_as_text(vts_rec_on, httpserver):
data = "Hello!"
# http://stackoverflow.com/a/22310760
gzip_compressor = zlib.compressobj(9, zlib.DEFLATED, zlib.MAX_WBITS | 16)
gzipped = gzip_compressor.compress(data.encode()) + gzip_compressor.flush()
httpserver.serve_content(
gzipped, 200,
headers={"Content-Encoding": "gzip"})
url = "{}/".format(httpserver.url)
resp = requests.get(url)
assert resp.status_code == 200
assert resp.text == data
assert len(vts_rec_on.cassette) == 1
track = vts_rec_on.cassette[0]
assert track['request']['url'] == url
assert "Content-Encoding" in track['response']['headers']
assert track['response']['body'] == data
# enable pytester fixture which allows running pytests within tests
评论列表
文章目录