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

fix: asyncio microgen client get_all type #126

Merged
merged 2 commits into from Jul 23, 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_client.py
Expand Up @@ -252,7 +252,7 @@ async def get_all(self, references, field_paths=None, transaction=None):
metadata=self._rpc_metadata,
)

for get_doc_response in response_iterator:
async for get_doc_response in response_iterator:
yield _parse_batch_get(get_doc_response, reference_map, self)

async def collections(self):
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/v1/test__helpers.py
Expand Up @@ -25,6 +25,15 @@ async def __call__(self, *args, **kwargs):
return super(AsyncMock, self).__call__(*args, **kwargs)


class AsyncIter:
def __init__(self, items):
self.items = items

async def __aiter__(self, **_):
for i in self.items:
yield i


class TestGeoPoint(unittest.TestCase):
@staticmethod
def _get_target_class():
Expand Down
4 changes: 2 additions & 2 deletions tests/unit/v1/test_async_client.py
Expand Up @@ -18,7 +18,7 @@
import aiounittest

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


class TestAsyncClient(aiounittest.AsyncTestCase):
Expand Down Expand Up @@ -237,7 +237,7 @@ def _next_page(self):
async def _get_all_helper(self, client, references, document_pbs, **kwargs):
# Create a minimal fake GAPIC with a dummy response.
firestore_api = mock.Mock(spec=["batch_get_documents"])
response_iterator = iter(document_pbs)
response_iterator = AsyncIter(document_pbs)
firestore_api.batch_get_documents.return_value = response_iterator

# Attach the fake GAPIC to a real client.
Expand Down
19 changes: 5 additions & 14 deletions tests/unit/v1/test_async_collection.py
Expand Up @@ -17,16 +17,7 @@
import aiounittest

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


class MockAsyncIter:
def __init__(self, count):
self.count = count

async def __aiter__(self, **_):
for i in range(self.count):
yield i
from tests.unit.v1.test__helpers import AsyncMock, AsyncIter


class TestAsyncCollectionReference(aiounittest.AsyncTestCase):
Expand Down Expand Up @@ -258,7 +249,7 @@ async def test_list_documents_w_page_size(self):
async def test_get(self, query_class):
import warnings

query_class.return_value.stream.return_value = MockAsyncIter(3)
query_class.return_value.stream.return_value = AsyncIter(range(3))

collection = self._make_one("collection")
with warnings.catch_warnings(record=True) as warned:
Expand All @@ -280,7 +271,7 @@ async def test_get(self, query_class):
async def test_get_with_transaction(self, query_class):
import warnings

query_class.return_value.stream.return_value = MockAsyncIter(3)
query_class.return_value.stream.return_value = AsyncIter(range(3))

collection = self._make_one("collection")
transaction = mock.sentinel.txn
Expand All @@ -301,7 +292,7 @@ async def test_get_with_transaction(self, query_class):
@mock.patch("google.cloud.firestore_v1.async_query.AsyncQuery", autospec=True)
@pytest.mark.asyncio
async def test_stream(self, query_class):
query_class.return_value.stream.return_value = MockAsyncIter(3)
query_class.return_value.stream.return_value = AsyncIter(range(3))

collection = self._make_one("collection")
stream_response = collection.stream()
Expand All @@ -316,7 +307,7 @@ async def test_stream(self, query_class):
@mock.patch("google.cloud.firestore_v1.async_query.AsyncQuery", autospec=True)
@pytest.mark.asyncio
async def test_stream_with_transaction(self, query_class):
query_class.return_value.stream.return_value = MockAsyncIter(3)
query_class.return_value.stream.return_value = AsyncIter(range(3))

collection = self._make_one("collection")
transaction = mock.sentinel.txn
Expand Down