Merge pull request 'fix exception when file does not exist' (#507) from Mic92-sops-nix into main
This commit is contained in:
@@ -30,6 +30,8 @@ async def root(path_name: str) -> Response:
|
|||||||
if not filename.is_file():
|
if not filename.is_file():
|
||||||
log.error("File not found: %s", filename)
|
log.error("File not found: %s", filename)
|
||||||
return Response(status_code=404)
|
return Response(status_code=404)
|
||||||
|
else:
|
||||||
|
return Response(status_code=404)
|
||||||
|
|
||||||
content_type, _ = guess_type(filename)
|
content_type, _ = guess_type(filename)
|
||||||
return Response(filename.read_bytes(), media_type=content_type)
|
return Response(filename.read_bytes(), media_type=content_type)
|
||||||
|
|||||||
10
pkgs/clan-cli/tests/test_static_files.py
Normal file
10
pkgs/clan-cli/tests/test_static_files.py
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import pytest
|
||||||
|
from api import TestClient
|
||||||
|
|
||||||
|
|
||||||
|
@pytest.mark.impure
|
||||||
|
def test_static_files(api: TestClient) -> None:
|
||||||
|
response = api.get("/")
|
||||||
|
assert response.headers["content-type"] == "text/html; charset=utf-8"
|
||||||
|
response = api.get("/does-no-exists.txt")
|
||||||
|
assert response.status_code == 404
|
||||||
Reference in New Issue
Block a user