fix: replace deprecated .dict() with .model_dump() and fix db.add() AsyncMock warnings
Agent-Logs-Url: https://github.com/christianlouis/InboxConverge/sessions/ac39d3f7-d4c3-4417-8c33-8e6340a27281 Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com>
This commit is contained in:
committed by
GitHub
parent
025684386b
commit
31dc059274
@@ -322,7 +322,7 @@ async def create_admin_notification_config(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Create a new admin notification configuration (admin only)"""
|
||||
config = AdminNotificationConfig(**config_in.dict())
|
||||
config = AdminNotificationConfig(**config_in.model_dump())
|
||||
db.add(config)
|
||||
await db.commit()
|
||||
await db.refresh(config)
|
||||
@@ -370,7 +370,7 @@ async def update_admin_notification_config(
|
||||
detail="Admin notification config not found",
|
||||
)
|
||||
|
||||
update_data = config_in.dict(exclude_unset=True)
|
||||
update_data = config_in.model_dump(exclude_unset=True)
|
||||
for field, value in update_data.items():
|
||||
setattr(config, field, value)
|
||||
|
||||
|
||||
@@ -29,7 +29,7 @@ async def create_notification_config(
|
||||
db: AsyncSession = Depends(get_db),
|
||||
):
|
||||
"""Create a new notification configuration"""
|
||||
config = NotificationConfig(user_id=current_user.id, **config_in.dict())
|
||||
config = NotificationConfig(user_id=current_user.id, **config_in.model_dump())
|
||||
db.add(config)
|
||||
await db.commit()
|
||||
await db.refresh(config)
|
||||
@@ -91,7 +91,7 @@ async def update_notification_config(
|
||||
detail="Notification config not found",
|
||||
)
|
||||
|
||||
update_data = config_in.dict(exclude_unset=True)
|
||||
update_data = config_in.model_dump(exclude_unset=True)
|
||||
for field, value in update_data.items():
|
||||
setattr(config, field, value)
|
||||
|
||||
|
||||
@@ -172,9 +172,8 @@ class TestConfigServiceSet:
|
||||
mock_result.scalar_one_or_none.return_value = None
|
||||
|
||||
mock_db = AsyncMock()
|
||||
mock_db.add = MagicMock()
|
||||
mock_db.execute.return_value = mock_result
|
||||
|
||||
# The method will call db.add() and db.commit()
|
||||
await ConfigService.set(
|
||||
"SMTP_HOST", "new.host.com", db=mock_db, category="smtp"
|
||||
)
|
||||
|
||||
@@ -77,6 +77,8 @@ def _mock_session_maker():
|
||||
is usable as ``async with session_maker_mock() as db:``.
|
||||
"""
|
||||
session = AsyncMock()
|
||||
# db.add() is synchronous in SQLAlchemy; prevent "coroutine never awaited" warnings
|
||||
session.add = MagicMock()
|
||||
|
||||
# Make the session usable as an async context manager
|
||||
ctx = AsyncMock()
|
||||
|
||||
Reference in New Issue
Block a user