def test__abs_headerlist_location_no_scheme(): res = Response() res.content_encoding = 'gzip' res.headerlist = [('Location', '/abc')] result = res._abs_headerlist({'wsgi.url_scheme': 'http', 'HTTP_HOST': 'example.com:80'}) assert result == [('Location', 'http://example.com/abc')]
def test_decode_content_with_deflate(): res = Response() body = b"Hey Hey Hey" # Simulate inflate by chopping the headers off # the gzip encoded data res.body = zlib.compress(body)[2:-4] res.content_encoding = "deflate" res.decode_content() eq_(res.body, body) eq_(res.content_encoding, None)
def test_decode_content_with_deflate(): res = Response() body = b'Hey Hey Hey' # Simulate inflate by chopping the headers off # the gzip encoded data res.body = zlib.compress(body)[2:-4] res.content_encoding = 'deflate' res.decode_content() assert res.body == body assert res.content_encoding is None
def test_decode_content_with_deflate_and_zlib_header(): res = Response() body = b"Hey Hey Hey" # don't chop off the zlib container # https://tools.ietf.org/html/rfc7230#section-4.2.2 says # that chopping it exists but is non-conformant res.body = zlib.compress(body) res.content_encoding = "deflate" res.decode_content() assert res.body == body assert res.content_encoding is None
def test_decode_content_gzip(): from gzip import GzipFile io_ = io.BytesIO() gzip_f = GzipFile(filename='', mode='w', fileobj=io_) gzip_f.write(b'abc') gzip_f.close() body = io_.getvalue() res = Response() res.content_encoding = 'gzip' res.body = body res.decode_content() assert res.body == b'abc'
def test_decode_content_gzip(): from gzip import GzipFile io_ = io.BytesIO() gzip_f = GzipFile(filename="", mode="w", fileobj=io_) gzip_f.write(b"abc") gzip_f.close() body = io_.getvalue() res = Response() res.content_encoding = "gzip" res.body = body res.decode_content() assert res.body == b"abc"
def test_decode_content_gzip(): from gzip import GzipFile io_ = io.BytesIO() gzip_f = GzipFile(filename="", mode="w", fileobj=io_) gzip_f.write(b"abc") gzip_f.close() body = io_.getvalue() res = Response() res.content_encoding = "gzip" res.body = body res.decode_content() assert res.body == b"abc"
def test_decode_content_weird(): res = Response() res.content_encoding = 'weird' with pytest.raises(ValueError): res.decode_content()
def test_decode_content_identity(): res = Response() res.content_encoding = 'identity' result = res.decode_content() assert result is None
def test_encode_content_gzip_already_gzipped(): res = Response() res.content_encoding = 'gzip' result = res.encode_content('gzip') assert result is None
def test_decode_content_weird(): res = Response() res.content_encoding = 'weird' assert_raises(ValueError, res.decode_content)
def test__abs_headerlist_location_no_scheme(): res = Response() res.content_encoding = "gzip" res.headerlist = [("Location", "/abc")] result = res._abs_headerlist({"wsgi.url_scheme": "http", "HTTP_HOST": "example.com:80"}) eq_(result, [("Location", "http://example.com/abc")])
def test_encode_content_gzip_already_gzipped(): res = Response() res.content_encoding = 'gzip' result = res.encode_content('gzip') eq_(result, None)
def test_decode_content_weird(): res = Response() res.content_encoding = 'weird' assert_raises(ValueError, res.decode_content)
def test_decode_content_identity(): res = Response() res.content_encoding = 'identity' result = res.decode_content() eq_(result, None)
def test__abs_headerlist_location_with_scheme(): res = Response() res.content_encoding = 'gzip' res.headerlist = [('Location', 'http:')] result = res._abs_headerlist({}) assert result, [('Location' == 'http:')]
def test_encode_content_gzip_already_gzipped(): res = Response() res.content_encoding = 'gzip' result = res.encode_content('gzip') eq_(result, None)
def test_decode_content_identity(): res = Response() res.content_encoding = 'identity' result = res.decode_content() eq_(result, None)
def test__abs_headerlist_location_with_scheme(): res = Response() res.content_encoding = "gzip" res.headerlist = [("Location", "http:")] result = res._abs_headerlist({}) eq_(result, [("Location", "http:")])