This repository was archived by the owner on Mar 31, 2026. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +13
-0
lines changed
Expand file tree Collapse file tree 1 file changed +13
-0
lines changed Original file line number Diff line number Diff line change 1616from mock import create_autospec
1717from typing import Mapping
1818
19+ from google .auth .credentials import Credentials , Scoped
1920from google .cloud .spanner_dbapi import Connection
2021from google .cloud .spanner_v1 import SpannerClient
2122from google .cloud .spanner_v1 .client import Client
@@ -92,6 +93,9 @@ def build_client(**kwargs: Mapping) -> Client:
9293 if "project" not in kwargs :
9394 kwargs ["project" ] = _PROJECT_ID
9495
96+ if "credentials" not in kwargs :
97+ kwargs ["credentials" ] = build_scoped_credentials ()
98+
9599 return Client (** kwargs )
96100
97101
@@ -174,6 +178,15 @@ def build_logger() -> Logger:
174178 return create_autospec (Logger , instance = True )
175179
176180
181+ def build_scoped_credentials () -> Credentials :
182+ """Builds and returns a mock scoped credentials for testing."""
183+
184+ class _ScopedCredentials (Credentials , Scoped ):
185+ pass
186+
187+ return create_autospec (spec = _ScopedCredentials , instance = True )
188+
189+
177190def build_spanner_api () -> SpannerClient :
178191 """Builds and returns a mock Spanner Client API for testing using the given arguments.
179192 Commonly used methods are mocked to return default values."""
You can’t perform that action at this time.
0 commit comments