Merge pull request #1054 from r0fls/rfc7231

fix issues with method not allowed response
This commit is contained in:
Raphael Deem
2017-12-13 23:42:37 -08:00
committed by GitHub
4 changed files with 47 additions and 10 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))