From 386e85ecf704e1168b0deb4ee9e6c2105a9040a9 Mon Sep 17 00:00:00 2001 From: Tres Seaver Date: Fri, 13 Nov 2020 15:41:29 -0500 Subject: [PATCH] fix: request and flattened params are exclusive, surface transport in generated layer (#256) - Restore path helper methods to generated clients. - Enforce that 'request' argument to generated client methods is exclusive to flattened arguments. - Surface 'transport' property for generated clients. Closes #251 Closes #252 --- .../services/firestore_admin/async_client.py | 71 ++- .../services/firestore_admin/client.py | 105 +++- .../firestore_admin/transports/grpc.py | 18 +- .../transports/grpc_asyncio.py | 4 + .../services/firestore/async_client.py | 94 ++- .../firestore_v1/services/firestore/client.py | 81 ++- .../services/firestore/transports/base.py | 20 +- .../services/firestore/transports/grpc.py | 18 +- .../firestore/transports/grpc_asyncio.py | 4 + google/cloud/firestore_v1/types/document.py | 4 +- noxfile.py | 4 +- scripts/fixup_firestore_admin_v1_keywords.py | 1 + scripts/fixup_firestore_v1_keywords.py | 1 + synth.metadata | 10 +- .../test_firestore_admin.py | 517 +++++++++++------ .../unit/gapic/firestore_v1/test_firestore.py | 541 ++++++++++++------ 16 files changed, 1041 insertions(+), 452 deletions(-) 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 38e6406eb..92ead923b 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 @@ -54,14 +54,58 @@ class FirestoreAdminAsyncClient: DEFAULT_ENDPOINT = FirestoreAdminClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = FirestoreAdminClient.DEFAULT_MTLS_ENDPOINT + collection_group_path = staticmethod(FirestoreAdminClient.collection_group_path) + parse_collection_group_path = staticmethod( + FirestoreAdminClient.parse_collection_group_path + ) + database_path = staticmethod(FirestoreAdminClient.database_path) + parse_database_path = staticmethod(FirestoreAdminClient.parse_database_path) field_path = staticmethod(FirestoreAdminClient.field_path) parse_field_path = staticmethod(FirestoreAdminClient.parse_field_path) index_path = staticmethod(FirestoreAdminClient.index_path) parse_index_path = staticmethod(FirestoreAdminClient.parse_index_path) + common_billing_account_path = staticmethod( + FirestoreAdminClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + FirestoreAdminClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(FirestoreAdminClient.common_folder_path) + parse_common_folder_path = staticmethod( + FirestoreAdminClient.parse_common_folder_path + ) + + common_organization_path = staticmethod( + FirestoreAdminClient.common_organization_path + ) + parse_common_organization_path = staticmethod( + FirestoreAdminClient.parse_common_organization_path + ) + + common_project_path = staticmethod(FirestoreAdminClient.common_project_path) + parse_common_project_path = staticmethod( + FirestoreAdminClient.parse_common_project_path + ) + + common_location_path = staticmethod(FirestoreAdminClient.common_location_path) + parse_common_location_path = staticmethod( + FirestoreAdminClient.parse_common_location_path + ) + from_service_account_file = FirestoreAdminClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> FirestoreAdminTransport: + """Return the transport used by the client instance. + + Returns: + FirestoreAdminTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(FirestoreAdminClient).get_transport_class, type(FirestoreAdminClient) ) @@ -166,7 +210,8 @@ async def create_index( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent, index]): + has_flattened_params = any([parent, index]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -250,7 +295,8 @@ async def list_indexes( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -338,7 +384,8 @@ async def get_index( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -413,7 +460,8 @@ async def delete_index( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -496,7 +544,8 @@ async def get_field( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -598,7 +647,8 @@ async def update_field( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([field]): + has_flattened_params = any([field]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -689,7 +739,8 @@ async def list_fields( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -790,7 +841,8 @@ async def export_documents( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -890,7 +942,8 @@ async def import_documents( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." 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 f721cee47..28ac8c7d5 100644 --- a/google/cloud/firestore_admin_v1/services/firestore_admin/client.py +++ b/google/cloud/firestore_admin_v1/services/firestore_admin/client.py @@ -140,6 +140,44 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> FirestoreAdminTransport: + """Return the transport used by the client instance. + + Returns: + FirestoreAdminTransport: The transport used by the client instance. + """ + return self._transport + + @staticmethod + def collection_group_path(project: str, database: str, collection: str,) -> str: + """Return a fully-qualified collection_group string.""" + return "projects/{project}/databases/{database}/collectionGroups/{collection}".format( + project=project, database=database, collection=collection, + ) + + @staticmethod + def parse_collection_group_path(path: str) -> Dict[str, str]: + """Parse a collection_group path into its component segments.""" + m = re.match( + r"^projects/(?P.+?)/databases/(?P.+?)/collectionGroups/(?P.+?)$", + path, + ) + return m.groupdict() if m else {} + + @staticmethod + def database_path(project: str, database: str,) -> str: + """Return a fully-qualified database string.""" + return "projects/{project}/databases/{database}".format( + project=project, database=database, + ) + + @staticmethod + def parse_database_path(path: str) -> Dict[str, str]: + """Parse a database path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/databases/(?P.+?)$", path) + return m.groupdict() if m else {} + @staticmethod def field_path(project: str, database: str, collection: str, field: str,) -> str: """Return a fully-qualified field string.""" @@ -172,6 +210,65 @@ def parse_index_path(path: str) -> Dict[str, str]: ) return m.groupdict() if m else {} + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, @@ -207,10 +304,10 @@ def __init__( not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: 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 dc82e06e8..dd9498705 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 @@ -95,10 +95,10 @@ def __init__( for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -107,6 +107,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -114,6 +116,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -150,6 +153,7 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -227,12 +231,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property 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 30ce02fc1..4221895f3 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 @@ -152,6 +152,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -159,6 +161,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -195,6 +198,7 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" diff --git a/google/cloud/firestore_v1/services/firestore/async_client.py b/google/cloud/firestore_v1/services/firestore/async_client.py index 92b790f4c..59d656803 100644 --- a/google/cloud/firestore_v1/services/firestore/async_client.py +++ b/google/cloud/firestore_v1/services/firestore/async_client.py @@ -18,7 +18,16 @@ from collections import OrderedDict import functools import re -from typing import Dict, AsyncIterable, AsyncIterator, Sequence, Tuple, Type, Union +from typing import ( + Dict, + AsyncIterable, + Awaitable, + AsyncIterator, + Sequence, + Tuple, + Type, + Union, +) import pkg_resources import google.api_core.client_options as ClientOptions # type: ignore @@ -59,9 +68,41 @@ class FirestoreAsyncClient: DEFAULT_ENDPOINT = FirestoreClient.DEFAULT_ENDPOINT DEFAULT_MTLS_ENDPOINT = FirestoreClient.DEFAULT_MTLS_ENDPOINT + common_billing_account_path = staticmethod( + FirestoreClient.common_billing_account_path + ) + parse_common_billing_account_path = staticmethod( + FirestoreClient.parse_common_billing_account_path + ) + + common_folder_path = staticmethod(FirestoreClient.common_folder_path) + parse_common_folder_path = staticmethod(FirestoreClient.parse_common_folder_path) + + common_organization_path = staticmethod(FirestoreClient.common_organization_path) + parse_common_organization_path = staticmethod( + FirestoreClient.parse_common_organization_path + ) + + common_project_path = staticmethod(FirestoreClient.common_project_path) + parse_common_project_path = staticmethod(FirestoreClient.parse_common_project_path) + + common_location_path = staticmethod(FirestoreClient.common_location_path) + parse_common_location_path = staticmethod( + FirestoreClient.parse_common_location_path + ) + from_service_account_file = FirestoreClient.from_service_account_file from_service_account_json = from_service_account_file + @property + def transport(self) -> FirestoreTransport: + """Return the transport used by the client instance. + + Returns: + FirestoreTransport: The transport used by the client instance. + """ + return self._client.transport + get_transport_class = functools.partial( type(FirestoreClient).get_transport_class, type(FirestoreClient) ) @@ -154,9 +195,9 @@ async def get_document( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, @@ -218,9 +259,9 @@ async def list_documents( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, @@ -297,7 +338,8 @@ async def update_document( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([document, update_mask]): + has_flattened_params = any([document, update_mask]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -373,7 +415,8 @@ async def delete_document( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([name]): + has_flattened_params = any([name]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -396,9 +439,9 @@ async def delete_document( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, @@ -423,7 +466,7 @@ def batch_get_documents( retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> AsyncIterable[firestore.BatchGetDocumentsResponse]: + ) -> Awaitable[AsyncIterable[firestore.BatchGetDocumentsResponse]]: r"""Gets multiple documents. Documents returned by this method are not guaranteed to be returned in the same order that they were requested. @@ -458,9 +501,9 @@ def batch_get_documents( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=300.0, @@ -516,7 +559,8 @@ async def begin_transaction( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([database]): + has_flattened_params = any([database]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -539,9 +583,9 @@ async def begin_transaction( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, @@ -605,7 +649,8 @@ async def commit( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([database, writes]): + has_flattened_params = any([database, writes]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -618,8 +663,9 @@ async def commit( if database is not None: request.database = database - if writes is not None: - request.writes = writes + + if writes: + request.writes.extend(writes) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. @@ -685,7 +731,8 @@ async def rollback( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([database, transaction]): + has_flattened_params = any([database, transaction]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -710,9 +757,9 @@ async def rollback( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, @@ -737,7 +784,7 @@ def run_query( retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> AsyncIterable[firestore.RunQueryResponse]: + ) -> Awaitable[AsyncIterable[firestore.RunQueryResponse]]: r"""Runs a query. Args: @@ -770,9 +817,9 @@ def run_query( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=300.0, @@ -838,9 +885,9 @@ async def partition_query( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=300.0, @@ -872,7 +919,7 @@ def write( retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> AsyncIterable[firestore.WriteResponse]: + ) -> Awaitable[AsyncIterable[firestore.WriteResponse]]: r"""Streams batches of document updates and deletes, in order. @@ -928,7 +975,7 @@ def listen( retry: retries.Retry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), - ) -> AsyncIterable[firestore.ListenResponse]: + ) -> Awaitable[AsyncIterable[firestore.ListenResponse]]: r"""Listens to changes. Args: @@ -957,9 +1004,9 @@ def listen( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=86400.0, @@ -1018,7 +1065,8 @@ async def list_collection_ids( # Create or coerce a protobuf request object. # Sanity check: If we got a request object, we should *not* have # gotten any keyword arguments that map to the request. - if request is not None and any([parent]): + has_flattened_params = any([parent]) + if request is not None and has_flattened_params: raise ValueError( "If the `request` argument is set, then none of " "the individual field arguments should be set." @@ -1041,9 +1089,9 @@ async def list_collection_ids( maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, diff --git a/google/cloud/firestore_v1/services/firestore/client.py b/google/cloud/firestore_v1/services/firestore/client.py index 527ba3c6a..88355df98 100644 --- a/google/cloud/firestore_v1/services/firestore/client.py +++ b/google/cloud/firestore_v1/services/firestore/client.py @@ -153,6 +153,74 @@ def from_service_account_file(cls, filename: str, *args, **kwargs): from_service_account_json = from_service_account_file + @property + def transport(self) -> FirestoreTransport: + """Return the transport used by the client instance. + + Returns: + FirestoreTransport: The transport used by the client instance. + """ + return self._transport + + @staticmethod + def common_billing_account_path(billing_account: str,) -> str: + """Return a fully-qualified billing_account string.""" + return "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + + @staticmethod + def parse_common_billing_account_path(path: str) -> Dict[str, str]: + """Parse a billing_account path into its component segments.""" + m = re.match(r"^billingAccounts/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_folder_path(folder: str,) -> str: + """Return a fully-qualified folder string.""" + return "folders/{folder}".format(folder=folder,) + + @staticmethod + def parse_common_folder_path(path: str) -> Dict[str, str]: + """Parse a folder path into its component segments.""" + m = re.match(r"^folders/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_organization_path(organization: str,) -> str: + """Return a fully-qualified organization string.""" + return "organizations/{organization}".format(organization=organization,) + + @staticmethod + def parse_common_organization_path(path: str) -> Dict[str, str]: + """Parse a organization path into its component segments.""" + m = re.match(r"^organizations/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_project_path(project: str,) -> str: + """Return a fully-qualified project string.""" + return "projects/{project}".format(project=project,) + + @staticmethod + def parse_common_project_path(path: str) -> Dict[str, str]: + """Parse a project path into its component segments.""" + m = re.match(r"^projects/(?P.+?)$", path) + return m.groupdict() if m else {} + + @staticmethod + def common_location_path(project: str, location: str,) -> str: + """Return a fully-qualified location string.""" + return "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + + @staticmethod + def parse_common_location_path(path: str) -> Dict[str, str]: + """Parse a location path into its component segments.""" + m = re.match(r"^projects/(?P.+?)/locations/(?P.+?)$", path) + return m.groupdict() if m else {} + def __init__( self, *, @@ -188,10 +256,10 @@ def __init__( not provided, the default SSL client certificate will be used if present. If GOOGLE_API_USE_CLIENT_CERTIFICATE is "false" or not set, no client certificate will be used. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -733,8 +801,9 @@ def commit( if database is not None: request.database = database - if writes is not None: - request.writes = writes + + if writes: + request.writes.extend(writes) # Wrap the RPC method; this adds retry and timeout information, # and friendly error handling. diff --git a/google/cloud/firestore_v1/services/firestore/transports/base.py b/google/cloud/firestore_v1/services/firestore/transports/base.py index 2fb5d0143..6a0e3a7d3 100644 --- a/google/cloud/firestore_v1/services/firestore/transports/base.py +++ b/google/cloud/firestore_v1/services/firestore/transports/base.py @@ -117,9 +117,9 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, @@ -132,9 +132,9 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, @@ -158,9 +158,9 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, @@ -173,9 +173,9 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=300.0, @@ -188,9 +188,9 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, @@ -214,9 +214,9 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, @@ -229,9 +229,9 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=300.0, @@ -244,9 +244,9 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=300.0, @@ -262,9 +262,9 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=86400.0, @@ -277,9 +277,9 @@ def _prep_wrapped_messages(self, client_info): maximum=60.0, multiplier=1.3, predicate=retries.if_exception_type( + exceptions.DeadlineExceeded, exceptions.InternalServerError, exceptions.ServiceUnavailable, - exceptions.DeadlineExceeded, ), ), default_timeout=60.0, diff --git a/google/cloud/firestore_v1/services/firestore/transports/grpc.py b/google/cloud/firestore_v1/services/firestore/transports/grpc.py index 417ae59c8..7e06e6321 100644 --- a/google/cloud/firestore_v1/services/firestore/transports/grpc.py +++ b/google/cloud/firestore_v1/services/firestore/transports/grpc.py @@ -99,10 +99,10 @@ def __init__( for grpc channel. It is ignored if ``channel`` is provided. quota_project_id (Optional[str]): An optional project to use for billing and quota. - client_info (google.api_core.gapic_v1.client_info.ClientInfo): - The client info used to send a user-agent string along with - API requests. If ``None``, then default info will be used. - Generally, you only need to set this if you're developing + client_info (google.api_core.gapic_v1.client_info.ClientInfo): + The client info used to send a user-agent string along with + API requests. If ``None``, then default info will be used. + Generally, you only need to set this if you're developing your own client library. Raises: @@ -111,6 +111,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -118,6 +120,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -154,6 +157,7 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" @@ -231,12 +235,8 @@ def create_channel( @property def grpc_channel(self) -> grpc.Channel: - """Create the channel designed to connect to this service. - - This property caches on the instance; repeated calls return - the same channel. + """Return the channel designed to connect to this service. """ - # Return the channel from cache. return self._grpc_channel @property 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 986044949..9088560d7 100644 --- a/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py +++ b/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py @@ -156,6 +156,8 @@ def __init__( google.api_core.exceptions.DuplicateCredentialArgs: If both ``credentials`` and ``credentials_file`` are passed. """ + self._ssl_channel_credentials = ssl_channel_credentials + if channel: # Sanity check: Ensure that channel and credentials are not both # provided. @@ -163,6 +165,7 @@ def __init__( # If a channel was explicitly provided, set it. self._grpc_channel = channel + self._ssl_channel_credentials = None elif api_mtls_endpoint: warnings.warn( "api_mtls_endpoint and client_cert_source are deprecated", @@ -199,6 +202,7 @@ def __init__( scopes=scopes or self.AUTH_SCOPES, quota_project_id=quota_project_id, ) + self._ssl_channel_credentials = ssl_credentials else: host = host if ":" in host else host + ":443" diff --git a/google/cloud/firestore_v1/types/document.py b/google/cloud/firestore_v1/types/document.py index 7104bfc61..2f3b2759a 100644 --- a/google/cloud/firestore_v1/types/document.py +++ b/google/cloud/firestore_v1/types/document.py @@ -172,7 +172,7 @@ class ArrayValue(proto.Message): Values in the array. """ - values = proto.RepeatedField(proto.MESSAGE, number=1, message=Value,) + values = proto.RepeatedField(proto.MESSAGE, number=1, message="Value",) class MapValue(proto.Message): @@ -189,7 +189,7 @@ class MapValue(proto.Message): bytes and cannot be empty. """ - fields = proto.MapField(proto.STRING, proto.MESSAGE, number=1, message=Value,) + fields = proto.MapField(proto.STRING, proto.MESSAGE, number=1, message="Value",) __all__ = tuple(sorted(__protobuf__.manifest)) diff --git a/noxfile.py b/noxfile.py index e5e398e6c..31b1a2ee4 100644 --- a/noxfile.py +++ b/noxfile.py @@ -28,8 +28,8 @@ BLACK_PATHS = ["docs", "google", "tests", "noxfile.py", "setup.py"] DEFAULT_PYTHON_VERSION = "3.8" -SYSTEM_TEST_PYTHON_VERSIONS = ["3.8"] -UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8", "3.9"] +SYSTEM_TEST_PYTHON_VERSIONS = ["3.7"] +UNIT_TEST_PYTHON_VERSIONS = ["3.6", "3.7", "3.8"] @nox.session(python=DEFAULT_PYTHON_VERSION) diff --git a/scripts/fixup_firestore_admin_v1_keywords.py b/scripts/fixup_firestore_admin_v1_keywords.py index e9341f047..18985c924 100644 --- a/scripts/fixup_firestore_admin_v1_keywords.py +++ b/scripts/fixup_firestore_admin_v1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/scripts/fixup_firestore_v1_keywords.py b/scripts/fixup_firestore_v1_keywords.py index 374b94162..9e3e6fba1 100644 --- a/scripts/fixup_firestore_v1_keywords.py +++ b/scripts/fixup_firestore_v1_keywords.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python3 # -*- coding: utf-8 -*- # Copyright 2020 Google LLC diff --git a/synth.metadata b/synth.metadata index a4626e30c..cd1802865 100644 --- a/synth.metadata +++ b/synth.metadata @@ -3,23 +3,23 @@ { "git": { "name": ".", - "remote": "https://github.com/googleapis/python-firestore.git", - "sha": "75d0a4821b09c3bed710353cf86082e41c28191f" + "remote": "git@github.com:googleapis/python-firestore", + "sha": "ab19546ee96c69f46519764a3fb0eb4bea4fc6f8" } }, { "git": { "name": "googleapis", "remote": "https://github.com/googleapis/googleapis.git", - "sha": "2131e2f755b3c2604e2d08de81a299fd7e377dcd", - "internalRef": "338527875" + "sha": "0c9e3f8cb3a0c75983fe9a7897f0ef048d81e999", + "internalRef": "342123525" } }, { "git": { "name": "synthtool", "remote": "https://github.com/googleapis/synthtool.git", - "sha": "6542bd723403513626f61642fc02ddca528409aa" + "sha": "e89175cf074dccc4babb4eca66ae913696e47a71" } } ], 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 6773457e9..093662c49 100644 --- a/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py +++ b/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py @@ -108,12 +108,12 @@ def test_firestore_admin_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "firestore.googleapis.com:443" + assert client.transport._host == "firestore.googleapis.com:443" def test_firestore_admin_client_get_transport_class(): @@ -463,7 +463,7 @@ def test_create_index( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_index), "__call__") as call: + with mock.patch.object(type(client.transport.create_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -484,19 +484,19 @@ def test_create_index_from_dict(): @pytest.mark.asyncio -async def test_create_index_async(transport: str = "grpc_asyncio"): +async def test_create_index_async( + transport: str = "grpc_asyncio", request_type=firestore_admin.CreateIndexRequest +): client = FirestoreAdminAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore_admin.CreateIndexRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_index), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -508,12 +508,17 @@ async def test_create_index_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore_admin.CreateIndexRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_create_index_async_from_dict(): + await test_create_index_async(request_type=dict) + + def test_create_index_field_headers(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) @@ -523,7 +528,7 @@ def test_create_index_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_index), "__call__") as call: + with mock.patch.object(type(client.transport.create_index), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.create_index(request) @@ -548,9 +553,7 @@ async def test_create_index_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_index), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_index), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -571,7 +574,7 @@ def test_create_index_flattened(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_index), "__call__") as call: + with mock.patch.object(type(client.transport.create_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -609,9 +612,7 @@ async def test_create_index_flattened_async(): client = FirestoreAdminAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_index), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -660,7 +661,7 @@ def test_list_indexes( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_indexes), "__call__") as call: + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore_admin.ListIndexesResponse( next_page_token="next_page_token_value", @@ -675,6 +676,7 @@ def test_list_indexes( assert args[0] == firestore_admin.ListIndexesRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListIndexesPager) assert response.next_page_token == "next_page_token_value" @@ -685,19 +687,19 @@ def test_list_indexes_from_dict(): @pytest.mark.asyncio -async def test_list_indexes_async(transport: str = "grpc_asyncio"): +async def test_list_indexes_async( + transport: str = "grpc_asyncio", request_type=firestore_admin.ListIndexesRequest +): client = FirestoreAdminAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore_admin.ListIndexesRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_indexes), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore_admin.ListIndexesResponse( @@ -711,7 +713,7 @@ async def test_list_indexes_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore_admin.ListIndexesRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListIndexesAsyncPager) @@ -719,6 +721,11 @@ async def test_list_indexes_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_indexes_async_from_dict(): + await test_list_indexes_async(request_type=dict) + + def test_list_indexes_field_headers(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) @@ -728,7 +735,7 @@ def test_list_indexes_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_indexes), "__call__") as call: + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: call.return_value = firestore_admin.ListIndexesResponse() client.list_indexes(request) @@ -753,9 +760,7 @@ async def test_list_indexes_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_indexes), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore_admin.ListIndexesResponse() ) @@ -776,7 +781,7 @@ def test_list_indexes_flattened(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_indexes), "__call__") as call: + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore_admin.ListIndexesResponse() @@ -808,9 +813,7 @@ async def test_list_indexes_flattened_async(): client = FirestoreAdminAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_indexes), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore_admin.ListIndexesResponse() @@ -845,7 +848,7 @@ def test_list_indexes_pager(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_indexes), "__call__") as call: + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( firestore_admin.ListIndexesResponse( @@ -879,7 +882,7 @@ def test_list_indexes_pages(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_indexes), "__call__") as call: + with mock.patch.object(type(client.transport.list_indexes), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( firestore_admin.ListIndexesResponse( @@ -906,9 +909,7 @@ async def test_list_indexes_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_indexes), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_indexes), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -941,9 +942,7 @@ async def test_list_indexes_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_indexes), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_indexes), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -979,7 +978,7 @@ def test_get_index( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_index), "__call__") as call: + with mock.patch.object(type(client.transport.get_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = index.Index( name="name_value", @@ -996,6 +995,7 @@ def test_get_index( assert args[0] == firestore_admin.GetIndexRequest() # Establish that the response is the type that we expect. + assert isinstance(response, index.Index) assert response.name == "name_value" @@ -1010,19 +1010,19 @@ def test_get_index_from_dict(): @pytest.mark.asyncio -async def test_get_index_async(transport: str = "grpc_asyncio"): +async def test_get_index_async( + transport: str = "grpc_asyncio", request_type=firestore_admin.GetIndexRequest +): client = FirestoreAdminAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore_admin.GetIndexRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_index), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( index.Index( @@ -1038,7 +1038,7 @@ async def test_get_index_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore_admin.GetIndexRequest() # Establish that the response is the type that we expect. assert isinstance(response, index.Index) @@ -1050,6 +1050,11 @@ async def test_get_index_async(transport: str = "grpc_asyncio"): assert response.state == index.Index.State.CREATING +@pytest.mark.asyncio +async def test_get_index_async_from_dict(): + await test_get_index_async(request_type=dict) + + def test_get_index_field_headers(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) @@ -1059,7 +1064,7 @@ def test_get_index_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_index), "__call__") as call: + with mock.patch.object(type(client.transport.get_index), "__call__") as call: call.return_value = index.Index() client.get_index(request) @@ -1084,9 +1089,7 @@ async def test_get_index_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_index), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_index), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(index.Index()) await client.get_index(request) @@ -1105,7 +1108,7 @@ def test_get_index_flattened(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_index), "__call__") as call: + with mock.patch.object(type(client.transport.get_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = index.Index() @@ -1137,9 +1140,7 @@ async def test_get_index_flattened_async(): client = FirestoreAdminAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_index), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = index.Index() @@ -1180,7 +1181,7 @@ def test_delete_index( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_index), "__call__") as call: + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1201,19 +1202,19 @@ def test_delete_index_from_dict(): @pytest.mark.asyncio -async def test_delete_index_async(transport: str = "grpc_asyncio"): +async def test_delete_index_async( + transport: str = "grpc_asyncio", request_type=firestore_admin.DeleteIndexRequest +): client = FirestoreAdminAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore_admin.DeleteIndexRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_index), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1223,12 +1224,17 @@ async def test_delete_index_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore_admin.DeleteIndexRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_index_async_from_dict(): + await test_delete_index_async(request_type=dict) + + def test_delete_index_field_headers(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) @@ -1238,7 +1244,7 @@ def test_delete_index_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_index), "__call__") as call: + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: call.return_value = None client.delete_index(request) @@ -1263,9 +1269,7 @@ async def test_delete_index_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_index), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_index(request) @@ -1284,7 +1288,7 @@ def test_delete_index_flattened(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_index), "__call__") as call: + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1316,9 +1320,7 @@ async def test_delete_index_flattened_async(): client = FirestoreAdminAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_index), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_index), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1359,7 +1361,7 @@ def test_get_field( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_field), "__call__") as call: + with mock.patch.object(type(client.transport.get_field), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = field.Field(name="name_value",) @@ -1372,6 +1374,7 @@ def test_get_field( assert args[0] == firestore_admin.GetFieldRequest() # Establish that the response is the type that we expect. + assert isinstance(response, field.Field) assert response.name == "name_value" @@ -1382,19 +1385,19 @@ def test_get_field_from_dict(): @pytest.mark.asyncio -async def test_get_field_async(transport: str = "grpc_asyncio"): +async def test_get_field_async( + transport: str = "grpc_asyncio", request_type=firestore_admin.GetFieldRequest +): client = FirestoreAdminAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore_admin.GetFieldRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_field), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_field), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( field.Field(name="name_value",) @@ -1406,7 +1409,7 @@ async def test_get_field_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore_admin.GetFieldRequest() # Establish that the response is the type that we expect. assert isinstance(response, field.Field) @@ -1414,6 +1417,11 @@ async def test_get_field_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_get_field_async_from_dict(): + await test_get_field_async(request_type=dict) + + def test_get_field_field_headers(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) @@ -1423,7 +1431,7 @@ def test_get_field_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_field), "__call__") as call: + with mock.patch.object(type(client.transport.get_field), "__call__") as call: call.return_value = field.Field() client.get_field(request) @@ -1448,9 +1456,7 @@ async def test_get_field_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_field), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_field), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(field.Field()) await client.get_field(request) @@ -1469,7 +1475,7 @@ def test_get_field_flattened(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_field), "__call__") as call: + with mock.patch.object(type(client.transport.get_field), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = field.Field() @@ -1501,9 +1507,7 @@ async def test_get_field_flattened_async(): client = FirestoreAdminAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_field), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_field), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = field.Field() @@ -1544,7 +1548,7 @@ def test_update_field( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_field), "__call__") as call: + with mock.patch.object(type(client.transport.update_field), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -1565,19 +1569,19 @@ def test_update_field_from_dict(): @pytest.mark.asyncio -async def test_update_field_async(transport: str = "grpc_asyncio"): +async def test_update_field_async( + transport: str = "grpc_asyncio", request_type=firestore_admin.UpdateFieldRequest +): client = FirestoreAdminAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore_admin.UpdateFieldRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_field), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_field), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -1589,12 +1593,17 @@ async def test_update_field_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore_admin.UpdateFieldRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_update_field_async_from_dict(): + await test_update_field_async(request_type=dict) + + def test_update_field_field_headers(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) @@ -1604,7 +1613,7 @@ def test_update_field_field_headers(): request.field.name = "field.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_field), "__call__") as call: + with mock.patch.object(type(client.transport.update_field), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.update_field(request) @@ -1629,9 +1638,7 @@ async def test_update_field_field_headers_async(): request.field.name = "field.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_field), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_field), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -1652,7 +1659,7 @@ def test_update_field_flattened(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_field), "__call__") as call: + with mock.patch.object(type(client.transport.update_field), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1685,9 +1692,7 @@ async def test_update_field_flattened_async(): client = FirestoreAdminAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_field), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_field), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -1731,7 +1736,7 @@ def test_list_fields( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_fields), "__call__") as call: + with mock.patch.object(type(client.transport.list_fields), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore_admin.ListFieldsResponse( next_page_token="next_page_token_value", @@ -1746,6 +1751,7 @@ def test_list_fields( assert args[0] == firestore_admin.ListFieldsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListFieldsPager) assert response.next_page_token == "next_page_token_value" @@ -1756,19 +1762,19 @@ def test_list_fields_from_dict(): @pytest.mark.asyncio -async def test_list_fields_async(transport: str = "grpc_asyncio"): +async def test_list_fields_async( + transport: str = "grpc_asyncio", request_type=firestore_admin.ListFieldsRequest +): client = FirestoreAdminAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore_admin.ListFieldsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_fields), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_fields), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore_admin.ListFieldsResponse(next_page_token="next_page_token_value",) @@ -1780,7 +1786,7 @@ async def test_list_fields_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore_admin.ListFieldsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListFieldsAsyncPager) @@ -1788,6 +1794,11 @@ async def test_list_fields_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_fields_async_from_dict(): + await test_list_fields_async(request_type=dict) + + def test_list_fields_field_headers(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) @@ -1797,7 +1808,7 @@ def test_list_fields_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_fields), "__call__") as call: + with mock.patch.object(type(client.transport.list_fields), "__call__") as call: call.return_value = firestore_admin.ListFieldsResponse() client.list_fields(request) @@ -1822,9 +1833,7 @@ async def test_list_fields_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_fields), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_fields), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore_admin.ListFieldsResponse() ) @@ -1845,7 +1854,7 @@ def test_list_fields_flattened(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_fields), "__call__") as call: + with mock.patch.object(type(client.transport.list_fields), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore_admin.ListFieldsResponse() @@ -1877,9 +1886,7 @@ async def test_list_fields_flattened_async(): client = FirestoreAdminAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_fields), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_fields), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore_admin.ListFieldsResponse() @@ -1914,7 +1921,7 @@ def test_list_fields_pager(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_fields), "__call__") as call: + with mock.patch.object(type(client.transport.list_fields), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( firestore_admin.ListFieldsResponse( @@ -1946,7 +1953,7 @@ def test_list_fields_pages(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_fields), "__call__") as call: + with mock.patch.object(type(client.transport.list_fields), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( firestore_admin.ListFieldsResponse( @@ -1971,9 +1978,7 @@ async def test_list_fields_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_fields), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_fields), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2004,9 +2009,7 @@ async def test_list_fields_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_fields), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_fields), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2040,9 +2043,7 @@ def test_export_documents( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.export_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_documents), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -2063,19 +2064,19 @@ def test_export_documents_from_dict(): @pytest.mark.asyncio -async def test_export_documents_async(transport: str = "grpc_asyncio"): +async def test_export_documents_async( + transport: str = "grpc_asyncio", request_type=firestore_admin.ExportDocumentsRequest +): client = FirestoreAdminAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore_admin.ExportDocumentsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_documents), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -2087,12 +2088,17 @@ async def test_export_documents_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore_admin.ExportDocumentsRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_export_documents_async_from_dict(): + await test_export_documents_async(request_type=dict) + + def test_export_documents_field_headers(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) @@ -2102,9 +2108,7 @@ def test_export_documents_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.export_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_documents), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.export_documents(request) @@ -2129,9 +2133,7 @@ async def test_export_documents_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_documents), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -2152,9 +2154,7 @@ def test_export_documents_flattened(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.export_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_documents), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2186,9 +2186,7 @@ async def test_export_documents_flattened_async(): client = FirestoreAdminAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.export_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.export_documents), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2231,9 +2229,7 @@ def test_import_documents( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.import_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_documents), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/spam") @@ -2254,19 +2250,19 @@ def test_import_documents_from_dict(): @pytest.mark.asyncio -async def test_import_documents_async(transport: str = "grpc_asyncio"): +async def test_import_documents_async( + transport: str = "grpc_asyncio", request_type=firestore_admin.ImportDocumentsRequest +): client = FirestoreAdminAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore_admin.ImportDocumentsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_documents), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/spam") @@ -2278,12 +2274,17 @@ async def test_import_documents_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore_admin.ImportDocumentsRequest() # Establish that the response is the type that we expect. assert isinstance(response, future.Future) +@pytest.mark.asyncio +async def test_import_documents_async_from_dict(): + await test_import_documents_async(request_type=dict) + + def test_import_documents_field_headers(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) @@ -2293,9 +2294,7 @@ def test_import_documents_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.import_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_documents), "__call__") as call: call.return_value = operations_pb2.Operation(name="operations/op") client.import_documents(request) @@ -2320,9 +2319,7 @@ async def test_import_documents_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_documents), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( operations_pb2.Operation(name="operations/op") ) @@ -2343,9 +2340,7 @@ def test_import_documents_flattened(): client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._transport.import_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_documents), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2377,9 +2372,7 @@ async def test_import_documents_flattened_async(): client = FirestoreAdminAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.import_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.import_documents), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = operations_pb2.Operation(name="operations/op") @@ -2446,7 +2439,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = FirestoreAdminClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -2482,7 +2475,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = FirestoreAdminClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.FirestoreAdminGrpcTransport,) + assert isinstance(client.transport, transports.FirestoreAdminGrpcTransport,) def test_firestore_admin_base_transport_error(): @@ -2598,7 +2591,7 @@ def test_firestore_admin_host_no_port(): api_endpoint="firestore.googleapis.com" ), ) - assert client._transport._host == "firestore.googleapis.com:443" + assert client.transport._host == "firestore.googleapis.com:443" def test_firestore_admin_host_with_port(): @@ -2608,7 +2601,7 @@ def test_firestore_admin_host_with_port(): api_endpoint="firestore.googleapis.com:8000" ), ) - assert client._transport._host == "firestore.googleapis.com:8000" + assert client.transport._host == "firestore.googleapis.com:8000" def test_firestore_admin_grpc_transport_channel(): @@ -2620,6 +2613,7 @@ def test_firestore_admin_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_firestore_admin_grpc_asyncio_transport_channel(): @@ -2631,6 +2625,7 @@ def test_firestore_admin_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -2681,6 +2676,7 @@ def test_firestore_admin_transport_channel_mtls_with_client_cert_source( quota_project_id=None, ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -2730,7 +2726,7 @@ def test_firestore_admin_grpc_lro_client(): client = FirestoreAdminClient( credentials=credentials.AnonymousCredentials(), transport="grpc", ) - transport = client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsClient,) @@ -2743,7 +2739,7 @@ def test_firestore_admin_grpc_lro_async_client(): client = FirestoreAdminAsyncClient( credentials=credentials.AnonymousCredentials(), transport="grpc_asyncio", ) - transport = client._client._transport + transport = client.transport # Ensure that we have a api-core operations client. assert isinstance(transport.operations_client, operations_v1.OperationsAsyncClient,) @@ -2752,11 +2748,59 @@ def test_firestore_admin_grpc_lro_async_client(): assert transport.operations_client is transport.operations_client -def test_field_path(): +def test_collection_group_path(): project = "squid" database = "clam" collection = "whelk" - field = "octopus" + + expected = "projects/{project}/databases/{database}/collectionGroups/{collection}".format( + project=project, database=database, collection=collection, + ) + actual = FirestoreAdminClient.collection_group_path(project, database, collection) + assert expected == actual + + +def test_parse_collection_group_path(): + expected = { + "project": "octopus", + "database": "oyster", + "collection": "nudibranch", + } + path = FirestoreAdminClient.collection_group_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreAdminClient.parse_collection_group_path(path) + assert expected == actual + + +def test_database_path(): + project = "cuttlefish" + database = "mussel" + + expected = "projects/{project}/databases/{database}".format( + project=project, database=database, + ) + actual = FirestoreAdminClient.database_path(project, database) + assert expected == actual + + +def test_parse_database_path(): + expected = { + "project": "winkle", + "database": "nautilus", + } + path = FirestoreAdminClient.database_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreAdminClient.parse_database_path(path) + assert expected == actual + + +def test_field_path(): + project = "scallop" + database = "abalone" + collection = "squid" + field = "clam" expected = "projects/{project}/databases/{database}/collectionGroups/{collection}/fields/{field}".format( project=project, database=database, collection=collection, field=field, @@ -2767,10 +2811,10 @@ def test_field_path(): def test_parse_field_path(): expected = { - "project": "oyster", - "database": "nudibranch", - "collection": "cuttlefish", - "field": "mussel", + "project": "whelk", + "database": "octopus", + "collection": "oyster", + "field": "nudibranch", } path = FirestoreAdminClient.field_path(**expected) @@ -2780,10 +2824,10 @@ def test_parse_field_path(): def test_index_path(): - project = "squid" - database = "clam" - collection = "whelk" - index = "octopus" + project = "cuttlefish" + database = "mussel" + collection = "winkle" + index = "nautilus" expected = "projects/{project}/databases/{database}/collectionGroups/{collection}/indexes/{index}".format( project=project, database=database, collection=collection, index=index, @@ -2794,10 +2838,10 @@ def test_index_path(): def test_parse_index_path(): expected = { - "project": "oyster", - "database": "nudibranch", - "collection": "cuttlefish", - "index": "mussel", + "project": "scallop", + "database": "abalone", + "collection": "squid", + "index": "clam", } path = FirestoreAdminClient.index_path(**expected) @@ -2806,6 +2850,107 @@ def test_parse_index_path(): assert expected == actual +def test_common_billing_account_path(): + billing_account = "whelk" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = FirestoreAdminClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "octopus", + } + path = FirestoreAdminClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreAdminClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "oyster" + + expected = "folders/{folder}".format(folder=folder,) + actual = FirestoreAdminClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "nudibranch", + } + path = FirestoreAdminClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreAdminClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "cuttlefish" + + expected = "organizations/{organization}".format(organization=organization,) + actual = FirestoreAdminClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "mussel", + } + path = FirestoreAdminClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreAdminClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "winkle" + + expected = "projects/{project}".format(project=project,) + actual = FirestoreAdminClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "nautilus", + } + path = FirestoreAdminClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreAdminClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "scallop" + location = "abalone" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + actual = FirestoreAdminClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "squid", + "location": "clam", + } + path = FirestoreAdminClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreAdminClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo() diff --git a/tests/unit/gapic/firestore_v1/test_firestore.py b/tests/unit/gapic/firestore_v1/test_firestore.py index 7b20d5a37..13891e602 100644 --- a/tests/unit/gapic/firestore_v1/test_firestore.py +++ b/tests/unit/gapic/firestore_v1/test_firestore.py @@ -41,7 +41,6 @@ from google.cloud.firestore_v1.types import document as gf_document from google.cloud.firestore_v1.types import firestore from google.cloud.firestore_v1.types import query -from google.cloud.firestore_v1.types import write from google.cloud.firestore_v1.types import write as gf_write from google.oauth2 import service_account from google.protobuf import struct_pb2 as struct # type: ignore @@ -98,12 +97,12 @@ def test_firestore_client_from_service_account_file(client_class): ) as factory: factory.return_value = creds client = client_class.from_service_account_file("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds client = client_class.from_service_account_json("dummy/file/path.json") - assert client._transport._credentials == creds + assert client.transport._credentials == creds - assert client._transport._host == "firestore.googleapis.com:443" + assert client.transport._host == "firestore.googleapis.com:443" def test_firestore_client_get_transport_class(): @@ -445,7 +444,7 @@ def test_get_document( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_document), "__call__") as call: + with mock.patch.object(type(client.transport.get_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = document.Document(name="name_value",) @@ -458,6 +457,7 @@ def test_get_document( assert args[0] == firestore.GetDocumentRequest() # Establish that the response is the type that we expect. + assert isinstance(response, document.Document) assert response.name == "name_value" @@ -468,19 +468,19 @@ def test_get_document_from_dict(): @pytest.mark.asyncio -async def test_get_document_async(transport: str = "grpc_asyncio"): +async def test_get_document_async( + transport: str = "grpc_asyncio", request_type=firestore.GetDocumentRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.GetDocumentRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_document), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( document.Document(name="name_value",) @@ -492,7 +492,7 @@ async def test_get_document_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.GetDocumentRequest() # Establish that the response is the type that we expect. assert isinstance(response, document.Document) @@ -500,6 +500,11 @@ async def test_get_document_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_get_document_async_from_dict(): + await test_get_document_async(request_type=dict) + + def test_get_document_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -509,7 +514,7 @@ def test_get_document_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.get_document), "__call__") as call: + with mock.patch.object(type(client.transport.get_document), "__call__") as call: call.return_value = document.Document() client.get_document(request) @@ -534,9 +539,7 @@ async def test_get_document_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.get_document), "__call__" - ) as call: + with mock.patch.object(type(client.transport.get_document), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document.Document()) await client.get_document(request) @@ -563,7 +566,7 @@ def test_list_documents( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_documents), "__call__") as call: + with mock.patch.object(type(client.transport.list_documents), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore.ListDocumentsResponse( next_page_token="next_page_token_value", @@ -578,6 +581,7 @@ def test_list_documents( assert args[0] == firestore.ListDocumentsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListDocumentsPager) assert response.next_page_token == "next_page_token_value" @@ -588,19 +592,19 @@ def test_list_documents_from_dict(): @pytest.mark.asyncio -async def test_list_documents_async(transport: str = "grpc_asyncio"): +async def test_list_documents_async( + transport: str = "grpc_asyncio", request_type=firestore.ListDocumentsRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.ListDocumentsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_documents), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore.ListDocumentsResponse(next_page_token="next_page_token_value",) @@ -612,7 +616,7 @@ async def test_list_documents_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.ListDocumentsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListDocumentsAsyncPager) @@ -620,6 +624,11 @@ async def test_list_documents_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_documents_async_from_dict(): + await test_list_documents_async(request_type=dict) + + def test_list_documents_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -629,7 +638,7 @@ def test_list_documents_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_documents), "__call__") as call: + with mock.patch.object(type(client.transport.list_documents), "__call__") as call: call.return_value = firestore.ListDocumentsResponse() client.list_documents(request) @@ -654,9 +663,7 @@ async def test_list_documents_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.list_documents), "__call__" - ) as call: + with mock.patch.object(type(client.transport.list_documents), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore.ListDocumentsResponse() ) @@ -677,7 +684,7 @@ def test_list_documents_pager(): client = FirestoreClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_documents), "__call__") as call: + with mock.patch.object(type(client.transport.list_documents), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( firestore.ListDocumentsResponse( @@ -715,7 +722,7 @@ def test_list_documents_pages(): client = FirestoreClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.list_documents), "__call__") as call: + with mock.patch.object(type(client.transport.list_documents), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( firestore.ListDocumentsResponse( @@ -746,9 +753,7 @@ async def test_list_documents_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_documents), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_documents), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -785,9 +790,7 @@ async def test_list_documents_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_documents), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.list_documents), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -827,7 +830,7 @@ def test_update_document( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_document), "__call__") as call: + with mock.patch.object(type(client.transport.update_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gf_document.Document(name="name_value",) @@ -840,6 +843,7 @@ def test_update_document( assert args[0] == firestore.UpdateDocumentRequest() # Establish that the response is the type that we expect. + assert isinstance(response, gf_document.Document) assert response.name == "name_value" @@ -850,19 +854,19 @@ def test_update_document_from_dict(): @pytest.mark.asyncio -async def test_update_document_async(transport: str = "grpc_asyncio"): +async def test_update_document_async( + transport: str = "grpc_asyncio", request_type=firestore.UpdateDocumentRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.UpdateDocumentRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_document), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gf_document.Document(name="name_value",) @@ -874,7 +878,7 @@ async def test_update_document_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.UpdateDocumentRequest() # Establish that the response is the type that we expect. assert isinstance(response, gf_document.Document) @@ -882,6 +886,11 @@ async def test_update_document_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_update_document_async_from_dict(): + await test_update_document_async(request_type=dict) + + def test_update_document_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -891,7 +900,7 @@ def test_update_document_field_headers(): request.document.name = "document.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_document), "__call__") as call: + with mock.patch.object(type(client.transport.update_document), "__call__") as call: call.return_value = gf_document.Document() client.update_document(request) @@ -918,9 +927,7 @@ async def test_update_document_field_headers_async(): request.document.name = "document.name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_document), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_document), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( gf_document.Document() ) @@ -943,7 +950,7 @@ def test_update_document_flattened(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.update_document), "__call__") as call: + with mock.patch.object(type(client.transport.update_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gf_document.Document() @@ -984,9 +991,7 @@ async def test_update_document_flattened_async(): client = FirestoreAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.update_document), "__call__" - ) as call: + with mock.patch.object(type(client.transport.update_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = gf_document.Document() @@ -1038,7 +1043,7 @@ def test_delete_document( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_document), "__call__") as call: + with mock.patch.object(type(client.transport.delete_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1059,19 +1064,19 @@ def test_delete_document_from_dict(): @pytest.mark.asyncio -async def test_delete_document_async(transport: str = "grpc_asyncio"): +async def test_delete_document_async( + transport: str = "grpc_asyncio", request_type=firestore.DeleteDocumentRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.DeleteDocumentRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_document), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1081,12 +1086,17 @@ async def test_delete_document_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.DeleteDocumentRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_delete_document_async_from_dict(): + await test_delete_document_async(request_type=dict) + + def test_delete_document_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -1096,7 +1106,7 @@ def test_delete_document_field_headers(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_document), "__call__") as call: + with mock.patch.object(type(client.transport.delete_document), "__call__") as call: call.return_value = None client.delete_document(request) @@ -1121,9 +1131,7 @@ async def test_delete_document_field_headers_async(): request.name = "name/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_document), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_document), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.delete_document(request) @@ -1142,7 +1150,7 @@ def test_delete_document_flattened(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.delete_document), "__call__") as call: + with mock.patch.object(type(client.transport.delete_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1174,9 +1182,7 @@ async def test_delete_document_flattened_async(): client = FirestoreAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.delete_document), "__call__" - ) as call: + with mock.patch.object(type(client.transport.delete_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1218,7 +1224,7 @@ def test_batch_get_documents( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.batch_get_documents), "__call__" + type(client.transport.batch_get_documents), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = iter([firestore.BatchGetDocumentsResponse()]) @@ -1241,18 +1247,20 @@ def test_batch_get_documents_from_dict(): @pytest.mark.asyncio -async def test_batch_get_documents_async(transport: str = "grpc_asyncio"): +async def test_batch_get_documents_async( + transport: str = "grpc_asyncio", request_type=firestore.BatchGetDocumentsRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.BatchGetDocumentsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.batch_get_documents), "__call__" + type(client.transport.batch_get_documents), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) @@ -1266,13 +1274,18 @@ async def test_batch_get_documents_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.BatchGetDocumentsRequest() # Establish that the response is the type that we expect. message = await response.read() assert isinstance(message, firestore.BatchGetDocumentsResponse) +@pytest.mark.asyncio +async def test_batch_get_documents_async_from_dict(): + await test_batch_get_documents_async(request_type=dict) + + def test_batch_get_documents_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -1283,7 +1296,7 @@ def test_batch_get_documents_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.batch_get_documents), "__call__" + type(client.transport.batch_get_documents), "__call__" ) as call: call.return_value = iter([firestore.BatchGetDocumentsResponse()]) @@ -1310,7 +1323,7 @@ async def test_batch_get_documents_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.batch_get_documents), "__call__" + type(client.transport.batch_get_documents), "__call__" ) as call: call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) call.return_value.read = mock.AsyncMock( @@ -1342,7 +1355,7 @@ def test_begin_transaction( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.begin_transaction), "__call__" + type(client.transport.begin_transaction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = firestore.BeginTransactionResponse( @@ -1358,6 +1371,7 @@ def test_begin_transaction( assert args[0] == firestore.BeginTransactionRequest() # Establish that the response is the type that we expect. + assert isinstance(response, firestore.BeginTransactionResponse) assert response.transaction == b"transaction_blob" @@ -1368,18 +1382,20 @@ def test_begin_transaction_from_dict(): @pytest.mark.asyncio -async def test_begin_transaction_async(transport: str = "grpc_asyncio"): +async def test_begin_transaction_async( + transport: str = "grpc_asyncio", request_type=firestore.BeginTransactionRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.BeginTransactionRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.begin_transaction), "__call__" + type(client.transport.begin_transaction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -1392,7 +1408,7 @@ async def test_begin_transaction_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.BeginTransactionRequest() # Establish that the response is the type that we expect. assert isinstance(response, firestore.BeginTransactionResponse) @@ -1400,6 +1416,11 @@ async def test_begin_transaction_async(transport: str = "grpc_asyncio"): assert response.transaction == b"transaction_blob" +@pytest.mark.asyncio +async def test_begin_transaction_async_from_dict(): + await test_begin_transaction_async(request_type=dict) + + def test_begin_transaction_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -1410,7 +1431,7 @@ def test_begin_transaction_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.begin_transaction), "__call__" + type(client.transport.begin_transaction), "__call__" ) as call: call.return_value = firestore.BeginTransactionResponse() @@ -1437,7 +1458,7 @@ async def test_begin_transaction_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.begin_transaction), "__call__" + type(client.transport.begin_transaction), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore.BeginTransactionResponse() @@ -1460,7 +1481,7 @@ def test_begin_transaction_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.begin_transaction), "__call__" + type(client.transport.begin_transaction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = firestore.BeginTransactionResponse() @@ -1494,7 +1515,7 @@ async def test_begin_transaction_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.begin_transaction), "__call__" + type(client.transport.begin_transaction), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = firestore.BeginTransactionResponse() @@ -1536,7 +1557,7 @@ def test_commit(transport: str = "grpc", request_type=firestore.CommitRequest): request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.commit), "__call__") as call: + with mock.patch.object(type(client.transport.commit), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore.CommitResponse() @@ -1549,6 +1570,7 @@ def test_commit(transport: str = "grpc", request_type=firestore.CommitRequest): assert args[0] == firestore.CommitRequest() # Establish that the response is the type that we expect. + assert isinstance(response, firestore.CommitResponse) @@ -1557,17 +1579,19 @@ def test_commit_from_dict(): @pytest.mark.asyncio -async def test_commit_async(transport: str = "grpc_asyncio"): +async def test_commit_async( + transport: str = "grpc_asyncio", request_type=firestore.CommitRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.CommitRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.commit), "__call__") as call: + with mock.patch.object(type(client.transport.commit), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore.CommitResponse() @@ -1579,12 +1603,17 @@ async def test_commit_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.CommitRequest() # Establish that the response is the type that we expect. assert isinstance(response, firestore.CommitResponse) +@pytest.mark.asyncio +async def test_commit_async_from_dict(): + await test_commit_async(request_type=dict) + + def test_commit_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -1594,7 +1623,7 @@ def test_commit_field_headers(): request.database = "database/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.commit), "__call__") as call: + with mock.patch.object(type(client.transport.commit), "__call__") as call: call.return_value = firestore.CommitResponse() client.commit(request) @@ -1619,7 +1648,7 @@ async def test_commit_field_headers_async(): request.database = "database/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.commit), "__call__") as call: + with mock.patch.object(type(client.transport.commit), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore.CommitResponse() ) @@ -1640,7 +1669,7 @@ def test_commit_flattened(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.commit), "__call__") as call: + with mock.patch.object(type(client.transport.commit), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore.CommitResponse() @@ -1648,7 +1677,7 @@ def test_commit_flattened(): # using the keyword arguments to the method. client.commit( database="database_value", - writes=[gf_write.Write(update=gf_document.Document(name="name_value"))], + writes=[gf_write.Write(update=document.Document(name="name_value"))], ) # Establish that the underlying call was made with the expected @@ -1659,7 +1688,7 @@ def test_commit_flattened(): assert args[0].database == "database_value" assert args[0].writes == [ - gf_write.Write(update=gf_document.Document(name="name_value")) + gf_write.Write(update=document.Document(name="name_value")) ] @@ -1672,7 +1701,7 @@ def test_commit_flattened_error(): client.commit( firestore.CommitRequest(), database="database_value", - writes=[gf_write.Write(update=gf_document.Document(name="name_value"))], + writes=[gf_write.Write(update=document.Document(name="name_value"))], ) @@ -1681,7 +1710,7 @@ async def test_commit_flattened_async(): client = FirestoreAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.commit), "__call__") as call: + with mock.patch.object(type(client.transport.commit), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore.CommitResponse() @@ -1692,7 +1721,7 @@ async def test_commit_flattened_async(): # using the keyword arguments to the method. response = await client.commit( database="database_value", - writes=[gf_write.Write(update=gf_document.Document(name="name_value"))], + writes=[gf_write.Write(update=document.Document(name="name_value"))], ) # Establish that the underlying call was made with the expected @@ -1703,7 +1732,7 @@ async def test_commit_flattened_async(): assert args[0].database == "database_value" assert args[0].writes == [ - gf_write.Write(update=gf_document.Document(name="name_value")) + gf_write.Write(update=document.Document(name="name_value")) ] @@ -1717,7 +1746,7 @@ async def test_commit_flattened_error_async(): await client.commit( firestore.CommitRequest(), database="database_value", - writes=[gf_write.Write(update=gf_document.Document(name="name_value"))], + writes=[gf_write.Write(update=document.Document(name="name_value"))], ) @@ -1731,7 +1760,7 @@ def test_rollback(transport: str = "grpc", request_type=firestore.RollbackReques request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.rollback), "__call__") as call: + with mock.patch.object(type(client.transport.rollback), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1752,19 +1781,19 @@ def test_rollback_from_dict(): @pytest.mark.asyncio -async def test_rollback_async(transport: str = "grpc_asyncio"): +async def test_rollback_async( + transport: str = "grpc_asyncio", request_type=firestore.RollbackRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.RollbackRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.rollback), "__call__" - ) as call: + with mock.patch.object(type(client.transport.rollback), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) @@ -1774,12 +1803,17 @@ async def test_rollback_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.RollbackRequest() # Establish that the response is the type that we expect. assert response is None +@pytest.mark.asyncio +async def test_rollback_async_from_dict(): + await test_rollback_async(request_type=dict) + + def test_rollback_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -1789,7 +1823,7 @@ def test_rollback_field_headers(): request.database = "database/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.rollback), "__call__") as call: + with mock.patch.object(type(client.transport.rollback), "__call__") as call: call.return_value = None client.rollback(request) @@ -1814,9 +1848,7 @@ async def test_rollback_field_headers_async(): request.database = "database/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.rollback), "__call__" - ) as call: + with mock.patch.object(type(client.transport.rollback), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(None) await client.rollback(request) @@ -1835,7 +1867,7 @@ def test_rollback_flattened(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.rollback), "__call__") as call: + with mock.patch.object(type(client.transport.rollback), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1873,9 +1905,7 @@ async def test_rollback_flattened_async(): client = FirestoreAsyncClient(credentials=credentials.AnonymousCredentials(),) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.rollback), "__call__" - ) as call: + with mock.patch.object(type(client.transport.rollback), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = None @@ -1920,7 +1950,7 @@ def test_run_query(transport: str = "grpc", request_type=firestore.RunQueryReque request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.run_query), "__call__") as call: + with mock.patch.object(type(client.transport.run_query), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = iter([firestore.RunQueryResponse()]) @@ -1942,19 +1972,19 @@ def test_run_query_from_dict(): @pytest.mark.asyncio -async def test_run_query_async(transport: str = "grpc_asyncio"): +async def test_run_query_async( + transport: str = "grpc_asyncio", request_type=firestore.RunQueryRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.RunQueryRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.run_query), "__call__" - ) as call: + with mock.patch.object(type(client.transport.run_query), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) call.return_value.read = mock.AsyncMock( @@ -1967,13 +1997,18 @@ async def test_run_query_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.RunQueryRequest() # Establish that the response is the type that we expect. message = await response.read() assert isinstance(message, firestore.RunQueryResponse) +@pytest.mark.asyncio +async def test_run_query_async_from_dict(): + await test_run_query_async(request_type=dict) + + def test_run_query_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -1983,7 +2018,7 @@ def test_run_query_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.run_query), "__call__") as call: + with mock.patch.object(type(client.transport.run_query), "__call__") as call: call.return_value = iter([firestore.RunQueryResponse()]) client.run_query(request) @@ -2008,9 +2043,7 @@ async def test_run_query_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.run_query), "__call__" - ) as call: + with mock.patch.object(type(client.transport.run_query), "__call__") as call: call.return_value = mock.Mock(aio.UnaryStreamCall, autospec=True) call.return_value.read = mock.AsyncMock( side_effect=[firestore.RunQueryResponse()] @@ -2040,7 +2073,7 @@ def test_partition_query( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.partition_query), "__call__") as call: + with mock.patch.object(type(client.transport.partition_query), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore.PartitionQueryResponse( next_page_token="next_page_token_value", @@ -2055,6 +2088,7 @@ def test_partition_query( assert args[0] == firestore.PartitionQueryRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.PartitionQueryPager) assert response.next_page_token == "next_page_token_value" @@ -2065,19 +2099,19 @@ def test_partition_query_from_dict(): @pytest.mark.asyncio -async def test_partition_query_async(transport: str = "grpc_asyncio"): +async def test_partition_query_async( + transport: str = "grpc_asyncio", request_type=firestore.PartitionQueryRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.PartitionQueryRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.partition_query), "__call__" - ) as call: + with mock.patch.object(type(client.transport.partition_query), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore.PartitionQueryResponse(next_page_token="next_page_token_value",) @@ -2089,7 +2123,7 @@ async def test_partition_query_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.PartitionQueryRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.PartitionQueryAsyncPager) @@ -2097,6 +2131,11 @@ async def test_partition_query_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_partition_query_async_from_dict(): + await test_partition_query_async(request_type=dict) + + def test_partition_query_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -2106,7 +2145,7 @@ def test_partition_query_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.partition_query), "__call__") as call: + with mock.patch.object(type(client.transport.partition_query), "__call__") as call: call.return_value = firestore.PartitionQueryResponse() client.partition_query(request) @@ -2131,9 +2170,7 @@ async def test_partition_query_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.partition_query), "__call__" - ) as call: + with mock.patch.object(type(client.transport.partition_query), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore.PartitionQueryResponse() ) @@ -2154,7 +2191,7 @@ def test_partition_query_pager(): client = FirestoreClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.partition_query), "__call__") as call: + with mock.patch.object(type(client.transport.partition_query), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( firestore.PartitionQueryResponse( @@ -2188,7 +2225,7 @@ def test_partition_query_pages(): client = FirestoreClient(credentials=credentials.AnonymousCredentials,) # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.partition_query), "__call__") as call: + with mock.patch.object(type(client.transport.partition_query), "__call__") as call: # Set the response to a series of pages. call.side_effect = ( firestore.PartitionQueryResponse( @@ -2215,9 +2252,7 @@ async def test_partition_query_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.partition_query), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.partition_query), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2250,9 +2285,7 @@ async def test_partition_query_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.partition_query), - "__call__", - new_callable=mock.AsyncMock, + type(client.transport.partition_query), "__call__", new_callable=mock.AsyncMock ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2288,7 +2321,7 @@ def test_write(transport: str = "grpc", request_type=firestore.WriteRequest): requests = [request] # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.write), "__call__") as call: + with mock.patch.object(type(client.transport.write), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = iter([firestore.WriteResponse()]) @@ -2310,19 +2343,21 @@ def test_write_from_dict(): @pytest.mark.asyncio -async def test_write_async(transport: str = "grpc_asyncio"): +async def test_write_async( + transport: str = "grpc_asyncio", request_type=firestore.WriteRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.WriteRequest() + request = request_type() requests = [request] # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.write), "__call__") as call: + with mock.patch.object(type(client.transport.write), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = mock.Mock(aio.StreamStreamCall, autospec=True) call.return_value.read = mock.AsyncMock(side_effect=[firestore.WriteResponse()]) @@ -2340,6 +2375,11 @@ async def test_write_async(transport: str = "grpc_asyncio"): assert isinstance(message, firestore.WriteResponse) +@pytest.mark.asyncio +async def test_write_async_from_dict(): + await test_write_async(request_type=dict) + + def test_listen(transport: str = "grpc", request_type=firestore.ListenRequest): client = FirestoreClient( credentials=credentials.AnonymousCredentials(), transport=transport, @@ -2352,7 +2392,7 @@ def test_listen(transport: str = "grpc", request_type=firestore.ListenRequest): requests = [request] # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.listen), "__call__") as call: + with mock.patch.object(type(client.transport.listen), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = iter([firestore.ListenResponse()]) @@ -2374,19 +2414,21 @@ def test_listen_from_dict(): @pytest.mark.asyncio -async def test_listen_async(transport: str = "grpc_asyncio"): +async def test_listen_async( + transport: str = "grpc_asyncio", request_type=firestore.ListenRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.ListenRequest() + request = request_type() requests = [request] # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._client._transport.listen), "__call__") as call: + with mock.patch.object(type(client.transport.listen), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = mock.Mock(aio.StreamStreamCall, autospec=True) call.return_value.read = mock.AsyncMock( @@ -2406,6 +2448,11 @@ async def test_listen_async(transport: str = "grpc_asyncio"): assert isinstance(message, firestore.ListenResponse) +@pytest.mark.asyncio +async def test_listen_async_from_dict(): + await test_listen_async(request_type=dict) + + def test_list_collection_ids( transport: str = "grpc", request_type=firestore.ListCollectionIdsRequest ): @@ -2419,7 +2466,7 @@ def test_list_collection_ids( # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_collection_ids), "__call__" + type(client.transport.list_collection_ids), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = firestore.ListCollectionIdsResponse( @@ -2436,6 +2483,7 @@ def test_list_collection_ids( assert args[0] == firestore.ListCollectionIdsRequest() # Establish that the response is the type that we expect. + assert isinstance(response, pagers.ListCollectionIdsPager) assert response.collection_ids == ["collection_ids_value"] @@ -2448,18 +2496,20 @@ def test_list_collection_ids_from_dict(): @pytest.mark.asyncio -async def test_list_collection_ids_async(transport: str = "grpc_asyncio"): +async def test_list_collection_ids_async( + transport: str = "grpc_asyncio", request_type=firestore.ListCollectionIdsRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.ListCollectionIdsRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_collection_ids), "__call__" + type(client.transport.list_collection_ids), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( @@ -2475,7 +2525,7 @@ async def test_list_collection_ids_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.ListCollectionIdsRequest() # Establish that the response is the type that we expect. assert isinstance(response, pagers.ListCollectionIdsAsyncPager) @@ -2485,6 +2535,11 @@ async def test_list_collection_ids_async(transport: str = "grpc_asyncio"): assert response.next_page_token == "next_page_token_value" +@pytest.mark.asyncio +async def test_list_collection_ids_async_from_dict(): + await test_list_collection_ids_async(request_type=dict) + + def test_list_collection_ids_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -2495,7 +2550,7 @@ def test_list_collection_ids_field_headers(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_collection_ids), "__call__" + type(client.transport.list_collection_ids), "__call__" ) as call: call.return_value = firestore.ListCollectionIdsResponse() @@ -2522,7 +2577,7 @@ async def test_list_collection_ids_field_headers_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_collection_ids), "__call__" + type(client.transport.list_collection_ids), "__call__" ) as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore.ListCollectionIdsResponse() @@ -2545,7 +2600,7 @@ def test_list_collection_ids_flattened(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_collection_ids), "__call__" + type(client.transport.list_collection_ids), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = firestore.ListCollectionIdsResponse() @@ -2579,7 +2634,7 @@ async def test_list_collection_ids_flattened_async(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_collection_ids), "__call__" + type(client.transport.list_collection_ids), "__call__" ) as call: # Designate an appropriate return value for the call. call.return_value = firestore.ListCollectionIdsResponse() @@ -2616,7 +2671,7 @@ def test_list_collection_ids_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_collection_ids), "__call__" + type(client.transport.list_collection_ids), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2651,7 +2706,7 @@ def test_list_collection_ids_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._transport.list_collection_ids), "__call__" + type(client.transport.list_collection_ids), "__call__" ) as call: # Set the response to a series of pages. call.side_effect = ( @@ -2678,7 +2733,7 @@ async def test_list_collection_ids_async_pager(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_collection_ids), + type(client.transport.list_collection_ids), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -2712,7 +2767,7 @@ async def test_list_collection_ids_async_pages(): # Mock the actual call within the gRPC stub, and fake the request. with mock.patch.object( - type(client._client._transport.list_collection_ids), + type(client.transport.list_collection_ids), "__call__", new_callable=mock.AsyncMock, ) as call: @@ -2747,7 +2802,7 @@ def test_batch_write(transport: str = "grpc", request_type=firestore.BatchWriteR request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.batch_write), "__call__") as call: + with mock.patch.object(type(client.transport.batch_write), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = firestore.BatchWriteResponse() @@ -2760,6 +2815,7 @@ def test_batch_write(transport: str = "grpc", request_type=firestore.BatchWriteR assert args[0] == firestore.BatchWriteRequest() # Establish that the response is the type that we expect. + assert isinstance(response, firestore.BatchWriteResponse) @@ -2768,19 +2824,19 @@ def test_batch_write_from_dict(): @pytest.mark.asyncio -async def test_batch_write_async(transport: str = "grpc_asyncio"): +async def test_batch_write_async( + transport: str = "grpc_asyncio", request_type=firestore.BatchWriteRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.BatchWriteRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.batch_write), "__call__" - ) as call: + with mock.patch.object(type(client.transport.batch_write), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore.BatchWriteResponse() @@ -2792,12 +2848,17 @@ async def test_batch_write_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.BatchWriteRequest() # Establish that the response is the type that we expect. assert isinstance(response, firestore.BatchWriteResponse) +@pytest.mark.asyncio +async def test_batch_write_async_from_dict(): + await test_batch_write_async(request_type=dict) + + def test_batch_write_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -2807,7 +2868,7 @@ def test_batch_write_field_headers(): request.database = "database/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.batch_write), "__call__") as call: + with mock.patch.object(type(client.transport.batch_write), "__call__") as call: call.return_value = firestore.BatchWriteResponse() client.batch_write(request) @@ -2832,9 +2893,7 @@ async def test_batch_write_field_headers_async(): request.database = "database/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.batch_write), "__call__" - ) as call: + with mock.patch.object(type(client.transport.batch_write), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( firestore.BatchWriteResponse() ) @@ -2863,7 +2922,7 @@ def test_create_document( request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_document), "__call__") as call: + with mock.patch.object(type(client.transport.create_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = document.Document(name="name_value",) @@ -2876,6 +2935,7 @@ def test_create_document( assert args[0] == firestore.CreateDocumentRequest() # Establish that the response is the type that we expect. + assert isinstance(response, document.Document) assert response.name == "name_value" @@ -2886,19 +2946,19 @@ def test_create_document_from_dict(): @pytest.mark.asyncio -async def test_create_document_async(transport: str = "grpc_asyncio"): +async def test_create_document_async( + transport: str = "grpc_asyncio", request_type=firestore.CreateDocumentRequest +): client = FirestoreAsyncClient( credentials=credentials.AnonymousCredentials(), transport=transport, ) # Everything is optional in proto3 as far as the runtime is concerned, # and we are mocking out the actual API, so just send an empty request. - request = firestore.CreateDocumentRequest() + request = request_type() # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_document), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_document), "__call__") as call: # Designate an appropriate return value for the call. call.return_value = grpc_helpers_async.FakeUnaryUnaryCall( document.Document(name="name_value",) @@ -2910,7 +2970,7 @@ async def test_create_document_async(transport: str = "grpc_asyncio"): assert len(call.mock_calls) _, args, _ = call.mock_calls[0] - assert args[0] == request + assert args[0] == firestore.CreateDocumentRequest() # Establish that the response is the type that we expect. assert isinstance(response, document.Document) @@ -2918,6 +2978,11 @@ async def test_create_document_async(transport: str = "grpc_asyncio"): assert response.name == "name_value" +@pytest.mark.asyncio +async def test_create_document_async_from_dict(): + await test_create_document_async(request_type=dict) + + def test_create_document_field_headers(): client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) @@ -2927,7 +2992,7 @@ def test_create_document_field_headers(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object(type(client._transport.create_document), "__call__") as call: + with mock.patch.object(type(client.transport.create_document), "__call__") as call: call.return_value = document.Document() client.create_document(request) @@ -2952,9 +3017,7 @@ async def test_create_document_field_headers_async(): request.parent = "parent/value" # Mock the actual call within the gRPC stub, and fake the request. - with mock.patch.object( - type(client._client._transport.create_document), "__call__" - ) as call: + with mock.patch.object(type(client.transport.create_document), "__call__") as call: call.return_value = grpc_helpers_async.FakeUnaryUnaryCall(document.Document()) await client.create_document(request) @@ -3005,7 +3068,7 @@ def test_transport_instance(): credentials=credentials.AnonymousCredentials(), ) client = FirestoreClient(transport=transport) - assert client._transport is transport + assert client.transport is transport def test_transport_get_channel(): @@ -3038,7 +3101,7 @@ def test_transport_adc(transport_class): def test_transport_grpc_default(): # A client should use the gRPC transport by default. client = FirestoreClient(credentials=credentials.AnonymousCredentials(),) - assert isinstance(client._transport, transports.FirestoreGrpcTransport,) + assert isinstance(client.transport, transports.FirestoreGrpcTransport,) def test_firestore_base_transport_error(): @@ -3155,7 +3218,7 @@ def test_firestore_host_no_port(): api_endpoint="firestore.googleapis.com" ), ) - assert client._transport._host == "firestore.googleapis.com:443" + assert client.transport._host == "firestore.googleapis.com:443" def test_firestore_host_with_port(): @@ -3165,7 +3228,7 @@ def test_firestore_host_with_port(): api_endpoint="firestore.googleapis.com:8000" ), ) - assert client._transport._host == "firestore.googleapis.com:8000" + assert client.transport._host == "firestore.googleapis.com:8000" def test_firestore_grpc_transport_channel(): @@ -3177,6 +3240,7 @@ def test_firestore_grpc_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None def test_firestore_grpc_asyncio_transport_channel(): @@ -3188,6 +3252,7 @@ def test_firestore_grpc_asyncio_transport_channel(): ) assert transport.grpc_channel == channel assert transport._host == "squid.clam.whelk:443" + assert transport._ssl_channel_credentials == None @pytest.mark.parametrize( @@ -3233,6 +3298,7 @@ def test_firestore_transport_channel_mtls_with_client_cert_source(transport_clas quota_project_id=None, ) assert transport.grpc_channel == mock_grpc_channel + assert transport._ssl_channel_credentials == mock_ssl_cred @pytest.mark.parametrize( @@ -3275,6 +3341,107 @@ def test_firestore_transport_channel_mtls_with_adc(transport_class): assert transport.grpc_channel == mock_grpc_channel +def test_common_billing_account_path(): + billing_account = "squid" + + expected = "billingAccounts/{billing_account}".format( + billing_account=billing_account, + ) + actual = FirestoreClient.common_billing_account_path(billing_account) + assert expected == actual + + +def test_parse_common_billing_account_path(): + expected = { + "billing_account": "clam", + } + path = FirestoreClient.common_billing_account_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreClient.parse_common_billing_account_path(path) + assert expected == actual + + +def test_common_folder_path(): + folder = "whelk" + + expected = "folders/{folder}".format(folder=folder,) + actual = FirestoreClient.common_folder_path(folder) + assert expected == actual + + +def test_parse_common_folder_path(): + expected = { + "folder": "octopus", + } + path = FirestoreClient.common_folder_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreClient.parse_common_folder_path(path) + assert expected == actual + + +def test_common_organization_path(): + organization = "oyster" + + expected = "organizations/{organization}".format(organization=organization,) + actual = FirestoreClient.common_organization_path(organization) + assert expected == actual + + +def test_parse_common_organization_path(): + expected = { + "organization": "nudibranch", + } + path = FirestoreClient.common_organization_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreClient.parse_common_organization_path(path) + assert expected == actual + + +def test_common_project_path(): + project = "cuttlefish" + + expected = "projects/{project}".format(project=project,) + actual = FirestoreClient.common_project_path(project) + assert expected == actual + + +def test_parse_common_project_path(): + expected = { + "project": "mussel", + } + path = FirestoreClient.common_project_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreClient.parse_common_project_path(path) + assert expected == actual + + +def test_common_location_path(): + project = "winkle" + location = "nautilus" + + expected = "projects/{project}/locations/{location}".format( + project=project, location=location, + ) + actual = FirestoreClient.common_location_path(project, location) + assert expected == actual + + +def test_parse_common_location_path(): + expected = { + "project": "scallop", + "location": "abalone", + } + path = FirestoreClient.common_location_path(**expected) + + # Check that the path construction is reversible. + actual = FirestoreClient.parse_common_location_path(path) + assert expected == actual + + def test_client_withDEFAULT_CLIENT_INFO(): client_info = gapic_v1.client_info.ClientInfo()