Skip to content

Commit

Permalink
(test) Add test for "Expect" header handling
Browse files Browse the repository at this point in the history
  • Loading branch information
akubera committed Mar 8, 2020
1 parent 7371694 commit 5492466
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions tests/test_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -476,6 +476,35 @@ async def test_handle_client_request_get(app, req, res, middlewares, called, moc
assert m1.called is called


@pytest.mark.asyncio
async def test_handle_header_expect(mock_transport):
from asyncio import sleep
from growler.aio import GrowlerHTTPProtocol

app = Application(__name__)

payload = b'123abc'
http_req = ("POST / HTTP/1.1\nHost: test\nExpect: 100-continue\n"
f"content-length: {len(payload)}\n\n").encode() + payload

protocol = GrowlerHTTPProtocol(app)
protocol.connection_made(mock_transport)

responder = protocol.responders[0]
protocol.data_received(http_req)
req = responder.req
res = responder.res

assert 'EXPECT' in req.headers
assert not res.has_sent_continue

# allow event loop to move to app.handle_client_request
await sleep(0)

assert res.has_sent_continue
assert mock_transport.write.mock_calls[0] == mock.call(b'HTTP/1.1 100 Continue\r\n\r\n')


@pytest.mark.asyncio
async def test_middleware_stops_with_stop_iteration(app, req, res):
async def do_something(req, res):
Expand Down

0 comments on commit 5492466

Please sign in to comment.