Skip to content

Commit

Permalink
feat: asyncio microgen collection (#119)
Browse files Browse the repository at this point in the history
* feat: make collections call backed by async

* fix: failing asyncmock assertion

* fix: lint

* refactor: move AsyncMock to test helpers

* feat: integrate microgen async client to collection

* fix: lint
  • Loading branch information
rafilong committed Jul 22, 2020
1 parent de4cc44 commit 6281a67
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
2 changes: 1 addition & 1 deletion google/cloud/firestore_v1/async_collection.py
Expand Up @@ -110,7 +110,7 @@ async def list_documents(self, page_size=None):
"""
parent, _ = self._parent_info()

iterator = self._client._firestore_api.list_documents(
iterator = await self._client._firestore_api.list_documents(
request={
"parent": parent,
"collection_id": self.id,
Expand Down
11 changes: 6 additions & 5 deletions tests/unit/v1/test_async_collection.py
Expand Up @@ -17,6 +17,7 @@
import aiounittest

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


class MockAsyncIter:
Expand Down Expand Up @@ -196,7 +197,6 @@ async def _list_documents_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_document import AsyncDocumentReference
from google.cloud.firestore_v1.services.firestore.client import FirestoreClient
from google.cloud.firestore_v1.types.document import Document

class _Iterator(Iterator):
Expand All @@ -216,9 +216,10 @@ def _next_page(self):
Document(name=template.format(document_id)) for document_id in document_ids
]
iterator = _Iterator(pages=[documents])
api_client = mock.create_autospec(FirestoreClient)
api_client.list_documents.return_value = iterator
client._firestore_api_internal = api_client
firestore_api = AsyncMock()
firestore_api.mock_add_spec(spec=["list_documents"])
firestore_api.list_documents.return_value = iterator
client._firestore_api_internal = firestore_api
collection = self._make_one("collection", client=client)

if page_size is not None:
Expand All @@ -234,7 +235,7 @@ def _next_page(self):
self.assertEqual(document.id, document_id)

parent, _ = collection._parent_info()
api_client.list_documents.assert_called_once_with(
firestore_api.list_documents.assert_called_once_with(
request={
"parent": parent,
"collection_id": collection.id,
Expand Down

0 comments on commit 6281a67

Please sign in to comment.