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>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-26 12:04:38 +00:00
parent b4e93c00b4
commit 44dcabd1f3
+4 -5
View File
@@ -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