Browse Source

test: simplify included route method check for coverage

pull/15356/head
Herrtian 1 month ago
parent
commit
2bfa699e60
  1. 24
      fastapi/routing.py

24
fastapi/routing.py

@ -1192,18 +1192,18 @@ class APIRoute(routing.Route):
effective_context = _get_scope_effective_route_context(scope) effective_context = _get_scope_effective_route_context(scope)
if effective_context is not None and effective_context.original_route is self: if effective_context is not None and effective_context.original_route is self:
methods = effective_context.methods methods = effective_context.methods
if methods and ( if methods:
scope["method"] not in methods method = scope["method"]
and not self._is_head_for_get(scope, methods) method_is_allowed = method in methods or self._is_head_for_get(scope, methods)
): if not method_is_allowed:
headers = {"Allow": ", ".join(self._allow_methods(methods))} headers = {"Allow": ", ".join(self._allow_methods(methods))}
if "app" in scope: if "app" in scope:
raise HTTPException(status_code=405, headers=headers) raise HTTPException(status_code=405, headers=headers)
response = PlainTextResponse( response = PlainTextResponse(
"Method Not Allowed", status_code=405, headers=headers "Method Not Allowed", status_code=405, headers=headers
) )
await response(scope, receive, send) await response(scope, receive, send)
return return
token = _effective_route_context_var.set(effective_context) token = _effective_route_context_var.set(effective_context)
try: try:
app = request_response(self.get_route_handler()) app = request_response(self.get_route_handler())

Loading…
Cancel
Save