Browse Source

🔥 Remove dead code, adjust coverage

pull/15908/head
Sebastián Ramírez 3 weeks ago
parent
commit
191fff3114
  1. 7
      fastapi/routing.py
  2. 16
      tests/test_frontend.py

7
fastapi/routing.py

@ -1511,8 +1511,6 @@ class _EffectiveRouteContext:
return Match.FULL, child_scope
def url_path_for(self, name: str, /, **path_params: Any) -> Any:
if isinstance(self.original_route, _FrontendRouteGroup):
raise routing.NoMatchFound(name, path_params)
if not isinstance(self.original_route, APIRoute):
assert self.starlette_route is not None
return self.starlette_route.url_path_for(name, **path_params)
@ -2025,11 +2023,6 @@ class _FrontendRoute(BaseRoute):
directory=directory, fallback=fallback, check_dir=check_dir
)
def with_path(self, path: str) -> "_FrontendRoute":
route = copy.copy(self)
route.path = _normalize_frontend_path(path)
return route
def matches(self, scope: Scope) -> tuple[Match, Scope]:
return self.matches_with_path(scope, self.path)

16
tests/test_frontend.py

@ -132,6 +132,12 @@ def test_frontend_route_group_helpers(tmp_path: Path):
assert match == Match.FULL
assert child_scope["fastapi"]["frontend_path"] == ""
match, child_scope = route_group.routes[0].matches(
{"type": "http", "path": "/app", "method": "GET"}
)
assert match == Match.FULL
assert child_scope["fastapi"]["frontend_path"] == ""
with pytest.raises(StarletteHTTPException) as exc_info:
anyio.run(
route_group.handle,
@ -343,8 +349,18 @@ def test_included_frontend_does_not_block_url_path_for(tmp_path: Path):
app = FastAPI()
app.include_router(frontend_router, prefix="/app")
app.include_router(api_router)
included_frontend = next(
route
for route in app.router.routes
if hasattr(route, "effective_low_priority_routes")
)
with pytest.raises(NoMatchFound):
included_frontend.url_path_for("missing")
assert app.url_path_for("read_api") == "/api"
response = TestClient(app).get("/api")
assert response.status_code == 200
assert response.json() == {"ok": True}
def test_include_router_frontend_dependencies_apply_in_nested_order(tmp_path: Path):

Loading…
Cancel
Save