Skip to content

Commit 497ee78

Browse files
committed
Removed Dev comments
1 parent 5078d2d commit 497ee78

File tree

9 files changed

+12
-21
lines changed

9 files changed

+12
-21
lines changed

src/app/api/dependencies.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,9 @@ async def get_current_user(
3434
user = await crud_users.get(db=db, username=token_data.username_or_email, is_deleted=False)
3535

3636
if user:
37-
# Ensure consistent return type - always return dict
38-
if hasattr(user, 'model_dump'): # It's a Pydantic model
37+
if hasattr(user, 'model_dump'):
3938
return user.model_dump()
40-
else: # It's already a dict
39+
else:
4140
return user
4241

4342
raise UnauthorizedException("User not authenticated.")

src/app/api/v1/posts.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
from typing import Annotated, Any, cast
2-
32
from fastapi import APIRouter, Depends, Request
43
from fastcrud.paginated import PaginatedListResponse, compute_offset, paginated_response
54
from sqlalchemy.ext.asyncio import AsyncSession

src/app/api/v1/users.py

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ async def read_user(request: Request, username: str, db: Annotated[AsyncSession,
7272
return cast(UserRead, db_user)
7373

7474

75-
# In src/app/api/v1/users.py, replace the patch_user function with this:
7675

7776
@router.patch("/user/{username}")
7877
async def patch_user(
@@ -86,7 +85,6 @@ async def patch_user(
8685
if db_user is None:
8786
raise NotFoundException("User not found")
8887

89-
# Handle both dict and UserRead object types
9088
if isinstance(db_user, dict):
9189
db_username = db_user["username"]
9290
db_email = db_user["email"]
@@ -97,17 +95,14 @@ async def patch_user(
9795
if db_username != current_user["username"]:
9896
raise ForbiddenException()
9997

100-
# Check for email conflicts if email is being updated
10198
if values.email is not None and values.email != db_email:
10299
if await crud_users.exists(db=db, email=values.email):
103100
raise DuplicateValueException("Email is already registered")
104-
105-
# Check for username conflicts if username is being updated
101+
106102
if values.username is not None and values.username != db_username:
107103
if await crud_users.exists(db=db, username=values.username):
108104
raise DuplicateValueException("Username not available")
109105

110-
# Update the user
111106
await crud_users.update(db=db, object=values, username=username)
112107
return {"message": "User updated"}
113108

src/app/core/db/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uuid as uuid_pkg
2-
from uuid6 import uuid7 #126
2+
from uuid6 import uuid7
33
from datetime import UTC, datetime
44

55
from sqlalchemy import Boolean, DateTime, text

src/app/core/schemas.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import uuid as uuid_pkg
2-
from uuid6 import uuid7 #126
2+
from uuid6 import uuid7
33
from datetime import UTC, datetime
44
from typing import Any
55

src/app/core/utils/cache.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -174,12 +174,12 @@ async def _delete_keys_by_pattern(pattern: str) -> None:
174174
if client is None:
175175
return
176176

177-
cursor = 0 # Make sure cursor starts at 0
177+
cursor = 0
178178
while True:
179179
cursor, keys = await client.scan(cursor, match=pattern, count=100)
180180
if keys:
181181
await client.delete(*keys)
182-
if cursor == 0: # cursor returns to 0 when scan is complete
182+
if cursor == 0:
183183
break
184184

185185

src/app/models/post.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import uuid as uuid_pkg
22
from datetime import UTC, datetime
3-
from uuid6 import uuid7 #126
3+
from uuid6 import uuid7
44

55
from sqlalchemy import DateTime, ForeignKey, String,UUID
66
from sqlalchemy.orm import Mapped, mapped_column

src/app/models/user.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
class User(Base):
1313
__tablename__ = "user"
1414

15-
# Option 1: Use integer ID as primary key (recommended for compatibility)
1615
id: Mapped[int] = mapped_column(autoincrement=True, primary_key=True, init=False)
1716

1817
name: Mapped[str] = mapped_column(String(30))

tests/test_user.py

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -119,13 +119,13 @@ async def test_patch_user_success(self, mock_db, current_user_dict, sample_user_
119119
username = current_user_dict["username"]
120120
user_update = UserUpdate(name="New Name")
121121

122-
# Convert the UserRead model to a dictionary for the mock
122+
123123
user_dict = sample_user_read.model_dump()
124124
user_dict["username"] = username
125125

126126
with patch("src.app.api.v1.users.crud_users") as mock_crud:
127-
mock_crud.get = AsyncMock(return_value=user_dict) # Return dict instead of UserRead
128-
mock_crud.exists = AsyncMock(return_value=False) # No conflicts
127+
mock_crud.get = AsyncMock(return_value=user_dict)
128+
mock_crud.exists = AsyncMock(return_value=False)
129129
mock_crud.update = AsyncMock(return_value=None)
130130

131131
result = await patch_user(Mock(), user_update, username, current_user_dict, mock_db)
@@ -138,12 +138,11 @@ async def test_patch_user_forbidden(self, mock_db, current_user_dict, sample_use
138138
"""Test user update when user tries to update another user."""
139139
username = "different_user"
140140
user_update = UserUpdate(name="New Name")
141-
# Convert the UserRead model to a dictionary for the mock
142141
user_dict = sample_user_read.model_dump()
143142
user_dict["username"] = username
144143

145144
with patch("src.app.api.v1.users.crud_users") as mock_crud:
146-
mock_crud.get = AsyncMock(return_value=user_dict) # Return dict instead of UserRead
145+
mock_crud.get = AsyncMock(return_value=user_dict)
147146

148147
with pytest.raises(ForbiddenException):
149148
await patch_user(Mock(), user_update, username, current_user_dict, mock_db)

0 commit comments

Comments
 (0)