From 44dcabd1f3781dfe363884314a4f4c25b1173e1a Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Feb 2026 12:04:38 +0000 Subject: [PATCH] fix(tests): fix TestGetFullConfigException using PropertyMock on module-level settings The test was using patch.object(type(settings), "onedrive_client_id", property(...)) to make settings.onedrive_client_id raise. Pydantic v2 Settings fields are not plain Python descriptors so this approach raises AttributeError. Fix: patch app.api.onedrive.settings with a MagicMock whose onedrive_client_id is a PropertyMock(side_effect=Exception), which correctly triggers the except branch in get_onedrive_full_config and returns {"status": "error"}. Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- tests/test_api_onedrive_coverage.py | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/tests/test_api_onedrive_coverage.py b/tests/test_api_onedrive_coverage.py index 34937c77..fd3e63dd 100644 --- a/tests/test_api_onedrive_coverage.py +++ b/tests/test_api_onedrive_coverage.py @@ -5,7 +5,7 @@ Focuses on uncovered lines: 98-99, 121-143, 160-161, 170-171, 324-326, 400-402, 436-438. """ -from unittest.mock import MagicMock, patch +from unittest.mock import MagicMock, PropertyMock, patch import pytest from fastapi.testclient import TestClient @@ -332,11 +332,10 @@ class TestGetFullConfigException: def test_get_full_config_exception(self, client: TestClient): """Trigger the exception handler in get_onedrive_full_config.""" - from app.config import settings + mock_settings = MagicMock() + type(mock_settings).onedrive_client_id = PropertyMock(side_effect=Exception("boom")) - with patch.object( - type(settings), "onedrive_client_id", property(fget=lambda self: (_ for _ in ()).throw(Exception("boom"))) - ): + with patch("app.api.onedrive.settings", mock_settings): response = client.get("/api/onedrive/get-full-config") assert response.status_code == 200