Skip to content

Commit 0bc5302

Browse files
committed
Added system test for DocumentReference.collections
1 parent ffae9bc commit 0bc5302

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

tests/system/test_system.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -740,6 +740,38 @@ def test_create_document_w_subcollection(client, cleanup, database):
740740
assert sorted(child.id for child in children) == sorted(child_ids)
741741

742742

743+
@pytest.mark.parametrize("database", [None, FIRESTORE_OTHER_DB], indirect=True)
744+
def test_document_collections_w_read_time(client, cleanup, database):
745+
collection_id = "doc-create-sub" + UNIQUE_RESOURCE_ID
746+
document_id = "doc" + UNIQUE_RESOURCE_ID
747+
document = client.document(collection_id, document_id)
748+
# Add to clean-up before API request (in case ``create()`` fails).
749+
cleanup(document.delete)
750+
751+
data = {"now": firestore.SERVER_TIMESTAMP}
752+
document.create(data)
753+
754+
original_child_ids = ["child1", "child2"]
755+
read_time = None
756+
757+
for child_id in original_child_ids:
758+
subcollection = document.collection(child_id)
759+
update_time, subdoc = subcollection.add({"foo": "bar"})
760+
read_time = update_time if read_time is None or update_time > read_time else read_time
761+
cleanup(subdoc.delete)
762+
763+
update_time, newdoc = document.collection("child3").add({"foo": "bar"})
764+
cleanup(newdoc.delete)
765+
assert update_time > read_time
766+
767+
# Compare the query at read_time to the query at new update time.
768+
original_children = document.collections(read_time=read_time)
769+
assert sorted(child.id for child in original_children) == sorted(original_child_ids)
770+
771+
original_children = document.collections()
772+
assert sorted(child.id for child in original_children) == sorted(original_child_ids + ["child3"])
773+
774+
743775
def assert_timestamp_less(timestamp_pb1, timestamp_pb2):
744776
assert timestamp_pb1 < timestamp_pb2
745777

0 commit comments

Comments
 (0)