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:
|
else:
|
||||||
self.write_error(
|
self.write_error(
|
||||||
HeaderExpectationFailed(
|
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
|
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):
|
class SimpleView(HTTPMethodView):
|
||||||
|
|
||||||
@stream_decorator
|
@stream_decorator
|
||||||
|
@ -61,32 +64,14 @@ def test_request_stream_100_continue(app):
|
||||||
|
|
||||||
assert app.is_request_stream is True
|
assert app.is_request_stream is True
|
||||||
|
|
||||||
request, response = app.test_client.post("/method_view", data=data, headers={"EXPECT": "100-continue"})
|
if not expect_raise_exception:
|
||||||
assert response.status == 200
|
request, response = app.test_client.post("/method_view", data=data, headers={"EXPECT": "100-continue"})
|
||||||
assert response.text == data
|
assert response.status == 200
|
||||||
|
assert response.text == data
|
||||||
|
else:
|
||||||
def test_request_stream_100_continue_raise_HeaderExpectationFailed(app):
|
with pytest.raises(ValueError) as e:
|
||||||
|
app.test_client.post("/method_view", data=data, headers={"EXPECT": "100-continue-extra"})
|
||||||
class SimpleView(HTTPMethodView):
|
assert "Unknow Expect: 100-continue-extra" in str(e)
|
||||||
|
|
||||||
@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
|
|
||||||
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)
|
|
||||||
|
|
||||||
|
|
||||||
def test_request_stream_app(app):
|
def test_request_stream_app(app):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user