async def _collections_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_collection import AsyncCollectionReference # TODO(microgen): https://github.com/googleapis/gapic-generator-python/issues/516 class _Iterator(Iterator): def __init__(self, pages): super(_Iterator, self).__init__(client=None) self._pages = pages self.collection_ids = pages[0] def _next_page(self): if self._pages: page, self._pages = self._pages[0], self._pages[1:] return Page(self, page, self.item_to_value) collection_ids = ["coll-1", "coll-2"] iterator = _Iterator(pages=[collection_ids]) firestore_api = AsyncMock() firestore_api.mock_add_spec(spec=["list_collection_ids"]) firestore_api.list_collection_ids.return_value = iterator client = _make_client() client._firestore_api_internal = firestore_api # Actually make a document and call delete(). document = self._make_one("where", "we-are", client=client) if page_size is not None: collections = [ c async for c in document.collections(page_size=page_size) ] else: collections = [c async for c in document.collections()] # Verify the response and the mocks. self.assertEqual(len(collections), len(collection_ids)) for collection, collection_id in zip(collections, collection_ids): self.assertIsInstance(collection, AsyncCollectionReference) self.assertEqual(collection.parent, document) self.assertEqual(collection.id, collection_id) firestore_api.list_collection_ids.assert_called_once_with( request={ "parent": document._document_path, "page_size": page_size }, metadata=client._rpc_metadata, )
async def _collections_helper(self, page_size=None, retry=None, timeout=None): from google.cloud.firestore_v1 import _helpers from google.cloud.firestore_v1.async_collection import AsyncCollectionReference collection_ids = ["coll-1", "coll-2"] class Pager(object): async def __aiter__(self, **_): for collection_id in collection_ids: yield collection_id firestore_api = AsyncMock() firestore_api.mock_add_spec(spec=["list_collection_ids"]) firestore_api.list_collection_ids.return_value = Pager() client = _make_client() client._firestore_api_internal = firestore_api kwargs = _helpers.make_retry_timeout_kwargs(retry, timeout) # Actually make a document and call delete(). document = self._make_one("where", "we-are", client=client) if page_size is not None: collections = [ c async for c in document.collections(page_size=page_size, **kwargs) ] else: collections = [c async for c in document.collections(**kwargs)] # Verify the response and the mocks. self.assertEqual(len(collections), len(collection_ids)) for collection, collection_id in zip(collections, collection_ids): self.assertIsInstance(collection, AsyncCollectionReference) self.assertEqual(collection.parent, document) self.assertEqual(collection.id, collection_id) firestore_api.list_collection_ids.assert_called_once_with( request={ "parent": document._document_path, "page_size": page_size }, metadata=client._rpc_metadata, **kwargs, )
def _collections_helper(self, page_size=None, retry=None, timeout=None): from google.cloud.firestore_v1.collection import CollectionReference from google.cloud.firestore_v1 import _helpers from google.cloud.firestore_v1.services.firestore.client import FirestoreClient collection_ids = ["coll-1", "coll-2"] class Pager(object): def __iter__(self): yield from collection_ids api_client = mock.create_autospec(FirestoreClient) api_client.list_collection_ids.return_value = Pager() client = _make_client() client._firestore_api_internal = api_client kwargs = _helpers.make_retry_timeout_kwargs(retry, timeout) # Actually make a document and call delete(). document = self._make_one("where", "we-are", client=client) if page_size is not None: collections = list( document.collections(page_size=page_size, **kwargs)) else: collections = list(document.collections(**kwargs)) # Verify the response and the mocks. self.assertEqual(len(collections), len(collection_ids)) for collection, collection_id in zip(collections, collection_ids): self.assertIsInstance(collection, CollectionReference) self.assertEqual(collection.parent, document) self.assertEqual(collection.id, collection_id) api_client.list_collection_ids.assert_called_once_with( request={ "parent": document._document_path, "page_size": page_size }, metadata=client._rpc_metadata, **kwargs, )