MCPcopy Index your code
hub / github.com/fastapi/fastapi / test_frontend_static_files_lookup_errors

Function test_frontend_static_files_lookup_errors

tests/test_frontend.py:78–113  ·  view source on GitHub ↗
(monkeypatch, tmp_path: Path)

Source from the content-addressed store, hash-verified

76
77
78def test_frontend_static_files_lookup_errors(monkeypatch, tmp_path: Path):
79 dist = tmp_path / "dist"
80 write_file(dist / "index.html", "app")
81 app = FastAPI()
82 app.frontend("/", directory=dist)
83 frontend_routes = app.router._frontend_routes
84 assert frontend_routes is not None
85 static_files = frontend_routes.routes[0].app
86
87 def raise_permission_error(path: str):
88 raise PermissionError
89
90 monkeypatch.setattr(static_files, "lookup_path", raise_permission_error)
91 response = TestClient(app).get("/asset.txt")
92 assert response.status_code == 401
93
94 def raise_value_error(path: str):
95 raise ValueError
96
97 monkeypatch.setattr(static_files, "lookup_path", raise_value_error)
98 response = TestClient(app).get("/asset.txt")
99 assert response.status_code == 404
100
101 def raise_name_too_long(path: str):
102 raise OSError(errno.ENAMETOOLONG, "name too long")
103
104 monkeypatch.setattr(static_files, "lookup_path", raise_name_too_long)
105 response = TestClient(app).get("/asset.txt")
106 assert response.status_code == 404
107
108 def raise_os_error(path: str):
109 raise OSError(5, "other")
110
111 monkeypatch.setattr(static_files, "lookup_path", raise_os_error)
112 with pytest.raises(OSError):
113 TestClient(app).get("/asset.txt")
114
115
116def test_frontend_route_group_helpers(tmp_path: Path):

Callers

nothing calls this directly

Calls 4

frontendMethod · 0.95
FastAPIClass · 0.90
write_fileFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…