diff --git a/google/cloud/firestore_v1/async_document.py b/google/cloud/firestore_v1/async_document.py index dfcc5037b..a2e54492e 100644 --- a/google/cloud/firestore_v1/async_document.py +++ b/google/cloud/firestore_v1/async_document.py @@ -270,7 +270,7 @@ async def delete(self, option=None): still return the time that the request was received by the server. """ write_pb = _helpers.pb_for_delete(self._document_path, option) - commit_response = self._client._firestore_api.commit( + commit_response = await self._client._firestore_api.commit( request={ "database": self._client._database_string, "writes": [write_pb], @@ -284,7 +284,7 @@ async def delete(self, option=None): async def get(self, field_paths=None, transaction=None): """Retrieve a snapshot of the current document. - See :meth:`~google.cloud.firestore_v1.client.Client.field_path` for + See :meth:`~google.cloud.firestore_v1.base_client.BaseClient.field_path` for more information on **field paths**. If a ``transaction`` is used and it already has write operations @@ -296,12 +296,12 @@ async def get(self, field_paths=None, transaction=None): paths (``.``-delimited list of field names) to use as a projection of document fields in the returned results. If no value is provided, all fields will be returned. - transaction (Optional[:class:`~google.cloud.firestore_v1.transaction.Transaction`]): + transaction (Optional[:class:`~google.cloud.firestore_v1.async_transaction.AsyncTransaction`]): An existing transaction that this reference will be retrieved in. Returns: - :class:`~google.cloud.firestore_v1.document.DocumentSnapshot`: + :class:`~google.cloud.firestore_v1.base_document.DocumentSnapshot`: A snapshot of the current document. If the document does not exist at the time of the snapshot is taken, the snapshot's :attr:`reference`, :attr:`data`, :attr:`update_time`, and @@ -318,7 +318,7 @@ async def get(self, field_paths=None, transaction=None): firestore_api = self._client._firestore_api try: - document_pb = firestore_api.get_document( + document_pb = await firestore_api.get_document( request={ "name": self._document_path, "mask": mask, @@ -360,7 +360,7 @@ async def collections(self, page_size=None): document does not exist at the time of `snapshot`, the iterator will be empty """ - iterator = self._client._firestore_api.list_collection_ids( + iterator = await self._client._firestore_api.list_collection_ids( request={"parent": self._document_path, "page_size": page_size}, metadata=self._client._rpc_metadata, ) @@ -369,7 +369,7 @@ async def collections(self, page_size=None): for i in iterator.collection_ids: yield self.collection(i) if iterator.next_page_token: - iterator = self._client._firestore_api.list_collection_ids( + iterator = await self._client._firestore_api.list_collection_ids( request={ "parent": self._document_path, "page_size": page_size, diff --git a/google/cloud/firestore_v1/document.py b/google/cloud/firestore_v1/document.py index 48816e563..4d5d42aa4 100644 --- a/google/cloud/firestore_v1/document.py +++ b/google/cloud/firestore_v1/document.py @@ -284,7 +284,7 @@ def delete(self, option=None): def get(self, field_paths=None, transaction=None): """Retrieve a snapshot of the current document. - See :meth:`~google.cloud.firestore_v1.client.Client.field_path` for + See :meth:`~google.cloud.firestore_v1.base_client.BaseClient.field_path` for more information on **field paths**. If a ``transaction`` is used and it already has write operations @@ -301,7 +301,7 @@ def get(self, field_paths=None, transaction=None): will be retrieved in. Returns: - :class:`~google.cloud.firestore_v1.document.DocumentSnapshot`: + :class:`~google.cloud.firestore_v1.base_document.DocumentSnapshot`: A snapshot of the current document. If the document does not exist at the time of the snapshot is taken, the snapshot's :attr:`reference`, :attr:`data`, :attr:`update_time`, and diff --git a/tests/unit/v1/test_async_document.py b/tests/unit/v1/test_async_document.py index 71e3ce4a8..6d5c1f5d1 100644 --- a/tests/unit/v1/test_async_document.py +++ b/tests/unit/v1/test_async_document.py @@ -17,6 +17,7 @@ import aiounittest import mock +from tests.unit.v1.test__helpers import AsyncMock class TestAsyncDocumentReference(aiounittest.AsyncTestCase): @@ -286,7 +287,7 @@ async def _delete_helper(self, **option_kwargs): from google.cloud.firestore_v1.types import write # Create a minimal fake GAPIC with a dummy response. - firestore_api = mock.Mock(spec=["commit"]) + firestore_api = AsyncMock(spec=["commit"]) firestore_api.commit.return_value = self._make_commit_repsonse() # Attach the fake GAPIC to a real client. @@ -339,7 +340,7 @@ async def _get_helper( # Create a minimal fake GAPIC with a dummy response. create_time = 123 update_time = 234 - firestore_api = mock.Mock(spec=["get_document"]) + firestore_api = AsyncMock(spec=["get_document"]) response = mock.create_autospec(document.Document) response.fields = {} response.create_time = create_time @@ -427,7 +428,6 @@ async def _collections_helper(self, page_size=None): from google.api_core.page_iterator import Iterator from google.api_core.page_iterator import Page from google.cloud.firestore_v1.async_collection import AsyncCollectionReference - from google.cloud.firestore_v1.services.firestore.client import FirestoreClient # TODO(microgen): https://github.com/googleapis/gapic-generator-python/issues/516 class _Iterator(Iterator): @@ -443,11 +443,12 @@ def _next_page(self): collection_ids = ["coll-1", "coll-2"] iterator = _Iterator(pages=[collection_ids]) - api_client = mock.create_autospec(FirestoreClient) - api_client.list_collection_ids.return_value = iterator + firestore_api = AsyncMock() + firestore_api.mock_add_spec(spec=["list_collection_ids"]) + firestore_api.list_collection_ids.return_value = iterator client = _make_client() - client._firestore_api_internal = api_client + client._firestore_api_internal = firestore_api # Actually make a document and call delete(). document = self._make_one("where", "we-are", client=client) @@ -463,7 +464,7 @@ def _next_page(self): self.assertEqual(collection.parent, document) self.assertEqual(collection.id, collection_id) - api_client.list_collection_ids.assert_called_once_with( + firestore_api.list_collection_ids.assert_called_once_with( request={"parent": document._document_path, "page_size": page_size}, metadata=client._rpc_metadata, )