diff --git a/google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py b/google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py index 1cc401d6af..a63d45be01 100644 --- a/google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py +++ b/google/cloud/firestore_admin_v1/services/firestore_admin/async_client.py @@ -301,7 +301,7 @@ async def create_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, index]) if request is not None and has_flattened_params: @@ -385,7 +385,7 @@ async def list_indexes( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -474,7 +474,7 @@ async def get_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -550,7 +550,7 @@ async def delete_index( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -634,7 +634,7 @@ async def get_field( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -736,7 +736,7 @@ async def update_field( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([field]) if request is not None and has_flattened_params: @@ -828,7 +828,7 @@ async def list_fields( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -903,8 +903,7 @@ async def export_documents( For more details on export behavior and output format, refer to: - https://cloud.google.com/firestore/docs/manage- - data/export-import + https://cloud.google.com/firestore/docs/manage-data/export-import Args: request (Union[google.cloud.firestore_admin_v1.types.ExportDocumentsRequest, dict]): @@ -935,7 +934,7 @@ async def export_documents( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -1033,7 +1032,7 @@ async def import_documents( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -1114,7 +1113,7 @@ async def get_database( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -1183,7 +1182,7 @@ async def list_databases( The list of databases for a project. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -1262,7 +1261,7 @@ async def update_database( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([database, update_mask]) if request is not None and has_flattened_params: diff --git a/google/cloud/firestore_admin_v1/services/firestore_admin/client.py b/google/cloud/firestore_admin_v1/services/firestore_admin/client.py index fdd179066a..16030b8a37 100644 --- a/google/cloud/firestore_admin_v1/services/firestore_admin/client.py +++ b/google/cloud/firestore_admin_v1/services/firestore_admin/client.py @@ -535,7 +535,7 @@ def create_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent, index]) if request is not None and has_flattened_params: @@ -619,7 +619,7 @@ def list_indexes( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -697,7 +697,7 @@ def get_index( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -762,7 +762,7 @@ def delete_index( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -835,7 +835,7 @@ def get_field( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -926,7 +926,7 @@ def update_field( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([field]) if request is not None and has_flattened_params: @@ -1018,7 +1018,7 @@ def list_fields( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -1082,8 +1082,7 @@ def export_documents( For more details on export behavior and output format, refer to: - https://cloud.google.com/firestore/docs/manage- - data/export-import + https://cloud.google.com/firestore/docs/manage-data/export-import Args: request (Union[google.cloud.firestore_admin_v1.types.ExportDocumentsRequest, dict]): @@ -1114,7 +1113,7 @@ def export_documents( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -1212,7 +1211,7 @@ def import_documents( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -1293,7 +1292,7 @@ def get_database( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -1362,7 +1361,7 @@ def list_databases( The list of databases for a project. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: @@ -1441,7 +1440,7 @@ def update_database( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([database, update_mask]) if request is not None and has_flattened_params: diff --git a/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc.py b/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc.py index 0c9bb2da70..a59344396a 100644 --- a/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc.py +++ b/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc.py @@ -195,8 +195,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -269,7 +272,7 @@ def operations_client(self) -> operations_v1.OperationsClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsClient(self.grpc_channel) @@ -504,8 +507,7 @@ def export_documents( For more details on export behavior and output format, refer to: - https://cloud.google.com/firestore/docs/manage- - data/export-import + https://cloud.google.com/firestore/docs/manage-data/export-import Returns: Callable[[~.ExportDocumentsRequest], diff --git a/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc_asyncio.py b/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc_asyncio.py index 0e1b164fbc..3990831151 100644 --- a/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc_asyncio.py +++ b/google/cloud/firestore_admin_v1/services/firestore_admin/transports/grpc_asyncio.py @@ -240,8 +240,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, @@ -271,7 +274,7 @@ def operations_client(self) -> operations_v1.OperationsAsyncClient: This property caches on the instance; repeated calls return the same client. """ - # Sanity check: Only create a new client if we do not already have one. + # Quick check: Only create a new client if we do not already have one. if self._operations_client is None: self._operations_client = operations_v1.OperationsAsyncClient( self.grpc_channel @@ -520,8 +523,7 @@ def export_documents( For more details on export behavior and output format, refer to: - https://cloud.google.com/firestore/docs/manage- - data/export-import + https://cloud.google.com/firestore/docs/manage-data/export-import Returns: Callable[[~.ExportDocumentsRequest], diff --git a/google/cloud/firestore_admin_v1/types/database.py b/google/cloud/firestore_admin_v1/types/database.py index 1ebb283ea7..de8b51548c 100644 --- a/google/cloud/firestore_admin_v1/types/database.py +++ b/google/cloud/firestore_admin_v1/types/database.py @@ -37,9 +37,8 @@ class Database(proto.Message): type_ (google.cloud.firestore_admin_v1.types.Database.DatabaseType): The type of the database. See - https://cloud.google.com/datastore/docs/firestore- - or-datastore for information about how to - choose. + https://cloud.google.com/datastore/docs/firestore-or-datastore + for information about how to choose. concurrency_mode (google.cloud.firestore_admin_v1.types.Database.ConcurrencyMode): The concurrency control mode to use for this database. @@ -52,8 +51,9 @@ class Database(proto.Message): class DatabaseType(proto.Enum): r"""The type of the database. - See https://cloud.google.com/datastore/docs/firestore-or- - datastore for information about how to choose. + See + https://cloud.google.com/datastore/docs/firestore-or-datastore + for information about how to choose. """ DATABASE_TYPE_UNSPECIFIED = 0 FIRESTORE_NATIVE = 1 diff --git a/google/cloud/firestore_v1/services/firestore/async_client.py b/google/cloud/firestore_v1/services/firestore/async_client.py index 432a2edea2..3ced3ee586 100644 --- a/google/cloud/firestore_v1/services/firestore/async_client.py +++ b/google/cloud/firestore_v1/services/firestore/async_client.py @@ -57,13 +57,13 @@ class FirestoreAsyncClient: """The Cloud Firestore service. - Cloud Firestore is a fast, fully managed, serverless, cloud- - native NoSQL document database that simplifies storing, syncing, - and querying data for your mobile, web, and IoT apps at global - scale. Its client libraries provide live synchronization and - offline support, while its security features and integrations - with Firebase and Google Cloud Platform (GCP) accelerate - building truly serverless apps. + Cloud Firestore is a fast, fully managed, serverless, + cloud-native NoSQL document database that simplifies storing, + syncing, and querying data for your mobile, web, and IoT apps at + global scale. Its client libraries provide live synchronization + and offline support, while its security features and + integrations with Firebase and Google Cloud Platform (GCP) + accelerate building truly serverless apps. """ _client: FirestoreClient @@ -401,7 +401,7 @@ async def update_document( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, update_mask]) if request is not None and has_flattened_params: @@ -481,7 +481,7 @@ async def delete_document( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -626,7 +626,7 @@ async def begin_transaction( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([database]) if request is not None and has_flattened_params: @@ -718,7 +718,7 @@ async def commit( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([database, writes]) if request is not None and has_flattened_params: @@ -803,7 +803,7 @@ async def rollback( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([database, transaction]) if request is not None and has_flattened_params: @@ -1140,7 +1140,7 @@ async def list_collection_ids( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: diff --git a/google/cloud/firestore_v1/services/firestore/client.py b/google/cloud/firestore_v1/services/firestore/client.py index 0c46e4559b..fc6129b674 100644 --- a/google/cloud/firestore_v1/services/firestore/client.py +++ b/google/cloud/firestore_v1/services/firestore/client.py @@ -81,13 +81,13 @@ def get_transport_class(cls, label: str = None,) -> Type[FirestoreTransport]: class FirestoreClient(metaclass=FirestoreClientMeta): """The Cloud Firestore service. - Cloud Firestore is a fast, fully managed, serverless, cloud- - native NoSQL document database that simplifies storing, syncing, - and querying data for your mobile, web, and IoT apps at global - scale. Its client libraries provide live synchronization and - offline support, while its security features and integrations - with Firebase and Google Cloud Platform (GCP) accelerate - building truly serverless apps. + Cloud Firestore is a fast, fully managed, serverless, + cloud-native NoSQL document database that simplifies storing, + syncing, and querying data for your mobile, web, and IoT apps at + global scale. Its client libraries provide live synchronization + and offline support, while its security features and + integrations with Firebase and Google Cloud Platform (GCP) + accelerate building truly serverless apps. """ @staticmethod @@ -556,7 +556,7 @@ def update_document( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([document, update_mask]) if request is not None and has_flattened_params: @@ -626,7 +626,7 @@ def delete_document( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([name]) if request is not None and has_flattened_params: @@ -748,7 +748,7 @@ def begin_transaction( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([database]) if request is not None and has_flattened_params: @@ -828,7 +828,7 @@ def commit( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([database, writes]) if request is not None and has_flattened_params: @@ -903,7 +903,7 @@ def rollback( sent along with the request as metadata. """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([database, transaction]) if request is not None and has_flattened_params: @@ -1186,7 +1186,7 @@ def list_collection_ids( """ # Create or coerce a protobuf request object. - # Sanity check: If we got a request object, we should *not* have + # Quick check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. has_flattened_params = any([parent]) if request is not None and has_flattened_params: diff --git a/google/cloud/firestore_v1/services/firestore/transports/grpc.py b/google/cloud/firestore_v1/services/firestore/transports/grpc.py index 5e16a4e69b..4233222448 100644 --- a/google/cloud/firestore_v1/services/firestore/transports/grpc.py +++ b/google/cloud/firestore_v1/services/firestore/transports/grpc.py @@ -35,13 +35,13 @@ class FirestoreGrpcTransport(FirestoreTransport): """gRPC backend transport for Firestore. The Cloud Firestore service. - Cloud Firestore is a fast, fully managed, serverless, cloud- - native NoSQL document database that simplifies storing, syncing, - and querying data for your mobile, web, and IoT apps at global - scale. Its client libraries provide live synchronization and - offline support, while its security features and integrations - with Firebase and Google Cloud Platform (GCP) accelerate - building truly serverless apps. + Cloud Firestore is a fast, fully managed, serverless, + cloud-native NoSQL document database that simplifies storing, + syncing, and querying data for your mobile, web, and IoT apps at + global scale. Its client libraries provide live synchronization + and offline support, while its security features and + integrations with Firebase and Google Cloud Platform (GCP) + accelerate building truly serverless apps. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -168,8 +168,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py b/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py index b927558f23..12c11f7af8 100644 --- a/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py +++ b/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py @@ -36,13 +36,13 @@ class FirestoreGrpcAsyncIOTransport(FirestoreTransport): """gRPC AsyncIO backend transport for Firestore. The Cloud Firestore service. - Cloud Firestore is a fast, fully managed, serverless, cloud- - native NoSQL document database that simplifies storing, syncing, - and querying data for your mobile, web, and IoT apps at global - scale. Its client libraries provide live synchronization and - offline support, while its security features and integrations - with Firebase and Google Cloud Platform (GCP) accelerate - building truly serverless apps. + Cloud Firestore is a fast, fully managed, serverless, + cloud-native NoSQL document database that simplifies storing, + syncing, and querying data for your mobile, web, and IoT apps at + global scale. Its client libraries provide live synchronization + and offline support, while its security features and + integrations with Firebase and Google Cloud Platform (GCP) + accelerate building truly serverless apps. This class defines the same methods as the primary client, so the primary client can load the underlying transport implementation @@ -213,8 +213,11 @@ def __init__( if not self._grpc_channel: self._grpc_channel = type(self).create_channel( self._host, + # use the credentials which are saved credentials=self._credentials, - credentials_file=credentials_file, + # Set ``credentials_file`` to ``None`` here as + # the credentials that we saved earlier should be used. + credentials_file=None, scopes=self._scopes, ssl_credentials=self._ssl_channel_credentials, quota_project_id=quota_project_id, diff --git a/google/cloud/firestore_v1/types/firestore.py b/google/cloud/firestore_v1/types/firestore.py index dc7dcc7d45..499ced324a 100644 --- a/google/cloud/firestore_v1/types/firestore.py +++ b/google/cloud/firestore_v1/types/firestore.py @@ -912,8 +912,8 @@ class Target(proto.Message): This field is a member of `oneof`_ ``resume_type``. target_id (int): The target ID that identifies the target on - the stream. Must be a positive number and non- - zero. + the stream. Must be a positive number and + non-zero. once (bool): If the target should be removed once it is current and consistent. diff --git a/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py b/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py index e40c995ddc..1edec41430 100644 --- a/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py +++ b/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py @@ -29,6 +29,7 @@ from google.api_core import gapic_v1 from google.api_core import grpc_helpers from google.api_core import grpc_helpers_async +from google.api_core import operation from google.api_core import operation_async # type: ignore from google.api_core import operations_v1 from google.api_core import path_template @@ -524,21 +525,28 @@ def test_firestore_admin_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (FirestoreAdminClient, transports.FirestoreAdminGrpcTransport, "grpc"), + ( + FirestoreAdminClient, + transports.FirestoreAdminGrpcTransport, + "grpc", + grpc_helpers, + ), ( FirestoreAdminAsyncClient, transports.FirestoreAdminGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_firestore_admin_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -574,6 +582,75 @@ def test_firestore_admin_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + ( + FirestoreAdminClient, + transports.FirestoreAdminGrpcTransport, + "grpc", + grpc_helpers, + ), + ( + FirestoreAdminAsyncClient, + transports.FirestoreAdminGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_firestore_admin_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "firestore.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/datastore", + ), + scopes=None, + default_host="firestore.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize("request_type", [firestore_admin.CreateIndexRequest, dict,]) def test_create_index(request_type, transport: str = "grpc"): client = FirestoreAdminClient( diff --git a/tests/unit/gapic/firestore_v1/test_firestore.py b/tests/unit/gapic/firestore_v1/test_firestore.py index 7ee65a751e..7b354d1322 100644 --- a/tests/unit/gapic/firestore_v1/test_firestore.py +++ b/tests/unit/gapic/firestore_v1/test_firestore.py @@ -499,21 +499,23 @@ def test_firestore_client_client_options_scopes( @pytest.mark.parametrize( - "client_class,transport_class,transport_name", + "client_class,transport_class,transport_name,grpc_helpers", [ - (FirestoreClient, transports.FirestoreGrpcTransport, "grpc"), + (FirestoreClient, transports.FirestoreGrpcTransport, "grpc", grpc_helpers), ( FirestoreAsyncClient, transports.FirestoreGrpcAsyncIOTransport, "grpc_asyncio", + grpc_helpers_async, ), ], ) def test_firestore_client_client_options_credentials_file( - client_class, transport_class, transport_name + client_class, transport_class, transport_name, grpc_helpers ): # Check the case credentials file is provided. options = client_options.ClientOptions(credentials_file="credentials.json") + with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None client = client_class(client_options=options, transport=transport_name) @@ -547,6 +549,70 @@ def test_firestore_client_client_options_from_dict(): ) +@pytest.mark.parametrize( + "client_class,transport_class,transport_name,grpc_helpers", + [ + (FirestoreClient, transports.FirestoreGrpcTransport, "grpc", grpc_helpers), + ( + FirestoreAsyncClient, + transports.FirestoreGrpcAsyncIOTransport, + "grpc_asyncio", + grpc_helpers_async, + ), + ], +) +def test_firestore_client_create_channel_credentials_file( + client_class, transport_class, transport_name, grpc_helpers +): + # Check the case credentials file is provided. + options = client_options.ClientOptions(credentials_file="credentials.json") + + with mock.patch.object(transport_class, "__init__") as patched: + patched.return_value = None + client = client_class(client_options=options, transport=transport_name) + patched.assert_called_once_with( + credentials=None, + credentials_file="credentials.json", + host=client.DEFAULT_ENDPOINT, + scopes=None, + client_cert_source_for_mtls=None, + quota_project_id=None, + client_info=transports.base.DEFAULT_CLIENT_INFO, + always_use_jwt_access=True, + ) + + # test that the credentials from file are saved and used as the credentials. + with mock.patch.object( + google.auth, "load_credentials_from_file", autospec=True + ) as load_creds, mock.patch.object( + google.auth, "default", autospec=True + ) as adc, mock.patch.object( + grpc_helpers, "create_channel" + ) as create_channel: + creds = ga_credentials.AnonymousCredentials() + file_creds = ga_credentials.AnonymousCredentials() + load_creds.return_value = (file_creds, None) + adc.return_value = (creds, None) + client = client_class(client_options=options, transport=transport_name) + create_channel.assert_called_with( + "firestore.googleapis.com:443", + credentials=file_creds, + credentials_file=None, + quota_project_id=None, + default_scopes=( + "https://www.googleapis.com/auth/cloud-platform", + "https://www.googleapis.com/auth/datastore", + ), + scopes=None, + default_host="firestore.googleapis.com", + ssl_credentials=None, + options=[ + ("grpc.max_send_message_length", -1), + ("grpc.max_receive_message_length", -1), + ], + ) + + @pytest.mark.parametrize("request_type", [firestore.GetDocumentRequest, dict,]) def test_get_document(request_type, transport: str = "grpc"): client = FirestoreClient(