fix issues with method not allowed response

This commit is contained in:
Raphael Deem
2017-12-11 20:11:20 -08:00
parent 969dac2033
commit 2b0258c13a
4 changed files with 45 additions and 5 deletions

View File

@@ -35,6 +35,25 @@ async def sample_streaming_fn(response):
await asyncio.sleep(.001)
response.write('bar')
def test_method_not_allowed():
app = Sanic('method_not_allowed')
@app.get('/')
async def test(request):
return response.json({'hello': 'world'})
request, response = app.test_client.head('/')
assert response.headers['Allow']== 'GET'
@app.post('/')
async def test(request):
return response.json({'hello': 'world'})
request, response = app.test_client.head('/')
assert response.status == 405
assert set(response.headers['Allow'].split(', ')) == set(['GET', 'POST'])
assert response.headers['Content-Length'] == '0'
@pytest.fixture
def json_app():
@@ -254,4 +273,4 @@ def test_file_stream_head_response(file_name, static_file_directory):
assert 'Content-Length' in response.headers
assert int(response.headers[
'Content-Length']) == len(
get_file_content(static_file_directory, file_name))
get_file_content(static_file_directory, file_name))