Skip to content

Commit a4e5b00

Browse files
authored
feat: asyncio microgen batch (#122)
* refactor: move generated client instantiation out of base class * feat: integrate microgen async client to client * feat: make collections call backed by async * fix: failing asyncmock assertion * refactor: remove unused install * fix: lint * refactor: shared functionality in client to base class * refactor: move AsyncMock to test helpers * fix: return type in client docs * feat: integrate microgen async client to collection * fix: lint * feat: integrate microgen async client to document * feat: integrate microgen async client to batch * fix: use AsyncMock for batch async tests: * fix: collection and document testing batch
1 parent 31faecb commit a4e5b00

File tree

4 files changed

+12
-11
lines changed

4 files changed

+12
-11
lines changed

‎google/cloud/firestore_v1/async_batch.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ async def commit(self):
4242
in the same order as the changes were applied to this batch. A
4343
write result contains an ``update_time`` field.
4444
"""
45-
commit_response = self._client._firestore_api.commit(
45+
commit_response = await self._client._firestore_api.commit(
4646
request={
4747
"database": self._client._database_string,
4848
"writes": self._write_pbs,

‎tests/unit/v1/test_async_batch.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import aiounittest
1717

1818
import mock
19+
from tests.unit.v1.test__helpers import AsyncMock
1920

2021

2122
class TestAsyncWriteBatch(aiounittest.AsyncTestCase):
@@ -43,7 +44,7 @@ async def test_commit(self):
4344
from google.cloud.firestore_v1.types import write
4445

4546
# Create a minimal fake GAPIC with a dummy result.
46-
firestore_api = mock.Mock(spec=["commit"])
47+
firestore_api = AsyncMock(spec=["commit"])
4748
timestamp = timestamp_pb2.Timestamp(seconds=1234567, nanos=123456798)
4849
commit_response = firestore.CommitResponse(
4950
write_results=[write.WriteResult(), write.WriteResult()],
@@ -87,7 +88,7 @@ async def test_as_context_mgr_wo_error(self):
8788
from google.cloud.firestore_v1.types import firestore
8889
from google.cloud.firestore_v1.types import write
8990

90-
firestore_api = mock.Mock(spec=["commit"])
91+
firestore_api = AsyncMock(spec=["commit"])
9192
timestamp = timestamp_pb2.Timestamp(seconds=1234567, nanos=123456798)
9293
commit_response = firestore.CommitResponse(
9394
write_results=[write.WriteResult(), write.WriteResult()],
@@ -124,7 +125,7 @@ async def test_as_context_mgr_wo_error(self):
124125

125126
@pytest.mark.asyncio
126127
async def test_as_context_mgr_w_error(self):
127-
firestore_api = mock.Mock(spec=["commit"])
128+
firestore_api = AsyncMock(spec=["commit"])
128129
client = _make_client()
129130
client._firestore_api_internal = firestore_api
130131
batch = self._make_one(client)

‎tests/unit/v1/test_async_collection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ async def test_add_auto_assigned(self):
8787
from google.cloud.firestore_v1._helpers import pbs_for_create
8888

8989
# Create a minimal fake GAPIC add attach it to a real client.
90-
firestore_api = mock.Mock(spec=["create_document", "commit"])
90+
firestore_api = AsyncMock(spec=["create_document", "commit"])
9191
write_result = mock.Mock(
9292
update_time=mock.sentinel.update_time, spec=["update_time"]
9393
)
@@ -153,7 +153,7 @@ async def test_add_explicit_id(self):
153153
from google.cloud.firestore_v1.async_document import AsyncDocumentReference
154154

155155
# Create a minimal fake GAPIC with a dummy response.
156-
firestore_api = mock.Mock(spec=["commit"])
156+
firestore_api = AsyncMock(spec=["commit"])
157157
write_result = mock.Mock(
158158
update_time=mock.sentinel.update_time, spec=["update_time"]
159159
)

‎tests/unit/v1/test_async_document.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ def _write_pb_for_create(document_path, document_data):
7474
@pytest.mark.asyncio
7575
async def test_create(self):
7676
# Create a minimal fake GAPIC with a dummy response.
77-
firestore_api = mock.Mock()
77+
firestore_api = AsyncMock()
7878
firestore_api.commit.mock_add_spec(spec=["commit"])
7979
firestore_api.commit.return_value = self._make_commit_repsonse()
8080

@@ -105,7 +105,7 @@ async def test_create_empty(self):
105105
from google.cloud.firestore_v1.async_document import AsyncDocumentReference
106106
from google.cloud.firestore_v1.async_document import DocumentSnapshot
107107

108-
firestore_api = mock.Mock(spec=["commit"])
108+
firestore_api = AsyncMock(spec=["commit"])
109109
document_reference = mock.create_autospec(AsyncDocumentReference)
110110
snapshot = mock.create_autospec(DocumentSnapshot)
111111
snapshot.exists = True
@@ -155,7 +155,7 @@ def _write_pb_for_set(document_path, document_data, merge):
155155
@pytest.mark.asyncio
156156
async def _set_helper(self, merge=False, **option_kwargs):
157157
# Create a minimal fake GAPIC with a dummy response.
158-
firestore_api = mock.Mock(spec=["commit"])
158+
firestore_api = AsyncMock(spec=["commit"])
159159
firestore_api.commit.return_value = self._make_commit_repsonse()
160160

161161
# Attach the fake GAPIC to a real client.
@@ -208,7 +208,7 @@ async def _update_helper(self, **option_kwargs):
208208
from google.cloud.firestore_v1.transforms import DELETE_FIELD
209209

210210
# Create a minimal fake GAPIC with a dummy response.
211-
firestore_api = mock.Mock(spec=["commit"])
211+
firestore_api = AsyncMock(spec=["commit"])
212212
firestore_api.commit.return_value = self._make_commit_repsonse()
213213

214214
# Attach the fake GAPIC to a real client.
@@ -268,7 +268,7 @@ async def test_update_with_precondition(self):
268268
@pytest.mark.asyncio
269269
async def test_empty_update(self):
270270
# Create a minimal fake GAPIC with a dummy response.
271-
firestore_api = mock.Mock(spec=["commit"])
271+
firestore_api = AsyncMock(spec=["commit"])
272272
firestore_api.commit.return_value = self._make_commit_repsonse()
273273

274274
# Attach the fake GAPIC to a real client.

0 commit comments

Comments
 (0)