Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: asyncio microgen collection #119

Merged
merged 6 commits into from Jul 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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