Browse Source

🎨 Auto format

pull/14711/head
pre-commit-ci-lite[bot] 6 months ago
committed by GitHub
parent
commit
aaf14a86ab
No known key found for this signature in database GPG Key ID: B5690EEEBB952194
  1. 6
      fastapi/dependencies/utils.py
  2. 4
      fastapi/security/http.py
  3. 6
      tests/test_security_http_base.py

6
fastapi/dependencies/utils.py

@ -5,7 +5,6 @@ from collections.abc import Coroutine, Mapping, Sequence
from contextlib import AsyncExitStack, contextmanager
from copy import copy, deepcopy
from dataclasses import dataclass
from typing import get_type_hints
from typing import (
Annotated,
Any,
@ -14,6 +13,7 @@ from typing import (
Optional,
Union,
cast,
get_type_hints,
)
import anyio
@ -284,7 +284,7 @@ def get_dependant(
for param_name, param in signature_params.items():
annotation = param.annotation
# Resolve ForwardRef inside Annotated without destroying metadata
if get_origin(annotation) is Annotated:
args = list(get_args(annotation))
@ -294,7 +294,7 @@ def get_dependant(
args[0] = inner
annotation = Annotated[inner, *args[1:]]
param = param.replace(annotation=annotation)
is_path_param = param_name in path_param_names
param_details = analyze_param(
param_name=param_name,

4
fastapi/security/http.py

@ -145,15 +145,13 @@ class HTTPBasic(HTTPBase):
scheme_name: Optional[str] = None,
description: Optional[str] = None,
auto_error: bool = True,
):
):
self.model = HTTPBaseModel(scheme="basic", description=description)
self.scheme_name = scheme_name or self.__class__.__name__
self.auto_error = auto_error
def make_authenticate_headers(self) -> dict[str, str]:
return {"WWW-Authenticate": "Basic"}
async def __call__( # type: ignore
self, request: Request

6
tests/test_security_http_base.py

@ -1,7 +1,7 @@
from fastapi import FastAPI, Security, Depends
from fastapi import Depends, FastAPI, Security
from fastapi.security import HTTPBasic
from fastapi.security.http import HTTPAuthorizationCredentials, HTTPBase
from fastapi.testclient import TestClient
from fastapi.security import HTTPBasic
app = FastAPI()
@ -55,6 +55,7 @@ def test_openapi_schema():
},
}
def test_http_basic_includes_realm():
app = FastAPI()
security = HTTPBasic(realm="MyRealm")
@ -68,4 +69,3 @@ def test_http_basic_includes_realm():
assert response.status_code == 401
assert response.headers["WWW-Authenticate"] == 'Basic realm="MyRealm"'
Loading…
Cancel
Save