minor: address pr feedbacks, small refactoring and fix
This commit is contained in:
parent
2631f10c5e
commit
39d134994d
|
@ -340,7 +340,7 @@ class HttpProtocol(asyncio.Protocol):
|
|||
else:
|
||||
self.write_error(
|
||||
HeaderExpectationFailed(
|
||||
"Unknow Expect: {expect}".format(expect=expect)
|
||||
"Unknown Expect: {expect}".format(expect=expect)
|
||||
)
|
||||
)
|
||||
|
||||
|
|
|
@ -42,8 +42,11 @@ def test_request_stream_method_view(app):
|
|||
assert response.text == data
|
||||
|
||||
|
||||
def test_request_stream_100_continue(app):
|
||||
|
||||
@pytest.mark.parametrize("headers, expect_raise_exception", [
|
||||
({"EXPECT": "100-continue"}, False),
|
||||
({"EXPECT": "100-continue-extra"}, True),
|
||||
])
|
||||
def test_request_stream_100_continue(app, headers, expect_raise_exception):
|
||||
class SimpleView(HTTPMethodView):
|
||||
|
||||
@stream_decorator
|
||||
|
@ -61,29 +64,11 @@ def test_request_stream_100_continue(app):
|
|||
|
||||
assert app.is_request_stream is True
|
||||
|
||||
if not expect_raise_exception:
|
||||
request, response = app.test_client.post("/method_view", data=data, headers={"EXPECT": "100-continue"})
|
||||
assert response.status == 200
|
||||
assert response.text == data
|
||||
|
||||
|
||||
def test_request_stream_100_continue_raise_HeaderExpectationFailed(app):
|
||||
|
||||
class SimpleView(HTTPMethodView):
|
||||
|
||||
@stream_decorator
|
||||
async def post(self, request):
|
||||
assert isinstance(request.stream, StreamBuffer)
|
||||
result = ""
|
||||
while True:
|
||||
body = await request.stream.read()
|
||||
if body is None:
|
||||
break
|
||||
result += body.decode("utf-8")
|
||||
return text(result)
|
||||
|
||||
app.add_route(SimpleView.as_view(), "/method_view")
|
||||
|
||||
assert app.is_request_stream is True
|
||||
else:
|
||||
with pytest.raises(ValueError) as e:
|
||||
app.test_client.post("/method_view", data=data, headers={"EXPECT": "100-continue-extra"})
|
||||
assert "Unknow Expect: 100-continue-extra" in str(e)
|
||||
|
|
Loading…
Reference in New Issue
Block a user