Skip to content

Commit

Permalink
fix: update type hint for async_collection.document() to AsyncDocumen… (
Browse files Browse the repository at this point in the history
#370)

…tReference

Fixes #369 🦕
  • Loading branch information
kolea2 committed Jun 16, 2021
1 parent 77e6ced commit ee6a1c2
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
17 changes: 17 additions & 0 deletions google/cloud/firestore_v1/async_collection.py
Expand Up @@ -112,6 +112,23 @@ async def add(
write_result = await document_ref.create(document_data, **kwargs)
return write_result.update_time, document_ref

def document(
self, document_id: str = None
) -> async_document.AsyncDocumentReference:
"""Create a sub-document underneath the current collection.
Args:
document_id (Optional[str]): The document identifier
within the current collection. If not provided, will default
to a random 20 character string composed of digits,
uppercase and lowercase and letters.
Returns:
:class:`~google.cloud.firestore_v1.document.async_document.AsyncDocumentReference`:
The child document.
"""
return super(AsyncCollectionReference, self).document(document_id)

async def list_documents(
self,
page_size: int = None,
Expand Down
6 changes: 6 additions & 0 deletions tests/unit/v1/test_async_collection.py
Expand Up @@ -57,6 +57,12 @@ def test_query_method_matching(self):
# ``AsyncCollectionReference``.
self.assertLessEqual(query_methods, collection_methods)

def test_document_name_default(self):
client = _make_client()
document = client.collection("test").document()
# name is random, but assert it is not None
self.assertTrue(document.id is not None)

def test_constructor(self):
collection_id1 = "rooms"
document_id = "roomA"
Expand Down

0 comments on commit ee6a1c2

Please sign in to comment.