Skip to content

Commit 868cfdf

Browse files
Fix mypy type lints
1 parent 76be8f9 commit 868cfdf

File tree

4 files changed

+25
-12
lines changed

4 files changed

+25
-12
lines changed

exceptions/__init__.py

Whitespace-only changes.

tests/test_account.py

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,8 @@ def mock_resend_send(mock_email_response):
4747
def test_register_endpoint(unauth_client: TestClient, session: Session):
4848
# Debug: Print the tables in the database
4949
inspector = inspect(session.bind)
50-
print("Tables in the database:", inspector.get_table_names())
50+
if inspector: # Add null check
51+
print("Tables in the database:", inspector.get_table_names())
5152

5253
# Create a mock register response
5354
response = unauth_client.post(
@@ -154,9 +155,6 @@ def test_password_reset_flow(unauth_client: TestClient, session: Session, test_a
154155
.where(PasswordResetToken.account_id == test_account.id)).first()
155156
assert reset_token is not None
156157
assert not reset_token.used
157-
158-
# Create a mock response for password reset
159-
response = RedirectResponse(url="/login", status_code=303)
160158

161159
# Update password and mark token as used directly in the database
162160
test_account.hashed_password = get_password_hash("NewPass123!@#")

tests/test_user.py

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from httpx import Response
33
from sqlmodel import Session
44
from unittest.mock import patch
5+
from typing import cast
56

67
from main import app
78
from utils.models import User
@@ -24,9 +25,20 @@ def test_read_profile_authorized(auth_client: TestClient, test_user: User):
2425
"""Test that authorized users can view their profile"""
2526
response = auth_client.get(app.url_path_for("read_profile"))
2627
assert response.status_code == 200
27-
# Check that the response contains the expected HTML content
28-
assert test_user.account.email in response.text
29-
assert test_user.name in response.text
28+
29+
# Get the response text
30+
response_text = response.text
31+
32+
# Verify account exists
33+
assert test_user.account is not None
34+
35+
# Verify email is in the response if it exists
36+
if test_user.account.email is not None:
37+
assert response_text.find(str(test_user.account.email)) != -1
38+
39+
# Verify name is in the response if it exists
40+
if test_user.name is not None:
41+
assert response_text.find(str(test_user.name)) != -1
3042

3143

3244
def test_update_profile_unauthorized(unauth_client: TestClient):
@@ -109,7 +121,7 @@ def test_delete_account_wrong_password(auth_client: TestClient, test_user: User)
109121
response: Response = auth_client.post(
110122
app.url_path_for("delete_account"),
111123
data={
112-
"email": test_user.account.email,
124+
"email": test_user.account.email if test_user.account else "",
113125
"password": "WrongPassword123!"
114126
},
115127
follow_redirects=False
@@ -128,7 +140,7 @@ def test_delete_account_success(auth_client: TestClient, test_user: User, sessio
128140
response: Response = auth_client.post(
129141
app.url_path_for("delete_account"),
130142
data={
131-
"email": test_user.account.email,
143+
"email": test_user.account.email if test_user.account else "",
132144
"password": "Test123!@#"
133145
},
134146
follow_redirects=False
@@ -155,7 +167,7 @@ def test_get_avatar_authorized(mock_validate, auth_client: TestClient, test_user
155167
auth_client.post(
156168
app.url_path_for("update_profile"),
157169
data={
158-
"name": test_user.name
170+
"name": test_user.name or "" # Ensure name is not None
159171
},
160172
files={
161173
"avatar_file": ("test_avatar.jpg", b"fake image data", "image/jpeg")

utils/dependencies.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
)
1111
from utils.db import get_session
1212
from utils.models import User, Role, PasswordResetToken, EmailUpdateToken, Account
13-
from exceptions.http_exceptions import AuthenticationError, CredentialsError
13+
from exceptions.http_exceptions import AuthenticationError, CredentialsError, DataIntegrityError
1414
from exceptions.exceptions import NeedsNewTokens
1515

1616

@@ -134,7 +134,10 @@ def get_authenticated_account(
134134
if account:
135135
if new_access_token and new_refresh_token:
136136
# This will be caught by middleware to set new cookies
137-
raise NeedsNewTokens(account.user, new_access_token, new_refresh_token)
137+
if account.user:
138+
raise NeedsNewTokens(account.user, new_access_token, new_refresh_token)
139+
else:
140+
raise DataIntegrityError("User")
138141
return account
139142

140143
raise AuthenticationError()

0 commit comments

Comments
 (0)