raise exception for _static_request_handler unknown exception; add test with custom error (#2195)

Co-authored-by: n.feofanov <n.feofanov@visionlabs.ru>
Co-authored-by: Adam Hopkins <admhpkns@gmail.com>
This commit is contained in:
gluhar2006 2021-07-19 09:23:02 +03:00 committed by GitHub
parent 1b8cb742f9
commit 7b7a572f9b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 17 additions and 0 deletions

View File

@ -781,6 +781,7 @@ class RouteMixin:
path={file_or_directory}, "
f"relative_url={__file_uri__}"
)
raise
def _register_static(
self,

View File

@ -461,6 +461,22 @@ def test_nested_dir(app, static_file_directory):
assert response.text == "foo\n"
def test_handle_is_a_directory_error(app, static_file_directory):
error_text = "Is a directory. Access denied"
app.static("/static", static_file_directory)
@app.exception(Exception)
async def handleStaticDirError(request, exception):
if isinstance(exception, IsADirectoryError):
return text(error_text, status=403)
raise exception
request, response = app.test_client.get("/static/")
assert response.status == 403
assert response.text == error_text
def test_stack_trace_on_not_found(app, static_file_directory, caplog):
app.static("/static", static_file_directory)