diff --git a/CHANGELOG.md b/CHANGELOG.md index fde5620..b054fad 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 +## [Unreleased] + +### Fixed +- Replace deprecated Pydantic V2 `.dict()` calls with `.model_dump()` in `admin.py` and `notifications.py` endpoints. +- Fix `RuntimeWarning: coroutine 'AsyncMockMixin._execute_mock_call' was never awaited` in `test_tasks.py` and `test_config_service.py` by marking `db.add` as a synchronous `MagicMock` in test helpers. + ## v0.6.3 (2026-04-07) ### Bug Fixes diff --git a/backend/app/api/v1/endpoints/admin.py b/backend/app/api/v1/endpoints/admin.py index d91b377..24ff725 100644 --- a/backend/app/api/v1/endpoints/admin.py +++ b/backend/app/api/v1/endpoints/admin.py @@ -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) diff --git a/backend/app/api/v1/endpoints/notifications.py b/backend/app/api/v1/endpoints/notifications.py index 4706028..7640541 100644 --- a/backend/app/api/v1/endpoints/notifications.py +++ b/backend/app/api/v1/endpoints/notifications.py @@ -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) diff --git a/backend/tests/unit/test_config_service.py b/backend/tests/unit/test_config_service.py index 8532ede..06f2749 100644 --- a/backend/tests/unit/test_config_service.py +++ b/backend/tests/unit/test_config_service.py @@ -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" ) diff --git a/backend/tests/unit/test_tasks.py b/backend/tests/unit/test_tasks.py index 56bea67..b1e818a 100644 --- a/backend/tests/unit/test_tasks.py +++ b/backend/tests/unit/test_tasks.py @@ -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() diff --git a/docs/TODO.md b/docs/TODO.md index bb89f42..d437241 100644 --- a/docs/TODO.md +++ b/docs/TODO.md @@ -4,6 +4,8 @@ Comprehensive task breakdown for repository improvements and production readines ## ✅ Recently Completed +- [x] **Fix Pydantic V2 deprecation warnings**: Replaced `.dict()` with `.model_dump()` in `admin.py` and `notifications.py`. Fixed `RuntimeWarning: coroutine never awaited` for `db.add()` in test mocks (`test_tasks.py`, `test_config_service.py`). + - [x] **Expanded backend test coverage**: Added 150 new unit tests across 10 new test files, increasing the backend test count from 361 to 511. New coverage includes `core/gdpr.py`, `utils/gmail_labels.py`, `services/notification_service.py`, `services/auth_service.py`, and API endpoints for auth, users, notifications, processing-runs/logs, app-settings, and version. - [x] **Improved test coverage for `mail_processor.py`**: Added 46 new unit tests covering POP3 connection testing, POP3 email fetching, IMAP edge cases, email forwarding (STARTTLS/SSL), and `fetch_emails`/`test_connection` routing. Coverage increased from ~42% to 98%.