From 096aedb8a0ea3988a8072634647cfc3b1def0309 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Thu, 26 Feb 2026 09:14:08 +0000 Subject: [PATCH] fix(tests): correct mock patch targets in google_drive coverage tests - Change @patch("app.api.google_drive.get_google_drive_service") to @patch("app.tasks.upload_to_google_drive.get_google_drive_service") because the function is imported locally inside the endpoint function body, not at module level - Replace patch.object(type(settings), "google_drive_use_oauth", ...) with patch("app.api.google_drive.getattr", ...) because Pydantic v2 models don't expose fields as regular class attributes Co-authored-by: christianlouis <361235+christianlouis@users.noreply.github.com> --- tests/test_api_google_drive_coverage2.py | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/tests/test_api_google_drive_coverage2.py b/tests/test_api_google_drive_coverage2.py index 8215d8f5..10631e1b 100644 --- a/tests/test_api_google_drive_coverage2.py +++ b/tests/test_api_google_drive_coverage2.py @@ -31,7 +31,7 @@ class TestUpdateSettingsExceptionHandler: class TestTestTokenServiceAccount: """Cover lines 214-255: service account test-token paths.""" - @patch("app.api.google_drive.get_google_drive_service") + @patch("app.tasks.upload_to_google_drive.get_google_drive_service") def test_test_token_service_account_success_no_delegation(self, mock_get_service, client: TestClient): """Test successful service account connection without delegation.""" from app.config import settings @@ -55,7 +55,7 @@ class TestTestTokenServiceAccount: assert data["auth_type"] == "service_account" assert "sa@project.iam.gserviceaccount.com" in data["message"] - @patch("app.api.google_drive.get_google_drive_service") + @patch("app.tasks.upload_to_google_drive.get_google_drive_service") def test_test_token_service_account_with_delegation(self, mock_get_service, client: TestClient): """Test service account with delegation shows delegated user info.""" from app.config import settings @@ -93,7 +93,7 @@ class TestTestTokenServiceAccount: assert data["status"] == "error" assert "not configured" in data["message"] - @patch("app.api.google_drive.get_google_drive_service") + @patch("app.tasks.upload_to_google_drive.get_google_drive_service") def test_test_token_service_account_connection_error(self, mock_get_service, client: TestClient): """Test service account connection error (lines 245-251).""" from app.config import settings @@ -118,13 +118,7 @@ class TestGetTokenInfoOuterException: def test_get_token_info_outer_exception(self, client: TestClient): """Trigger the outer exception handler in get_google_drive_token_info.""" - from app.config import settings - - with patch.object( - type(settings), - "google_drive_use_oauth", - property(fget=lambda self: (_ for _ in ()).throw(Exception("boom"))), - ): + with patch("app.api.google_drive.getattr", side_effect=Exception("boom")): response = client.get("/api/google-drive/get-token-info") assert response.status_code == 200