Skip to content

Commit

Permalink
properly implement precompressed body tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Nikolay Kim committed Feb 1, 2017
1 parent 3ef3d09 commit 3e1b194
Showing 1 changed file with 26 additions and 4 deletions.
30 changes: 26 additions & 4 deletions tests/test_web_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -763,14 +763,36 @@ def handler(request):
assert 200 == resp.status


@pytest.mark.xfail # and had never worked
@asyncio.coroutine
def test_response_with_precompressed_body(loop, test_client):
def test_response_with_precompressed_body_gzip(loop, test_client):

@asyncio.coroutine
def handler(request):
headers = {'Content-Encoding': 'gzip'}
deflated_data = zlib.compress(b'mydata')
return web.Response(body=deflated_data, headers=headers)
zcomp = zlib.compressobj(wbits=16 + zlib.MAX_WBITS)
data = zcomp.compress(b'mydata') + zcomp.flush()
return web.Response(body=data, headers=headers)

app = web.Application(loop=loop)
app.router.add_get('/', handler)
client = yield from test_client(app)

resp = yield from client.get('/')
assert 200 == resp.status
data = yield from resp.read()
assert b'mydata' == data
assert resp.headers.get('Content-Encoding') == 'gzip'


@asyncio.coroutine
def test_response_with_precompressed_body_deflate(loop, test_client):

@asyncio.coroutine
def handler(request):
headers = {'Content-Encoding': 'deflate'}
zcomp = zlib.compressobj(wbits=-zlib.MAX_WBITS)
data = zcomp.compress(b'mydata') + zcomp.flush()
return web.Response(body=data, headers=headers)

app = web.Application(loop=loop)
app.router.add_get('/', handler)
Expand Down

0 comments on commit 3e1b194

Please sign in to comment.