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>
This commit is contained in:
copilot-swe-agent[bot]
2026-02-26 09:14:08 +00:00
parent ffa0e1eb7b
commit 096aedb8a0
+4 -10
View File
@@ -31,7 +31,7 @@ class TestUpdateSettingsExceptionHandler:
class TestTestTokenServiceAccount: class TestTestTokenServiceAccount:
"""Cover lines 214-255: service account test-token paths.""" """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): def test_test_token_service_account_success_no_delegation(self, mock_get_service, client: TestClient):
"""Test successful service account connection without delegation.""" """Test successful service account connection without delegation."""
from app.config import settings from app.config import settings
@@ -55,7 +55,7 @@ class TestTestTokenServiceAccount:
assert data["auth_type"] == "service_account" assert data["auth_type"] == "service_account"
assert "sa@project.iam.gserviceaccount.com" in data["message"] 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): def test_test_token_service_account_with_delegation(self, mock_get_service, client: TestClient):
"""Test service account with delegation shows delegated user info.""" """Test service account with delegation shows delegated user info."""
from app.config import settings from app.config import settings
@@ -93,7 +93,7 @@ class TestTestTokenServiceAccount:
assert data["status"] == "error" assert data["status"] == "error"
assert "not configured" in data["message"] 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): def test_test_token_service_account_connection_error(self, mock_get_service, client: TestClient):
"""Test service account connection error (lines 245-251).""" """Test service account connection error (lines 245-251)."""
from app.config import settings from app.config import settings
@@ -118,13 +118,7 @@ class TestGetTokenInfoOuterException:
def test_get_token_info_outer_exception(self, client: TestClient): def test_get_token_info_outer_exception(self, client: TestClient):
"""Trigger the outer exception handler in get_google_drive_token_info.""" """Trigger the outer exception handler in get_google_drive_token_info."""
from app.config import settings with patch("app.api.google_drive.getattr", side_effect=Exception("boom")):
with patch.object(
type(settings),
"google_drive_use_oauth",
property(fget=lambda self: (_ for _ in ()).throw(Exception("boom"))),
):
response = client.get("/api/google-drive/get-token-info") response = client.get("/api/google-drive/get-token-info")
assert response.status_code == 200 assert response.status_code == 200