예제 #1
0
    def test_decode_brotli(self):
        data = brotli.compress(b"foo")

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={"content-encoding": "br"})
        r.preload_content()
        assert r.data == b"foo"
예제 #2
0
    def test_io(self):
        fp = BytesIO(b"foo")
        resp = HTTPResponse(fp)

        assert not resp.closed
        assert resp.readable()
        assert not resp.writable()
        with pytest.raises(IOError):
            resp.fileno()

        resp.close()
        assert resp.closed

        # Try closing with a base Response
        hlr = get_response()
        resp2 = HTTPResponse(hlr.body)
        assert not resp2.closed
        resp2.close()
        assert resp2.closed

        # also try when only data is present.
        resp3 = HTTPResponse("foodata")
        resp3.preload_content()
        with pytest.raises(IOError):
            resp3.fileno()
예제 #3
0
    def test_preload(self):
        fp = BytesIO(b"foo")

        r = HTTPResponse(fp)
        r.preload_content()

        assert fp.tell() == len(b"foo")
        assert r.data == b"foo"
예제 #4
0
    def test_multi_decoding_deflate_deflate(self):
        data = zlib.compress(zlib.compress(b"foo"))

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={"content-encoding": "deflate, deflate"})
        r.preload_content()

        assert r.data == b"foo"
예제 #5
0
    def test_decode_deflate_case_insensitve(self):
        data = zlib.compress(b"foo")

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={"content-encoding": "DeFlAtE"})
        r.preload_content()

        assert r.data == b"foo"
예제 #6
0
    def test_multi_decoding_deflate_gzip(self):
        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
        data = compress.compress(zlib.compress(b"foo"))
        data += compress.flush()

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={"content-encoding": "deflate, gzip"})
        r.preload_content()

        assert r.data == b"foo"
예제 #7
0
    def test_chunked_decoding_gzip_swallow_garbage(self):
        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
        data = compress.compress(b"foo")
        data += compress.flush()
        data = data * 3 + b"foo"

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={"content-encoding": "gzip"})
        r.preload_content()

        assert r.data == b"foofoofoo"
예제 #8
0
    def test_decode_gzip_multi_member(self):
        compress = zlib.compressobj(6, zlib.DEFLATED, 16 + zlib.MAX_WBITS)
        data = compress.compress(b"foo")
        data += compress.flush()
        data = data * 3

        fp = BytesIO(data)
        r = HTTPResponse(fp, headers={"content-encoding": "gzip"})
        r.preload_content()

        assert r.data == b"foofoofoo"
예제 #9
0
 def test_decode_bad_data(self):
     fp = BytesIO(b"\x00" * 10)
     with pytest.raises(DecodeError):
         r = HTTPResponse(fp, headers={"content-encoding": "deflate"})
         r.preload_content()
예제 #10
0
 def test_none(self):
     r = HTTPResponse(None)
     r.preload_content()
     assert r.data == b""
예제 #11
0
 def test_default(self):
     r = HTTPResponse()
     r.preload_content()
     assert r.data == b""
예제 #12
0
 def test_body_blob(self):
     resp = HTTPResponse(b"foo")
     resp.preload_content()
     assert resp.data == b"foo"
     assert resp.closed
예제 #13
0
 def test_decode_brotli_error(self):
     fp = BytesIO(b"foo")
     with pytest.raises(DecodeError):
         r = HTTPResponse(fp, headers={"content-encoding": "br"})
         r.preload_content()