(monkeypatch, tmp_path: Path)
| 76 | |
| 77 | |
| 78 | def 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 | |
| 116 | def test_frontend_route_group_helpers(tmp_path: Path): |
nothing calls this directly
no test coverage detected
searching dependent graphs…