fix:routen2
This commit is contained in:
1 parent
90fbbffc20
commit
f18298d07f
2 files changed
+24
-8
No files matched your search
@@ -155,7 +155,8 @@ def test_edit_and_delete_with_personal_link(app: Any) -> None:
|
|||||||
csrf = token_for(first, f"{link}/edit")
|
csrf = token_for(first, f"{link}/edit")
|
||||||
resp = first.post(f"{link}/edit", data={"csrf_token": csrf, f"q{qid}": late})
|
resp = first.post(f"{link}/edit", data={"csrf_token": csrf, f"q{qid}": late})
|
||||||
assert resp.status_code == 303 and resp.headers["location"].endswith("?done=saved")
|
assert resp.status_code == 303 and resp.headers["location"].endswith("?done=saved")
|
||||||
assert sorted(b[:2] for b in bookings(qid)) == [(early, "confirmed"), (late, "confirmed")]
|
assert sorted(b[:2] for b in bookings(qid)) == sorted([(early, "confirmed"),
|
||||||
|
(late, "confirmed")])
|
||||||
# Löschen braucht die Bestätigung
|
# Löschen braucht die Bestätigung
|
||||||
csrf = token_for(first, link)
|
csrf = token_for(first, link)
|
||||||
assert first.post(f"{link}/delete", data={"csrf_token": csrf}).status_code == 400
|
assert first.post(f"{link}/delete", data={"csrf_token": csrf}).status_code == 400
|
||||||
|
|||||||
@@ -34,12 +34,22 @@ PROTECTED_PREFIXES = ("/admin", "/forms", "/account")
|
|||||||
DUMMY_ID = "00000000-0000-0000-0000-000000000000"
|
DUMMY_ID = "00000000-0000-0000-0000-000000000000"
|
||||||
|
|
||||||
|
|
||||||
|
def _get(obj: Any, name: str) -> Any:
|
||||||
|
"""Attribut oder Schlüssel (Einbindungs-Kontext kann beides sein)."""
|
||||||
|
if isinstance(obj, dict):
|
||||||
|
return obj.get(name)
|
||||||
|
return getattr(obj, name, None)
|
||||||
|
|
||||||
|
|
||||||
def _dep_calls(obj: Any) -> set[Any]:
|
def _dep_calls(obj: Any) -> set[Any]:
|
||||||
"""Abhängigkeiten eines Endpunkts oder Routers (Depends(...) und aufgelöster Baum)."""
|
"""Abhängigkeiten eines Endpunkts oder Routers (Depends(...) und aufgelöster Baum),
|
||||||
|
auch aus dem Einbindungs-Kontext (FastAPI ab 0.16x: include_router(dependencies=...))."""
|
||||||
calls: set[Any] = set()
|
calls: set[Any] = set()
|
||||||
for dep in getattr(obj, "dependencies", None) or ():
|
for holder in (obj, _get(obj, "include_context")):
|
||||||
if getattr(dep, "dependency", None) is not None:
|
for dep in _get(holder, "dependencies") or () if holder is not None else ():
|
||||||
calls.add(dep.dependency)
|
for name in ("dependency", "call"):
|
||||||
|
if getattr(dep, name, None) is not None:
|
||||||
|
calls.add(getattr(dep, name))
|
||||||
todo = [getattr(obj, "dependant", None)]
|
todo = [getattr(obj, "dependant", None)]
|
||||||
while todo:
|
while todo:
|
||||||
node = todo.pop()
|
node = todo.pop()
|
||||||
@@ -56,6 +66,10 @@ def _is_endpoint(obj: Any) -> bool:
|
|||||||
return bool(getattr(obj, "methods", None)) and isinstance(getattr(obj, "path", None), str)
|
return bool(getattr(obj, "methods", None)) and isinstance(getattr(obj, "path", None), str)
|
||||||
|
|
||||||
|
|
||||||
|
def _is_routing(obj: Any) -> bool:
|
||||||
|
return any(hasattr(obj, name) for name in ("path", "routes", "original_router"))
|
||||||
|
|
||||||
|
|
||||||
def _children(obj: Any) -> list[Any]:
|
def _children(obj: Any) -> list[Any]:
|
||||||
"""Untergeordnete Routen/Router, ohne sich auf eine bestimmte FastAPI-Version zu verlassen."""
|
"""Untergeordnete Routen/Router, ohne sich auf eine bestimmte FastAPI-Version zu verlassen."""
|
||||||
found: list[Any] = []
|
found: list[Any] = []
|
||||||
@@ -67,8 +81,8 @@ def _children(obj: Any) -> list[Any]:
|
|||||||
"original_router"))
|
"original_router"))
|
||||||
for value in values:
|
for value in values:
|
||||||
if isinstance(value, (list, tuple)):
|
if isinstance(value, (list, tuple)):
|
||||||
found.extend(v for v in value if hasattr(v, "path") or hasattr(v, "routes"))
|
found.extend(v for v in value if _is_routing(v))
|
||||||
elif value is not None and (hasattr(value, "routes") or _is_endpoint(value)):
|
elif value is not None and (_is_routing(value) and not isinstance(value, str)):
|
||||||
found.append(value)
|
found.append(value)
|
||||||
return found
|
return found
|
||||||
|
|
||||||
@@ -83,7 +97,8 @@ def _routes(app: Any) -> list[tuple[str, Any, set[Any]]]:
|
|||||||
if depth > 8 or id(obj) in seen:
|
if depth > 8 or id(obj) in seen:
|
||||||
return
|
return
|
||||||
seen.add(id(obj))
|
seen.add(id(obj))
|
||||||
own = getattr(obj, "prefix", None) or ""
|
own = getattr(obj, "prefix", None) or _get(_get(obj, "include_context"), "prefix") or ""
|
||||||
|
own = own if isinstance(own, str) else ""
|
||||||
if not _is_endpoint(obj) and not own and hasattr(obj, "routes"):
|
if not _is_endpoint(obj) and not own and hasattr(obj, "routes"):
|
||||||
own = getattr(obj, "path", "") or "" # Mount
|
own = getattr(obj, "path", "") or "" # Mount
|
||||||
if own and not own.startswith(prefix or "\0"):
|
if own and not own.startswith(prefix or "\0"):
|
||||||
|
|||||||
Reference in new issue
Block a user