def document(self, *document_path: str) -> AsyncDocumentReference: """Get a reference to a document in a collection. For a top-level document: .. code-block:: python >>> client.document('collek/shun') >>> # is the same as >>> client.document('collek', 'shun') For a document in a sub-collection: .. code-block:: python >>> client.document('mydocs/doc/subcol/child') >>> # is the same as >>> client.document('mydocs', 'doc', 'subcol', 'child') Documents in sub-collections can be nested deeper in a similar fashion. Args: document_path: Can either be * A single ``/``-delimited path to a document * A tuple of document path segments Returns: :class:`~google.cloud.firestore_v1.document.AsyncDocumentReference`: A reference to a document in a collection. """ return AsyncDocumentReference( *self._document_path_helper(*document_path), client=self)
async def test_get_document_ref(self): from google.cloud.firestore_v1.async_document import AsyncDocumentReference client = AsyncMock(spec=["get_all"]) transaction = self._make_one(client) ref = AsyncDocumentReference("documents", "doc-id") result = await transaction.get(ref) client.get_all.assert_called_once_with([ref], transaction=transaction) self.assertIs(result, client.get_all.return_value)
async def _get_w_document_ref_helper(retry=None, timeout=None): from google.cloud.firestore_v1.async_document import AsyncDocumentReference from google.cloud.firestore_v1 import _helpers client = AsyncMock(spec=["get_all"]) transaction = _make_async_transaction(client) ref = AsyncDocumentReference("documents", "doc-id") kwargs = _helpers.make_retry_timeout_kwargs(retry, timeout) result = await transaction.get(ref, **kwargs) client.get_all.assert_called_once_with([ref], transaction=transaction, **kwargs) assert result is client.get_all.return_value
def _make_async_document_reference(*args, **kwargs): from google.cloud.firestore_v1.async_document import AsyncDocumentReference return AsyncDocumentReference(*args, **kwargs)