Skip to content

Commit 71affa9

Browse files
committed
Fix lint errors
1 parent fd789a6 commit 71affa9

File tree

9 files changed

+65
-13
lines changed

9 files changed

+65
-13
lines changed

backend/.idea/.gitignore

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.idea/backend.iml

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.idea/inspectionProfiles/profiles_settings.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.idea/misc.xml

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.idea/modules.xml

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

backend/app/core/security.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
from typing import Any
33

44
import jwt
5-
from fastapi import Response
65
from fastapi.responses import JSONResponse
76
from passlib.context import CryptContext
87

@@ -20,7 +19,7 @@ def create_access_token(subject: str | Any, expires_delta: timedelta) -> str:
2019
return encoded_jwt
2120

2221

23-
def set_auth_cookie(subject: str | Any, expires_delta: timedelta) -> Response:
22+
def set_auth_cookie(subject: str | Any, expires_delta: timedelta) -> JSONResponse:
2423
access_token = create_access_token(subject, expires_delta)
2524
response = JSONResponse(content={"message": "Login successful"})
2625
# Note: The secure flag on cookies ensures they're only sent over encrypted HTTPS connections. For local development (HTTP) set it to False
@@ -37,7 +36,7 @@ def set_auth_cookie(subject: str | Any, expires_delta: timedelta) -> Response:
3736
return response
3837

3938

40-
def delete_auth_cookie() -> Response:
39+
def delete_auth_cookie() -> JSONResponse:
4140
response = JSONResponse(content={"message": "Logout successful"})
4241

4342
response.delete_cookie(

backend/app/tests/utils/user.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def user_authentication_headers(
1313
data = {"username": email, "password": password}
1414

1515
r = client.post(f"{settings.API_V1_STR}/login/access-token", data=data)
16+
print(f"user_authentication_headers: {r}")
1617
return extract_cookies(r)
1718

1819

backend/app/tests/utils/utils.py

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import random
22
import string
33

4+
import httpx
5+
from fastapi import Response
46
from fastapi.responses import JSONResponse
57
from fastapi.testclient import TestClient
68

@@ -24,13 +26,22 @@ def get_superuser_auth_cookies(client: TestClient) -> dict[str, str]:
2426
return extract_cookies(r)
2527

2628

27-
def extract_cookies(response: JSONResponse) -> dict[str, str]:
28-
cookie_header = response.headers.get("Set-Cookie")
29-
30-
cookie_value = None
31-
if cookie_header and "http_only_auth_cookie=" in cookie_header:
32-
cookie_value = cookie_header.split("http_only_auth_cookie=")[1].split(";")[0]
33-
34-
assert cookie_value, "Cookie value not found"
35-
36-
return {"http_only_auth_cookie": cookie_value}
29+
def extract_cookies(
30+
response: JSONResponse | httpx._models.Response | Response,
31+
) -> dict[str, str]:
32+
if isinstance(response, httpx._models.Response):
33+
# Handle httpx Response
34+
cookie_value = response.cookies.get("http_only_auth_cookie")
35+
if cookie_value:
36+
return {"http_only_auth_cookie": cookie_value}
37+
else:
38+
# Handle Starlette Response
39+
cookie_header = response.headers.get("Set-Cookie")
40+
if cookie_header and "http_only_auth_cookie=" in cookie_header:
41+
cookie_value = cookie_header.split("http_only_auth_cookie=")[1].split(";")[
42+
0
43+
]
44+
if cookie_value:
45+
return {"http_only_auth_cookie": cookie_value}
46+
47+
raise AssertionError("Cookie value not found")

0 commit comments

Comments
 (0)