sanic/tests/test_payload_too_large.py

46 lines
1.2 KiB
Python
Raw Normal View History

from sanic.exceptions import PayloadTooLarge
from sanic.response import text
2018-08-26 15:43:14 +01:00
def test_payload_too_large_from_error_handler(app):
app.config.REQUEST_MAX_SIZE = 1
2018-08-26 15:43:14 +01:00
@app.route('/1')
2017-03-29 04:38:45 +01:00
async def handler1(request):
return text('OK')
2018-08-26 15:43:14 +01:00
@app.exception(PayloadTooLarge)
2017-03-29 04:38:45 +01:00
def handler_exception(request, exception):
return text('Payload Too Large from error_handler.', 413)
2018-08-26 15:43:14 +01:00
response = app.test_client.get('/1', gather_request=False)
assert response.status == 413
assert response.text == 'Payload Too Large from error_handler.'
2018-08-26 15:43:14 +01:00
def test_payload_too_large_at_data_received_default(app):
app.config.REQUEST_MAX_SIZE = 1
2018-08-26 15:43:14 +01:00
@app.route('/1')
2017-03-29 04:38:45 +01:00
async def handler2(request):
return text('OK')
2018-08-26 15:43:14 +01:00
response = app.test_client.get(
2017-02-14 19:51:20 +00:00
'/1', gather_request=False)
assert response.status == 413
assert response.text == 'Error: Payload Too Large'
2018-08-26 15:43:14 +01:00
def test_payload_too_large_at_on_header_default(app):
app.config.REQUEST_MAX_SIZE = 500
2018-08-26 15:43:14 +01:00
@app.post('/1')
2017-03-29 04:38:45 +01:00
async def handler3(request):
return text('OK')
data = 'a' * 1000
2018-08-26 15:43:14 +01:00
response = app.test_client.post(
2017-02-14 19:51:20 +00:00
'/1', gather_request=False, data=data)
assert response.status == 413
assert response.text == 'Error: Payload Too Large'