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,34 +64,16 @@ def test_request_stream_100_continue(app):
|
|||
|
||||
assert app.is_request_stream is True
|
||||
|
||||
request, response = app.test_client.post("/method_view", data=data, headers={"EXPECT": "100-continue"})
|
||||
assert response.status == 200
|
||||
assert response.text == data
|
||||
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
|
||||
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)
|
||||
|
||||
|
||||
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
|
||||
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):
|
||||
"""for self.is_request_stream = True and decorators"""
|
||||
|
||||
|
|
Loading…
Reference in New Issue
Block a user