From 6b5a7795bb2827b65f8015fcef6663880a29a65d Mon Sep 17 00:00:00 2001 From: "gcf-owl-bot[bot]" <78513119+gcf-owl-bot[bot]@users.noreply.github.com> Date: Mon, 1 Nov 2021 14:40:16 +0000 Subject: [PATCH] chore: use gapic-generator-python 0.53.4 (#486) - [ ] Regenerate this pull request now. docs: list oneofs in docstring fix(deps): require google-api-core >= 1.28.0 fix(deps): drop packaging dependency committer: busunkim96@ PiperOrigin-RevId: 406468269 Source-Link: https://github.com/googleapis/googleapis/commit/83d81b0c8fc22291a13398d6d77f02dc97a5b6f4 Source-Link: https://github.com/googleapis/googleapis-gen/commit/2ff001fbacb9e77e71d734de5f955c05fdae8526 Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiMmZmMDAxZmJhY2I5ZTc3ZTcxZDczNGRlNWY5NTVjMDVmZGFlODUyNiJ9 --- .../services/firestore_admin/async_client.py | 58 +++++----- .../services/firestore_admin/client.py | 20 ++-- .../firestore_admin/transports/base.py | 37 +------ .../firestore_admin/transports/grpc.py | 2 +- .../transports/grpc_asyncio.py | 3 +- .../cloud/firestore_admin_v1/types/index.py | 9 ++ google/cloud/firestore_bundle/types/bundle.py | 14 +++ .../services/firestore/async_client.py | 86 +++++++-------- .../firestore_v1/services/firestore/client.py | 32 +++--- .../services/firestore/transports/base.py | 35 +----- .../firestore/transports/grpc_asyncio.py | 1 - google/cloud/firestore_v1/types/common.py | 22 ++++ google/cloud/firestore_v1/types/document.py | 18 ++++ google/cloud/firestore_v1/types/firestore.py | 87 +++++++++++++++ google/cloud/firestore_v1/types/query.py | 13 +++ google/cloud/firestore_v1/types/write.py | 23 ++++ setup.py | 3 +- testing/constraints-3.6.txt | 3 +- .../test_firestore_admin.py | 100 ++---------------- .../unit/gapic/firestore_v1/test_firestore.py | 97 ++--------------- 20 files changed, 313 insertions(+), 350 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 90d5b2cf16..c97b0b1c6b 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 @@ -19,13 +19,15 @@ from typing import Dict, Sequence, Tuple, Type, Union import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.firestore_admin_v1.services.firestore_admin import pagers @@ -181,11 +183,11 @@ def __init__( async def create_index( self, - request: firestore_admin.CreateIndexRequest = None, + request: Union[firestore_admin.CreateIndexRequest, dict] = None, *, parent: str = None, index: gfa_index.Index = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -196,7 +198,7 @@ async def create_index( [IndexOperationMetadata][google.firestore.admin.v1.IndexOperationMetadata]. Args: - request (:class:`google.cloud.firestore_admin_v1.types.CreateIndexRequest`): + request (Union[google.cloud.firestore_admin_v1.types.CreateIndexRequest, dict]): The request object. The request for [FirestoreAdmin.CreateIndex][google.firestore.admin.v1.FirestoreAdmin.CreateIndex]. parent (:class:`str`): @@ -276,17 +278,17 @@ async def create_index( async def list_indexes( self, - request: firestore_admin.ListIndexesRequest = None, + request: Union[firestore_admin.ListIndexesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListIndexesAsyncPager: r"""Lists composite indexes. Args: - request (:class:`google.cloud.firestore_admin_v1.types.ListIndexesRequest`): + request (Union[google.cloud.firestore_admin_v1.types.ListIndexesRequest, dict]): The request object. The request for [FirestoreAdmin.ListIndexes][google.firestore.admin.v1.FirestoreAdmin.ListIndexes]. parent (:class:`str`): @@ -367,17 +369,17 @@ async def list_indexes( async def get_index( self, - request: firestore_admin.GetIndexRequest = None, + request: Union[firestore_admin.GetIndexRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> index.Index: r"""Gets a composite index. Args: - request (:class:`google.cloud.firestore_admin_v1.types.GetIndexRequest`): + request (Union[google.cloud.firestore_admin_v1.types.GetIndexRequest, dict]): The request object. The request for [FirestoreAdmin.GetIndex][google.firestore.admin.v1.FirestoreAdmin.GetIndex]. name (:class:`str`): @@ -450,17 +452,17 @@ async def get_index( async def delete_index( self, - request: firestore_admin.DeleteIndexRequest = None, + request: Union[firestore_admin.DeleteIndexRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a composite index. Args: - request (:class:`google.cloud.firestore_admin_v1.types.DeleteIndexRequest`): + request (Union[google.cloud.firestore_admin_v1.types.DeleteIndexRequest, dict]): The request object. The request for [FirestoreAdmin.DeleteIndex][google.firestore.admin.v1.FirestoreAdmin.DeleteIndex]. name (:class:`str`): @@ -525,17 +527,17 @@ async def delete_index( async def get_field( self, - request: firestore_admin.GetFieldRequest = None, + request: Union[firestore_admin.GetFieldRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> field.Field: r"""Gets the metadata and configuration for a Field. Args: - request (:class:`google.cloud.firestore_admin_v1.types.GetFieldRequest`): + request (Union[google.cloud.firestore_admin_v1.types.GetFieldRequest, dict]): The request object. The request for [FirestoreAdmin.GetField][google.firestore.admin.v1.FirestoreAdmin.GetField]. name (:class:`str`): @@ -610,10 +612,10 @@ async def get_field( async def update_field( self, - request: firestore_admin.UpdateFieldRequest = None, + request: Union[firestore_admin.UpdateFieldRequest, dict] = None, *, field: gfa_field.Field = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -635,7 +637,7 @@ async def update_field( ``projects/{project_id}/databases/{database_id}/collectionGroups/__default__/fields/*``. Args: - request (:class:`google.cloud.firestore_admin_v1.types.UpdateFieldRequest`): + request (Union[google.cloud.firestore_admin_v1.types.UpdateFieldRequest, dict]): The request object. The request for [FirestoreAdmin.UpdateField][google.firestore.admin.v1.FirestoreAdmin.UpdateField]. field (:class:`google.cloud.firestore_admin_v1.types.Field`): @@ -711,10 +713,10 @@ async def update_field( async def list_fields( self, - request: firestore_admin.ListFieldsRequest = None, + request: Union[firestore_admin.ListFieldsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFieldsAsyncPager: @@ -728,7 +730,7 @@ async def list_fields( with the filter set to ``indexConfig.usesAncestorConfig:false``. Args: - request (:class:`google.cloud.firestore_admin_v1.types.ListFieldsRequest`): + request (Union[google.cloud.firestore_admin_v1.types.ListFieldsRequest, dict]): The request object. The request for [FirestoreAdmin.ListFields][google.firestore.admin.v1.FirestoreAdmin.ListFields]. parent (:class:`str`): @@ -809,10 +811,10 @@ async def list_fields( async def export_documents( self, - request: firestore_admin.ExportDocumentsRequest = None, + request: Union[firestore_admin.ExportDocumentsRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -828,7 +830,7 @@ async def export_documents( Google Cloud Storage. Args: - request (:class:`google.cloud.firestore_admin_v1.types.ExportDocumentsRequest`): + request (Union[google.cloud.firestore_admin_v1.types.ExportDocumentsRequest, dict]): The request object. The request for [FirestoreAdmin.ExportDocuments][google.firestore.admin.v1.FirestoreAdmin.ExportDocuments]. name (:class:`str`): @@ -902,10 +904,10 @@ async def export_documents( async def import_documents( self, - request: firestore_admin.ImportDocumentsRequest = None, + request: Union[firestore_admin.ImportDocumentsRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> operation_async.AsyncOperation: @@ -918,7 +920,7 @@ async def import_documents( already been imported to Cloud Firestore. Args: - request (:class:`google.cloud.firestore_admin_v1.types.ImportDocumentsRequest`): + request (Union[google.cloud.firestore_admin_v1.types.ImportDocumentsRequest, dict]): The request object. The request for [FirestoreAdmin.ImportDocuments][google.firestore.admin.v1.FirestoreAdmin.ImportDocuments]. name (:class:`str`): 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 bd91dc7c48..6a730c47da 100644 --- a/google/cloud/firestore_admin_v1/services/firestore_admin/client.py +++ b/google/cloud/firestore_admin_v1/services/firestore_admin/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.api_core import operation as gac_operation # type: ignore from google.api_core import operation_async # type: ignore from google.cloud.firestore_admin_v1.services.firestore_admin import pagers @@ -408,7 +410,7 @@ def create_index( *, parent: str = None, index: gfa_index.Index = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -502,7 +504,7 @@ def list_indexes( request: Union[firestore_admin.ListIndexesRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListIndexesPager: @@ -582,7 +584,7 @@ def get_index( request: Union[firestore_admin.GetIndexRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> index.Index: @@ -654,7 +656,7 @@ def delete_index( request: Union[firestore_admin.DeleteIndexRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -718,7 +720,7 @@ def get_field( request: Union[firestore_admin.GetFieldRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> field.Field: @@ -792,7 +794,7 @@ def update_field( request: Union[firestore_admin.UpdateFieldRequest, dict] = None, *, field: gfa_field.Field = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -893,7 +895,7 @@ def list_fields( request: Union[firestore_admin.ListFieldsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListFieldsPager: @@ -980,7 +982,7 @@ def export_documents( request: Union[firestore_admin.ExportDocumentsRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: @@ -1073,7 +1075,7 @@ def import_documents( request: Union[firestore_admin.ImportDocumentsRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gac_operation.Operation: diff --git a/google/cloud/firestore_admin_v1/services/firestore_admin/transports/base.py b/google/cloud/firestore_admin_v1/services/firestore_admin/transports/base.py index e51ff75cae..07fb738c78 100644 --- a/google/cloud/firestore_admin_v1/services/firestore_admin/transports/base.py +++ b/google/cloud/firestore_admin_v1/services/firestore_admin/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -42,15 +41,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class FirestoreAdminTransport(abc.ABC): """Abstract transport class for FirestoreAdmin.""" @@ -103,7 +93,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -136,29 +126,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { @@ -266,7 +233,7 @@ def close(self): raise NotImplementedError() @property - def operations_client(self) -> operations_v1.OperationsClient: + def operations_client(self): """Return the client designed to process long-running operations.""" raise NotImplementedError() 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 a03c589806..9ffba15c84 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 @@ -116,7 +116,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) 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 aaa0cd3595..1d60f7c1eb 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 @@ -21,7 +21,6 @@ from google.api_core import operations_v1 # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore @@ -163,7 +162,7 @@ def __init__( self._grpc_channel = None self._ssl_channel_credentials = ssl_channel_credentials self._stubs: Dict[str, Callable] = {} - self._operations_client = None + self._operations_client: Optional[operations_v1.OperationsAsyncClient] = None if api_mtls_endpoint: warnings.warn("api_mtls_endpoint is deprecated", DeprecationWarning) diff --git a/google/cloud/firestore_admin_v1/types/index.py b/google/cloud/firestore_admin_v1/types/index.py index 9d55ebe91a..cd4253e66a 100644 --- a/google/cloud/firestore_admin_v1/types/index.py +++ b/google/cloud/firestore_admin_v1/types/index.py @@ -83,6 +83,13 @@ class IndexField(proto.Message): r"""A field in an index. The field_path describes which field is indexed, the value_mode describes how the field value is indexed. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: field_path (str): Can be **name**. For single field indexes, this must match @@ -91,9 +98,11 @@ class IndexField(proto.Message): Indicates that this field supports ordering by the specified order or comparing using =, <, <=, >, >=. + This field is a member of `oneof`_ ``value_mode``. array_config (google.cloud.firestore_admin_v1.types.Index.IndexField.ArrayConfig): Indicates that this field supports operations on ``array_value``\ s. + This field is a member of `oneof`_ ``value_mode``. """ class Order(proto.Enum): diff --git a/google/cloud/firestore_bundle/types/bundle.py b/google/cloud/firestore_bundle/types/bundle.py index cd3cc51412..5e7209dfbd 100644 --- a/google/cloud/firestore_bundle/types/bundle.py +++ b/google/cloud/firestore_bundle/types/bundle.py @@ -35,11 +35,14 @@ class BundledQuery(proto.Message): r"""Encodes a query saved in the bundle. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: parent (str): The parent resource name. structured_query (google.firestore.v1.query_pb2.StructuredQuery): A structured query. + This field is a member of `oneof`_ ``query_type``. limit_type (google.cloud.bundle.types.BundledQuery.LimitType): """ @@ -137,15 +140,26 @@ class BundleElement(proto.Message): follow after ``metadata``. Every ``document_metadata`` is immediately followed by a ``document``. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: metadata (google.cloud.bundle.types.BundleMetadata): + This field is a member of `oneof`_ ``element_type``. named_query (google.cloud.bundle.types.NamedQuery): + This field is a member of `oneof`_ ``element_type``. document_metadata (google.cloud.bundle.types.BundledDocumentMetadata): + This field is a member of `oneof`_ ``element_type``. document (google.firestore.v1.document_pb2.Document): + This field is a member of `oneof`_ ``element_type``. """ metadata = proto.Field( diff --git a/google/cloud/firestore_v1/services/firestore/async_client.py b/google/cloud/firestore_v1/services/firestore/async_client.py index fae2b076f2..01766f576d 100644 --- a/google/cloud/firestore_v1/services/firestore/async_client.py +++ b/google/cloud/firestore_v1/services/firestore/async_client.py @@ -28,13 +28,15 @@ ) import pkg_resources -import google.api_core.client_options as ClientOptions # type: ignore +from google.api_core.client_options import ClientOptions # type: ignore from google.api_core import exceptions as core_exceptions # type: ignore from google.api_core import gapic_v1 # type: ignore from google.api_core import retry as retries # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.firestore_v1.services.firestore import pagers from google.cloud.firestore_v1.types import common from google.cloud.firestore_v1.types import document @@ -179,16 +181,16 @@ def __init__( async def get_document( self, - request: firestore.GetDocumentRequest = None, + request: Union[firestore.GetDocumentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> document.Document: r"""Gets a single document. Args: - request (:class:`google.cloud.firestore_v1.types.GetDocumentRequest`): + request (Union[google.cloud.firestore_v1.types.GetDocumentRequest, dict]): The request object. The request for [Firestore.GetDocument][google.firestore.v1.Firestore.GetDocument]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -240,16 +242,16 @@ async def get_document( async def list_documents( self, - request: firestore.ListDocumentsRequest = None, + request: Union[firestore.ListDocumentsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDocumentsAsyncPager: r"""Lists documents. Args: - request (:class:`google.cloud.firestore_v1.types.ListDocumentsRequest`): + request (Union[google.cloud.firestore_v1.types.ListDocumentsRequest, dict]): The request object. The request for [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -310,18 +312,18 @@ async def list_documents( async def update_document( self, - request: firestore.UpdateDocumentRequest = None, + request: Union[firestore.UpdateDocumentRequest, dict] = None, *, document: gf_document.Document = None, update_mask: common.DocumentMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gf_document.Document: r"""Updates or inserts a document. Args: - request (:class:`google.cloud.firestore_v1.types.UpdateDocumentRequest`): + request (Union[google.cloud.firestore_v1.types.UpdateDocumentRequest, dict]): The request object. The request for [Firestore.UpdateDocument][google.firestore.v1.Firestore.UpdateDocument]. document (:class:`google.cloud.firestore_v1.types.Document`): @@ -411,17 +413,17 @@ async def update_document( async def delete_document( self, - request: firestore.DeleteDocumentRequest = None, + request: Union[firestore.DeleteDocumentRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Deletes a document. Args: - request (:class:`google.cloud.firestore_v1.types.DeleteDocumentRequest`): + request (Union[google.cloud.firestore_v1.types.DeleteDocumentRequest, dict]): The request object. The request for [Firestore.DeleteDocument][google.firestore.v1.Firestore.DeleteDocument]. name (:class:`str`): @@ -488,9 +490,9 @@ async def delete_document( def batch_get_documents( self, - request: firestore.BatchGetDocumentsRequest = None, + request: Union[firestore.BatchGetDocumentsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[firestore.BatchGetDocumentsResponse]]: @@ -499,7 +501,7 @@ def batch_get_documents( be returned in the same order that they were requested. Args: - request (:class:`google.cloud.firestore_v1.types.BatchGetDocumentsRequest`): + request (Union[google.cloud.firestore_v1.types.BatchGetDocumentsRequest, dict]): The request object. The request for [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -551,17 +553,17 @@ def batch_get_documents( async def begin_transaction( self, - request: firestore.BeginTransactionRequest = None, + request: Union[firestore.BeginTransactionRequest, dict] = None, *, database: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> firestore.BeginTransactionResponse: r"""Starts a new transaction. Args: - request (:class:`google.cloud.firestore_v1.types.BeginTransactionRequest`): + request (Union[google.cloud.firestore_v1.types.BeginTransactionRequest, dict]): The request object. The request for [Firestore.BeginTransaction][google.firestore.v1.Firestore.BeginTransaction]. database (:class:`str`): @@ -634,11 +636,11 @@ async def begin_transaction( async def commit( self, - request: firestore.CommitRequest = None, + request: Union[firestore.CommitRequest, dict] = None, *, database: str = None, writes: Sequence[gf_write.Write] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> firestore.CommitResponse: @@ -646,7 +648,7 @@ async def commit( documents. Args: - request (:class:`google.cloud.firestore_v1.types.CommitRequest`): + request (Union[google.cloud.firestore_v1.types.CommitRequest, dict]): The request object. The request for [Firestore.Commit][google.firestore.v1.Firestore.Commit]. database (:class:`str`): @@ -726,18 +728,18 @@ async def commit( async def rollback( self, - request: firestore.RollbackRequest = None, + request: Union[firestore.RollbackRequest, dict] = None, *, database: str = None, transaction: bytes = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: r"""Rolls back a transaction. Args: - request (:class:`google.cloud.firestore_v1.types.RollbackRequest`): + request (Union[google.cloud.firestore_v1.types.RollbackRequest, dict]): The request object. The request for [Firestore.Rollback][google.firestore.v1.Firestore.Rollback]. database (:class:`str`): @@ -812,16 +814,16 @@ async def rollback( def run_query( self, - request: firestore.RunQueryRequest = None, + request: Union[firestore.RunQueryRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[firestore.RunQueryResponse]]: r"""Runs a query. Args: - request (:class:`google.cloud.firestore_v1.types.RunQueryRequest`): + request (Union[google.cloud.firestore_v1.types.RunQueryRequest, dict]): The request object. The request for [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -873,9 +875,9 @@ def run_query( async def partition_query( self, - request: firestore.PartitionQueryRequest = None, + request: Union[firestore.PartitionQueryRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.PartitionQueryAsyncPager: @@ -886,7 +888,7 @@ async def partition_query( results. Args: - request (:class:`google.cloud.firestore_v1.types.PartitionQueryRequest`): + request (Union[google.cloud.firestore_v1.types.PartitionQueryRequest, dict]): The request object. The request for [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -949,7 +951,7 @@ def write( self, requests: AsyncIterator[firestore.WriteRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[firestore.WriteResponse]]: @@ -1005,7 +1007,7 @@ def listen( self, requests: AsyncIterator[firestore.ListenRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Awaitable[AsyncIterable[firestore.ListenResponse]]: @@ -1060,17 +1062,17 @@ def listen( async def list_collection_ids( self, - request: firestore.ListCollectionIdsRequest = None, + request: Union[firestore.ListCollectionIdsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCollectionIdsAsyncPager: r"""Lists all the collection IDs underneath a document. Args: - request (:class:`google.cloud.firestore_v1.types.ListCollectionIdsRequest`): + request (Union[google.cloud.firestore_v1.types.ListCollectionIdsRequest, dict]): The request object. The request for [Firestore.ListCollectionIds][google.firestore.v1.Firestore.ListCollectionIds]. parent (:class:`str`): @@ -1154,9 +1156,9 @@ async def list_collection_ids( async def batch_write( self, - request: firestore.BatchWriteRequest = None, + request: Union[firestore.BatchWriteRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> firestore.BatchWriteResponse: @@ -1173,7 +1175,7 @@ async def batch_write( [Commit][google.firestore.v1.Firestore.Commit] instead. Args: - request (:class:`google.cloud.firestore_v1.types.BatchWriteRequest`): + request (Union[google.cloud.firestore_v1.types.BatchWriteRequest, dict]): The request object. The request for [Firestore.BatchWrite][google.firestore.v1.Firestore.BatchWrite]. retry (google.api_core.retry.Retry): Designation of what errors, if any, @@ -1224,16 +1226,16 @@ async def batch_write( async def create_document( self, - request: firestore.CreateDocumentRequest = None, + request: Union[firestore.CreateDocumentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> document.Document: r"""Creates a new document. Args: - request (:class:`google.cloud.firestore_v1.types.CreateDocumentRequest`): + request (Union[google.cloud.firestore_v1.types.CreateDocumentRequest, dict]): The request object. The request for [Firestore.CreateDocument][google.firestore.v1.Firestore.CreateDocument]. retry (google.api_core.retry.Retry): Designation of what errors, if any, diff --git a/google/cloud/firestore_v1/services/firestore/client.py b/google/cloud/firestore_v1/services/firestore/client.py index e62c2c2ef9..bdd8d51d2a 100644 --- a/google/cloud/firestore_v1/services/firestore/client.py +++ b/google/cloud/firestore_v1/services/firestore/client.py @@ -30,6 +30,8 @@ from google.auth.exceptions import MutualTLSChannelError # type: ignore from google.oauth2 import service_account # type: ignore +OptionalRetry = Union[retries.Retry, object] + from google.cloud.firestore_v1.services.firestore import pagers from google.cloud.firestore_v1.types import common from google.cloud.firestore_v1.types import document @@ -348,7 +350,7 @@ def get_document( self, request: Union[firestore.GetDocumentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> document.Document: @@ -398,7 +400,7 @@ def list_documents( self, request: Union[firestore.ListDocumentsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListDocumentsPager: @@ -459,7 +461,7 @@ def update_document( *, document: gf_document.Document = None, update_mask: common.DocumentMask = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> gf_document.Document: @@ -549,7 +551,7 @@ def delete_document( request: Union[firestore.DeleteDocumentRequest, dict] = None, *, name: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -613,7 +615,7 @@ def batch_get_documents( self, request: Union[firestore.BatchGetDocumentsRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[firestore.BatchGetDocumentsResponse]: @@ -666,7 +668,7 @@ def begin_transaction( request: Union[firestore.BeginTransactionRequest, dict] = None, *, database: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> firestore.BeginTransactionResponse: @@ -738,7 +740,7 @@ def commit( *, database: str = None, writes: Sequence[gf_write.Write] = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> firestore.CommitResponse: @@ -820,7 +822,7 @@ def rollback( *, database: str = None, transaction: bytes = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> None: @@ -892,7 +894,7 @@ def run_query( self, request: Union[firestore.RunQueryRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[firestore.RunQueryResponse]: @@ -942,7 +944,7 @@ def partition_query( self, request: Union[firestore.PartitionQueryRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.PartitionQueryPager: @@ -1005,7 +1007,7 @@ def write( self, requests: Iterator[firestore.WriteRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[firestore.WriteResponse]: @@ -1057,7 +1059,7 @@ def listen( self, requests: Iterator[firestore.ListenRequest] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> Iterable[firestore.ListenResponse]: @@ -1099,7 +1101,7 @@ def list_collection_ids( request: Union[firestore.ListCollectionIdsRequest, dict] = None, *, parent: str = None, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> pagers.ListCollectionIdsPager: @@ -1180,7 +1182,7 @@ def batch_write( self, request: Union[firestore.BatchWriteRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> firestore.BatchWriteResponse: @@ -1240,7 +1242,7 @@ def create_document( self, request: Union[firestore.CreateDocumentRequest, dict] = None, *, - retry: retries.Retry = gapic_v1.method.DEFAULT, + retry: OptionalRetry = gapic_v1.method.DEFAULT, timeout: float = None, metadata: Sequence[Tuple[str, str]] = (), ) -> document.Document: diff --git a/google/cloud/firestore_v1/services/firestore/transports/base.py b/google/cloud/firestore_v1/services/firestore/transports/base.py index 429bc7fedf..bf46b0962b 100644 --- a/google/cloud/firestore_v1/services/firestore/transports/base.py +++ b/google/cloud/firestore_v1/services/firestore/transports/base.py @@ -15,7 +15,6 @@ # import abc from typing import Awaitable, Callable, Dict, Optional, Sequence, Union -import packaging.version import pkg_resources import google.auth # type: ignore @@ -38,15 +37,6 @@ except pkg_resources.DistributionNotFound: DEFAULT_CLIENT_INFO = gapic_v1.client_info.ClientInfo() -try: - # google.auth.__version__ was added in 1.26.0 - _GOOGLE_AUTH_VERSION = google.auth.__version__ -except AttributeError: - try: # try pkg_resources if it is available - _GOOGLE_AUTH_VERSION = pkg_resources.get_distribution("google-auth").version - except pkg_resources.DistributionNotFound: # pragma: NO COVER - _GOOGLE_AUTH_VERSION = None - class FirestoreTransport(abc.ABC): """Abstract transport class for Firestore.""" @@ -99,7 +89,7 @@ def __init__( host += ":443" self._host = host - scopes_kwargs = self._get_scopes_kwargs(self._host, scopes) + scopes_kwargs = {"scopes": scopes, "default_scopes": self.AUTH_SCOPES} # Save the scopes. self._scopes = scopes @@ -132,29 +122,6 @@ def __init__( # Save the credentials. self._credentials = credentials - # TODO(busunkim): This method is in the base transport - # to avoid duplicating code across the transport classes. These functions - # should be deleted once the minimum required versions of google-auth is increased. - - # TODO: Remove this function once google-auth >= 1.25.0 is required - @classmethod - def _get_scopes_kwargs( - cls, host: str, scopes: Optional[Sequence[str]] - ) -> Dict[str, Optional[Sequence[str]]]: - """Returns scopes kwargs to pass to google-auth methods depending on the google-auth version""" - - scopes_kwargs = {} - - if _GOOGLE_AUTH_VERSION and ( - packaging.version.parse(_GOOGLE_AUTH_VERSION) - >= packaging.version.parse("1.25.0") - ): - scopes_kwargs = {"scopes": scopes, "default_scopes": cls.AUTH_SCOPES} - else: - scopes_kwargs = {"scopes": scopes or cls.AUTH_SCOPES} - - return scopes_kwargs - def _prep_wrapped_messages(self, client_info): # Precompute the wrapped methods. self._wrapped_methods = { 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 a4b372b067..f8575469c3 100644 --- a/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py +++ b/google/cloud/firestore_v1/services/firestore/transports/grpc_asyncio.py @@ -20,7 +20,6 @@ from google.api_core import grpc_helpers_async # type: ignore from google.auth import credentials as ga_credentials # type: ignore from google.auth.transport.grpc import SslCredentials # type: ignore -import packaging.version import grpc # type: ignore from grpc.experimental import aio # type: ignore diff --git a/google/cloud/firestore_v1/types/common.py b/google/cloud/firestore_v1/types/common.py index 6915adb229..f956b6e219 100644 --- a/google/cloud/firestore_v1/types/common.py +++ b/google/cloud/firestore_v1/types/common.py @@ -45,13 +45,22 @@ class Precondition(proto.Message): r"""A precondition on a document, used for conditional operations. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: exists (bool): When set to ``true``, the target document must exist. When set to ``false``, the target document must not exist. + This field is a member of `oneof`_ ``condition_type``. update_time (google.protobuf.timestamp_pb2.Timestamp): When set, the target document must exist and have been last updated at that time. + This field is a member of `oneof`_ ``condition_type``. """ exists = proto.Field(proto.BOOL, number=1, oneof="condition_type",) @@ -66,13 +75,22 @@ class Precondition(proto.Message): class TransactionOptions(proto.Message): r"""Options for creating a new transaction. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: read_only (google.cloud.firestore_v1.types.TransactionOptions.ReadOnly): The transaction can only be used for read operations. + This field is a member of `oneof`_ ``mode``. read_write (google.cloud.firestore_v1.types.TransactionOptions.ReadWrite): The transaction can be used for both read and write operations. + This field is a member of `oneof`_ ``mode``. """ class ReadWrite(proto.Message): @@ -90,10 +108,14 @@ class ReadOnly(proto.Message): r"""Options for a transaction that can only be used to read documents. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: read_time (google.protobuf.timestamp_pb2.Timestamp): Reads documents at the given time. This may not be older than 60 seconds. + This field is a member of `oneof`_ ``consistency_selector``. """ read_time = proto.Field( diff --git a/google/cloud/firestore_v1/types/document.py b/google/cloud/firestore_v1/types/document.py index 1696a9c88e..36c7269607 100644 --- a/google/cloud/firestore_v1/types/document.py +++ b/google/cloud/firestore_v1/types/document.py @@ -86,43 +86,61 @@ class Document(proto.Message): class Value(proto.Message): r"""A message that can hold any of the supported value types. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: null_value (google.protobuf.struct_pb2.NullValue): A null value. + This field is a member of `oneof`_ ``value_type``. boolean_value (bool): A boolean value. + This field is a member of `oneof`_ ``value_type``. integer_value (int): An integer value. + This field is a member of `oneof`_ ``value_type``. double_value (float): A double value. + This field is a member of `oneof`_ ``value_type``. timestamp_value (google.protobuf.timestamp_pb2.Timestamp): A timestamp value. Precise only to microseconds. When stored, any additional precision is rounded down. + This field is a member of `oneof`_ ``value_type``. string_value (str): A string value. The string, represented as UTF-8, must not exceed 1 MiB - 89 bytes. Only the first 1,500 bytes of the UTF-8 representation are considered by queries. + This field is a member of `oneof`_ ``value_type``. bytes_value (bytes): A bytes value. Must not exceed 1 MiB - 89 bytes. Only the first 1,500 bytes are considered by queries. + This field is a member of `oneof`_ ``value_type``. reference_value (str): A reference to a document. For example: ``projects/{project_id}/databases/{database_id}/documents/{document_path}``. + This field is a member of `oneof`_ ``value_type``. geo_point_value (google.type.latlng_pb2.LatLng): A geo point value representing a point on the surface of Earth. + This field is a member of `oneof`_ ``value_type``. array_value (google.cloud.firestore_v1.types.ArrayValue): An array value. Cannot directly contain another array value, though can contain an map which contains another array. + This field is a member of `oneof`_ ``value_type``. map_value (google.cloud.firestore_v1.types.MapValue): A map value. + This field is a member of `oneof`_ ``value_type``. """ null_value = proto.Field( diff --git a/google/cloud/firestore_v1/types/firestore.py b/google/cloud/firestore_v1/types/firestore.py index 78f71f0e06..52fec44d9f 100644 --- a/google/cloud/firestore_v1/types/firestore.py +++ b/google/cloud/firestore_v1/types/firestore.py @@ -61,6 +61,13 @@ class GetDocumentRequest(proto.Message): r"""The request for [Firestore.GetDocument][google.firestore.v1.Firestore.GetDocument]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: name (str): Required. The resource name of the Document to get. In the @@ -74,10 +81,12 @@ class GetDocumentRequest(proto.Message): the response. transaction (bytes): Reads the document in a transaction. + This field is a member of `oneof`_ ``consistency_selector``. read_time (google.protobuf.timestamp_pb2.Timestamp): Reads the version of the document at the given time. This may not be older than 270 seconds. + This field is a member of `oneof`_ ``consistency_selector``. """ name = proto.Field(proto.STRING, number=1,) @@ -95,6 +104,13 @@ class ListDocumentsRequest(proto.Message): r"""The request for [Firestore.ListDocuments][google.firestore.v1.Firestore.ListDocuments]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: parent (str): Required. The parent resource name. In the format: @@ -123,9 +139,11 @@ class ListDocumentsRequest(proto.Message): the response. transaction (bytes): Reads documents in a transaction. + This field is a member of `oneof`_ ``consistency_selector``. read_time (google.protobuf.timestamp_pb2.Timestamp): Reads documents as they were at the given time. This may not be older than 270 seconds. + This field is a member of `oneof`_ ``consistency_selector``. show_missing (bool): If the list should show missing documents. A missing document is a document that does not exist but has @@ -276,6 +294,13 @@ class BatchGetDocumentsRequest(proto.Message): r"""The request for [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: database (str): Required. The database name. In the format: @@ -294,14 +319,17 @@ class BatchGetDocumentsRequest(proto.Message): the response. transaction (bytes): Reads documents in a transaction. + This field is a member of `oneof`_ ``consistency_selector``. new_transaction (google.cloud.firestore_v1.types.TransactionOptions): Starts a new transaction and reads the documents. Defaults to a read-only transaction. The new transaction ID will be returned as the first response in the stream. + This field is a member of `oneof`_ ``consistency_selector``. read_time (google.protobuf.timestamp_pb2.Timestamp): Reads documents as they were at the given time. This may not be older than 270 seconds. + This field is a member of `oneof`_ ``consistency_selector``. """ database = proto.Field(proto.STRING, number=1,) @@ -326,13 +354,22 @@ class BatchGetDocumentsResponse(proto.Message): r"""The streamed response for [Firestore.BatchGetDocuments][google.firestore.v1.Firestore.BatchGetDocuments]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: found (google.cloud.firestore_v1.types.Document): A document that was requested. + This field is a member of `oneof`_ ``result``. missing (str): A document name that was requested but does not exist. In the format: ``projects/{project_id}/databases/{database_id}/documents/{document_path}``. + This field is a member of `oneof`_ ``result``. transaction (bytes): The transaction that was started as part of this request. Will only be set in the first response, and only if @@ -444,6 +481,13 @@ class RunQueryRequest(proto.Message): r"""The request for [Firestore.RunQuery][google.firestore.v1.Firestore.RunQuery]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: parent (str): Required. The parent resource name. In the format: @@ -455,16 +499,20 @@ class RunQueryRequest(proto.Message): ``projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`` structured_query (google.cloud.firestore_v1.types.StructuredQuery): A structured query. + This field is a member of `oneof`_ ``query_type``. transaction (bytes): Reads documents in a transaction. + This field is a member of `oneof`_ ``consistency_selector``. new_transaction (google.cloud.firestore_v1.types.TransactionOptions): Starts a new transaction and reads the documents. Defaults to a read-only transaction. The new transaction ID will be returned as the first response in the stream. + This field is a member of `oneof`_ ``consistency_selector``. read_time (google.protobuf.timestamp_pb2.Timestamp): Reads documents as they were at the given time. This may not be older than 270 seconds. + This field is a member of `oneof`_ ``consistency_selector``. """ parent = proto.Field(proto.STRING, number=1,) @@ -525,6 +573,9 @@ class PartitionQueryRequest(proto.Message): r"""The request for [Firestore.PartitionQuery][google.firestore.v1.Firestore.PartitionQuery]. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: parent (str): Required. The parent resource name. In the format: @@ -537,6 +588,7 @@ class PartitionQueryRequest(proto.Message): descendants and be ordered by name ascending. Other filters, order bys, limits, offsets, and start/end cursors are not supported. + This field is a member of `oneof`_ ``query_type``. partition_count (int): The desired maximum number of partition points. The partitions may be returned across @@ -718,15 +770,24 @@ class ListenRequest(proto.Message): r"""A request for [Firestore.Listen][google.firestore.v1.Firestore.Listen] + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: database (str): Required. The database name. In the format: ``projects/{project_id}/databases/{database_id}``. add_target (google.cloud.firestore_v1.types.Target): A target to add to this stream. + This field is a member of `oneof`_ ``target_change``. remove_target (int): The ID of a target to remove from this stream. + This field is a member of `oneof`_ ``target_change``. labels (Sequence[google.cloud.firestore_v1.types.ListenRequest.LabelsEntry]): Labels associated with this target change. """ @@ -743,17 +804,28 @@ class ListenResponse(proto.Message): r"""The response for [Firestore.Listen][google.firestore.v1.Firestore.Listen]. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: target_change (google.cloud.firestore_v1.types.TargetChange): Targets have changed. + This field is a member of `oneof`_ ``response_type``. document_change (google.cloud.firestore_v1.types.DocumentChange): A [Document][google.firestore.v1.Document] has changed. + This field is a member of `oneof`_ ``response_type``. document_delete (google.cloud.firestore_v1.types.DocumentDelete): A [Document][google.firestore.v1.Document] has been deleted. + This field is a member of `oneof`_ ``response_type``. document_remove (google.cloud.firestore_v1.types.DocumentRemove): A [Document][google.firestore.v1.Document] has been removed from a target (because it is no longer relevant to that target). + This field is a member of `oneof`_ ``response_type``. filter (google.cloud.firestore_v1.types.ExistenceFilter): A filter to apply to the set of documents previously returned for the given target. @@ -761,6 +833,7 @@ class ListenResponse(proto.Message): Returned when documents may have been removed from the given target, but the exact documents are unknown. + This field is a member of `oneof`_ ``response_type``. """ target_change = proto.Field( @@ -783,12 +856,21 @@ class ListenResponse(proto.Message): class Target(proto.Message): r"""A specification of a set of documents to listen to. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: query (google.cloud.firestore_v1.types.Target.QueryTarget): A target specified by a query. + This field is a member of `oneof`_ ``target_type``. documents (google.cloud.firestore_v1.types.Target.DocumentsTarget): A target specified by a set of document names. + This field is a member of `oneof`_ ``target_type``. resume_token (bytes): A resume token from a prior [TargetChange][google.firestore.v1.TargetChange] for an @@ -796,11 +878,13 @@ class Target(proto.Message): Using a resume token with a different target is unsupported and may fail. + This field is a member of `oneof`_ ``resume_type``. read_time (google.protobuf.timestamp_pb2.Timestamp): Start listening after a specific ``read_time``. The client must know the state of matching documents at this time. + This field is a member of `oneof`_ ``resume_type``. target_id (int): The target ID that identifies the target on the stream. Must be a positive number and non- @@ -827,6 +911,8 @@ class DocumentsTarget(proto.Message): class QueryTarget(proto.Message): r"""A target specified by a query. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: parent (str): The parent resource name. In the format: @@ -838,6 +924,7 @@ class QueryTarget(proto.Message): ``projects/my-project/databases/my-database/documents/chatrooms/my-chatroom`` structured_query (google.cloud.firestore_v1.types.StructuredQuery): A structured query. + This field is a member of `oneof`_ ``query_type``. """ parent = proto.Field(proto.STRING, number=1,) diff --git a/google/cloud/firestore_v1/types/query.py b/google/cloud/firestore_v1/types/query.py index 5e47a59012..b6f99362c5 100644 --- a/google/cloud/firestore_v1/types/query.py +++ b/google/cloud/firestore_v1/types/query.py @@ -96,13 +96,23 @@ class CollectionSelector(proto.Message): class Filter(proto.Message): r"""A filter. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: composite_filter (google.cloud.firestore_v1.types.StructuredQuery.CompositeFilter): A composite filter. + This field is a member of `oneof`_ ``filter_type``. field_filter (google.cloud.firestore_v1.types.StructuredQuery.FieldFilter): A filter on a document field. + This field is a member of `oneof`_ ``filter_type``. unary_filter (google.cloud.firestore_v1.types.StructuredQuery.UnaryFilter): A filter that takes exactly one argument. + This field is a member of `oneof`_ ``filter_type``. """ composite_filter = proto.Field( @@ -185,11 +195,14 @@ class Operator(proto.Enum): class UnaryFilter(proto.Message): r"""A filter with a single operand. + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: op (google.cloud.firestore_v1.types.StructuredQuery.UnaryFilter.Operator): The unary operator to apply. field (google.cloud.firestore_v1.types.StructuredQuery.FieldReference): The field to which to apply the operator. + This field is a member of `oneof`_ ``operand_type``. """ class Operator(proto.Enum): diff --git a/google/cloud/firestore_v1/types/write.py b/google/cloud/firestore_v1/types/write.py index fe6f0b7f32..2c895da82e 100644 --- a/google/cloud/firestore_v1/types/write.py +++ b/google/cloud/firestore_v1/types/write.py @@ -37,14 +37,24 @@ class Write(proto.Message): r"""A write on a document. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: update (google.cloud.firestore_v1.types.Document): A document to write. + This field is a member of `oneof`_ ``operation``. delete (str): A document name to delete. In the format: ``projects/{project_id}/databases/{database_id}/documents/{document_path}``. + This field is a member of `oneof`_ ``operation``. transform (google.cloud.firestore_v1.types.DocumentTransform): Applies a transformation to a document. + This field is a member of `oneof`_ ``operation``. update_mask (google.cloud.firestore_v1.types.DocumentMask): The fields to update in this write. @@ -100,6 +110,13 @@ class DocumentTransform(proto.Message): class FieldTransform(proto.Message): r"""A transformation of a field of the document. + This message has `oneof`_ fields (mutually exclusive fields). + For each oneof, at most one member field can be set at the same time. + Setting any member of the oneof automatically clears all other + members. + + .. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields + Attributes: field_path (str): The path of the field. See @@ -107,6 +124,7 @@ class FieldTransform(proto.Message): the field path syntax reference. set_to_server_value (google.cloud.firestore_v1.types.DocumentTransform.FieldTransform.ServerValue): Sets the field to the given server value. + This field is a member of `oneof`_ ``transform_type``. increment (google.cloud.firestore_v1.types.Value): Adds the given value to the field's current value. @@ -121,6 +139,7 @@ class FieldTransform(proto.Message): there is positive/negative integer overflow, the field is resolved to the largest magnitude positive/negative integer. + This field is a member of `oneof`_ ``transform_type``. maximum (google.cloud.firestore_v1.types.Value): Sets the field to the maximum of its current value and the given value. @@ -138,6 +157,7 @@ class FieldTransform(proto.Message): zero input value is always the stored value. The maximum of any numeric value x and NaN is NaN. + This field is a member of `oneof`_ ``transform_type``. minimum (google.cloud.firestore_v1.types.Value): Sets the field to the minimum of its current value and the given value. @@ -155,6 +175,7 @@ class FieldTransform(proto.Message): zero input value is always the stored value. The minimum of any numeric value x and NaN is NaN. + This field is a member of `oneof`_ ``transform_type``. append_missing_elements (google.cloud.firestore_v1.types.ArrayValue): Append the given elements in order if they are not already present in the current field value. If the field is not an @@ -168,6 +189,7 @@ class FieldTransform(proto.Message): considered. The corresponding transform_result will be the null value. + This field is a member of `oneof`_ ``transform_type``. remove_all_from_array (google.cloud.firestore_v1.types.ArrayValue): Remove all of the given elements from the array in the field. If the field is not an array, or if the field does @@ -180,6 +202,7 @@ class FieldTransform(proto.Message): duplicates. The corresponding transform_result will be the null value. + This field is a member of `oneof`_ ``transform_type``. """ class ServerValue(proto.Enum): diff --git a/setup.py b/setup.py index f047bd6b84..30033a6d5b 100644 --- a/setup.py +++ b/setup.py @@ -28,12 +28,11 @@ # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 - "google-api-core[grpc] >= 1.26.0, <3.0.0dev", + "google-api-core[grpc] >= 1.28.0, <3.0.0dev", # NOTE: Maintainers, please do not require google-api-core>=2.x.x # Until this issue is closed # https://github.com/googleapis/google-cloud-python/issues/10566 "google-cloud-core >= 1.4.1, <3.0.0dev", - "packaging >= 14.3", "proto-plus >= 1.10.0", ] extras = {} diff --git a/testing/constraints-3.6.txt b/testing/constraints-3.6.txt index 40f7b94c3f..a80f39ccbf 100644 --- a/testing/constraints-3.6.txt +++ b/testing/constraints-3.6.txt @@ -5,8 +5,7 @@ # # e.g., if setup.py has "foo >= 1.14.0, < 2.0.0dev", # Then this file should have foo==1.14.0 -google-api-core==1.26.0 +google-api-core==1.28.0 google-cloud-core==1.4.1 proto-plus==1.10.0 protobuf==3.12.0 # transitive from `google-api-core` -google-auth==1.24.0 # TODO: remove when google-auth>=1.25.0 is required through google-api-core 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 35d4f6c6de..c3345906d9 100644 --- a/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py +++ b/tests/unit/gapic/firestore_admin_v1/test_firestore_admin.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -43,9 +42,6 @@ ) from google.cloud.firestore_admin_v1.services.firestore_admin import pagers from google.cloud.firestore_admin_v1.services.firestore_admin import transports -from google.cloud.firestore_admin_v1.services.firestore_admin.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.firestore_admin_v1.types import field from google.cloud.firestore_admin_v1.types import field as gfa_field from google.cloud.firestore_admin_v1.types import firestore_admin @@ -58,20 +54,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -228,7 +210,7 @@ def test_firestore_admin_client_client_options( options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -245,7 +227,7 @@ def test_firestore_admin_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -262,7 +244,7 @@ def test_firestore_admin_client_client_options( with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -291,7 +273,7 @@ def test_firestore_admin_client_client_options( options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -350,7 +332,7 @@ def test_firestore_admin_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -392,7 +374,7 @@ def test_firestore_admin_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -414,7 +396,7 @@ def test_firestore_admin_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -445,7 +427,7 @@ def test_firestore_admin_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -476,7 +458,7 @@ def test_firestore_admin_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -2689,7 +2671,6 @@ def test_firestore_admin_base_transport(): transport.operations_client -@requires_google_auth_gte_1_25_0 def test_firestore_admin_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -2713,29 +2694,6 @@ def test_firestore_admin_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_firestore_admin_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.firestore_admin_v1.services.firestore_admin.transports.FirestoreAdminTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.FirestoreAdminTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore", - ), - quota_project_id="octopus", - ) - - def test_firestore_admin_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -2747,7 +2705,6 @@ def test_firestore_admin_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_firestore_admin_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -2763,21 +2720,6 @@ def test_firestore_admin_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_firestore_admin_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - FirestoreAdminClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [ @@ -2785,7 +2727,6 @@ def test_firestore_admin_auth_adc_old_google_auth(): transports.FirestoreAdminGrpcAsyncIOTransport, ], ) -@requires_google_auth_gte_1_25_0 def test_firestore_admin_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -2802,29 +2743,6 @@ def test_firestore_admin_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [ - transports.FirestoreAdminGrpcTransport, - transports.FirestoreAdminGrpcAsyncIOTransport, - ], -) -@requires_google_auth_lt_1_25_0 -def test_firestore_admin_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [ diff --git a/tests/unit/gapic/firestore_v1/test_firestore.py b/tests/unit/gapic/firestore_v1/test_firestore.py index 9de28358ce..92ed460dd3 100644 --- a/tests/unit/gapic/firestore_v1/test_firestore.py +++ b/tests/unit/gapic/firestore_v1/test_firestore.py @@ -15,7 +15,6 @@ # import os import mock -import packaging.version import grpc from grpc.experimental import aio @@ -36,9 +35,6 @@ from google.cloud.firestore_v1.services.firestore import FirestoreClient from google.cloud.firestore_v1.services.firestore import pagers from google.cloud.firestore_v1.services.firestore import transports -from google.cloud.firestore_v1.services.firestore.transports.base import ( - _GOOGLE_AUTH_VERSION, -) from google.cloud.firestore_v1.types import common from google.cloud.firestore_v1.types import document from google.cloud.firestore_v1.types import document as gf_document @@ -54,20 +50,6 @@ import google.auth -# TODO(busunkim): Once google-auth >= 1.25.0 is required transitively -# through google-api-core: -# - Delete the auth "less than" test cases -# - Delete these pytest markers (Make the "greater than or equal to" tests the default). -requires_google_auth_lt_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) >= packaging.version.parse("1.25.0"), - reason="This test requires google-auth < 1.25.0", -) -requires_google_auth_gte_1_25_0 = pytest.mark.skipif( - packaging.version.parse(_GOOGLE_AUTH_VERSION) < packaging.version.parse("1.25.0"), - reason="This test requires google-auth >= 1.25.0", -) - - def client_cert_source_callback(): return b"cert bytes", b"key bytes" @@ -211,7 +193,7 @@ def test_firestore_client_client_options(client_class, transport_class, transpor options = client_options.ClientOptions(api_endpoint="squid.clam.whelk") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -228,7 +210,7 @@ def test_firestore_client_client_options(client_class, transport_class, transpor with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "never"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -245,7 +227,7 @@ def test_firestore_client_client_options(client_class, transport_class, transpor with mock.patch.dict(os.environ, {"GOOGLE_API_USE_MTLS_ENDPOINT": "always"}): with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -274,7 +256,7 @@ def test_firestore_client_client_options(client_class, transport_class, transpor options = client_options.ClientOptions(quota_project_id="octopus") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -331,7 +313,7 @@ def test_firestore_client_mtls_env_auto( ) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) if use_client_cert_env == "false": expected_client_cert_source = None @@ -373,7 +355,7 @@ def test_firestore_client_mtls_env_auto( expected_client_cert_source = client_cert_source_callback patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -395,7 +377,7 @@ def test_firestore_client_mtls_env_auto( return_value=False, ): patched.return_value = None - client = client_class() + client = client_class(transport=transport_name) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -426,7 +408,7 @@ def test_firestore_client_client_options_scopes( options = client_options.ClientOptions(scopes=["1", "2"],) with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file=None, @@ -457,7 +439,7 @@ def test_firestore_client_client_options_credentials_file( options = client_options.ClientOptions(credentials_file="credentials.json") with mock.patch.object(transport_class, "__init__") as patched: patched.return_value = None - client = client_class(client_options=options) + client = client_class(transport=transport_name, client_options=options) patched.assert_called_once_with( credentials=None, credentials_file="credentials.json", @@ -3294,7 +3276,6 @@ def test_firestore_base_transport(): transport.close() -@requires_google_auth_gte_1_25_0 def test_firestore_base_transport_with_credentials_file(): # Instantiate the base transport with a credentials file with mock.patch.object( @@ -3318,29 +3299,6 @@ def test_firestore_base_transport_with_credentials_file(): ) -@requires_google_auth_lt_1_25_0 -def test_firestore_base_transport_with_credentials_file_old_google_auth(): - # Instantiate the base transport with a credentials file - with mock.patch.object( - google.auth, "load_credentials_from_file", autospec=True - ) as load_creds, mock.patch( - "google.cloud.firestore_v1.services.firestore.transports.FirestoreTransport._prep_wrapped_messages" - ) as Transport: - Transport.return_value = None - load_creds.return_value = (ga_credentials.AnonymousCredentials(), None) - transport = transports.FirestoreTransport( - credentials_file="credentials.json", quota_project_id="octopus", - ) - load_creds.assert_called_once_with( - "credentials.json", - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore", - ), - quota_project_id="octopus", - ) - - def test_firestore_base_transport_with_adc(): # Test the default credentials are used if credentials and credentials_file are None. with mock.patch.object(google.auth, "default", autospec=True) as adc, mock.patch( @@ -3352,7 +3310,6 @@ def test_firestore_base_transport_with_adc(): adc.assert_called_once() -@requires_google_auth_gte_1_25_0 def test_firestore_auth_adc(): # If no credentials are provided, we should use ADC credentials. with mock.patch.object(google.auth, "default", autospec=True) as adc: @@ -3368,26 +3325,10 @@ def test_firestore_auth_adc(): ) -@requires_google_auth_lt_1_25_0 -def test_firestore_auth_adc_old_google_auth(): - # If no credentials are provided, we should use ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - FirestoreClient() - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore", - ), - quota_project_id=None, - ) - - @pytest.mark.parametrize( "transport_class", [transports.FirestoreGrpcTransport, transports.FirestoreGrpcAsyncIOTransport,], ) -@requires_google_auth_gte_1_25_0 def test_firestore_transport_auth_adc(transport_class): # If credentials and host are not provided, the transport class should use # ADC credentials. @@ -3404,26 +3345,6 @@ def test_firestore_transport_auth_adc(transport_class): ) -@pytest.mark.parametrize( - "transport_class", - [transports.FirestoreGrpcTransport, transports.FirestoreGrpcAsyncIOTransport,], -) -@requires_google_auth_lt_1_25_0 -def test_firestore_transport_auth_adc_old_google_auth(transport_class): - # If credentials and host are not provided, the transport class should use - # ADC credentials. - with mock.patch.object(google.auth, "default", autospec=True) as adc: - adc.return_value = (ga_credentials.AnonymousCredentials(), None) - transport_class(quota_project_id="octopus") - adc.assert_called_once_with( - scopes=( - "https://www.googleapis.com/auth/cloud-platform", - "https://www.googleapis.com/auth/datastore", - ), - quota_project_id="octopus", - ) - - @pytest.mark.parametrize( "transport_class,grpc_helpers", [