Skip to content

Commit

Permalink
feat: asyncio microgen batch (#122)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
rafilong committed Jul 23, 2020
1 parent 31faecb commit a4e5b00
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
2 changes: 1 addition & 1 deletion google/cloud/firestore_v1/async_batch.py
Expand Up @@ -42,7 +42,7 @@ async def commit(self):
in the same order as the changes were applied to this batch. A
write result contains an ``update_time`` field.
"""
commit_response = self._client._firestore_api.commit(
commit_response = await self._client._firestore_api.commit(
request={
"database": self._client._database_string,
"writes": self._write_pbs,
Expand Down
7 changes: 4 additions & 3 deletions tests/unit/v1/test_async_batch.py
Expand Up @@ -16,6 +16,7 @@
import aiounittest

import mock
from tests.unit.v1.test__helpers import AsyncMock


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

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

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

@pytest.mark.asyncio
async def test_as_context_mgr_w_error(self):
firestore_api = mock.Mock(spec=["commit"])
firestore_api = AsyncMock(spec=["commit"])
client = _make_client()
client._firestore_api_internal = firestore_api
batch = self._make_one(client)
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/v1/test_async_collection.py
Expand Up @@ -87,7 +87,7 @@ async def test_add_auto_assigned(self):
from google.cloud.firestore_v1._helpers import pbs_for_create

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

# Create a minimal fake GAPIC with a dummy response.
firestore_api = mock.Mock(spec=["commit"])
firestore_api = AsyncMock(spec=["commit"])
write_result = mock.Mock(
update_time=mock.sentinel.update_time, spec=["update_time"]
)
Expand Down
10 changes: 5 additions & 5 deletions tests/unit/v1/test_async_document.py
Expand Up @@ -74,7 +74,7 @@ def _write_pb_for_create(document_path, document_data):
@pytest.mark.asyncio
async def test_create(self):
# Create a minimal fake GAPIC with a dummy response.
firestore_api = mock.Mock()
firestore_api = AsyncMock()
firestore_api.commit.mock_add_spec(spec=["commit"])
firestore_api.commit.return_value = self._make_commit_repsonse()

Expand Down Expand Up @@ -105,7 +105,7 @@ async def test_create_empty(self):
from google.cloud.firestore_v1.async_document import AsyncDocumentReference
from google.cloud.firestore_v1.async_document import DocumentSnapshot

firestore_api = mock.Mock(spec=["commit"])
firestore_api = AsyncMock(spec=["commit"])
document_reference = mock.create_autospec(AsyncDocumentReference)
snapshot = mock.create_autospec(DocumentSnapshot)
snapshot.exists = True
Expand Down Expand Up @@ -155,7 +155,7 @@ def _write_pb_for_set(document_path, document_data, merge):
@pytest.mark.asyncio
async def _set_helper(self, merge=False, **option_kwargs):
# 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.
Expand Down Expand Up @@ -208,7 +208,7 @@ async def _update_helper(self, **option_kwargs):
from google.cloud.firestore_v1.transforms import DELETE_FIELD

# 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.
Expand Down Expand Up @@ -268,7 +268,7 @@ async def test_update_with_precondition(self):
@pytest.mark.asyncio
async def test_empty_update(self):
# 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.
Expand Down

0 comments on commit a4e5b00

Please sign in to comment.