Skip to content

Commit

Permalink
Added system test for DocumentReference.collections
Browse files Browse the repository at this point in the history
  • Loading branch information
gkevinzheng committed Jan 30, 2025
1 parent ffae9bc commit 0bc5302
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -740,6 +740,38 @@ def test_create_document_w_subcollection(client, cleanup, database):
assert sorted(child.id for child in children) == sorted(child_ids)


@pytest.mark.parametrize("database", [None, FIRESTORE_OTHER_DB], indirect=True)
def test_document_collections_w_read_time(client, cleanup, database):
collection_id = "doc-create-sub" + UNIQUE_RESOURCE_ID
document_id = "doc" + UNIQUE_RESOURCE_ID
document = client.document(collection_id, document_id)
# Add to clean-up before API request (in case ``create()`` fails).
cleanup(document.delete)

data = {"now": firestore.SERVER_TIMESTAMP}
document.create(data)

original_child_ids = ["child1", "child2"]
read_time = None

for child_id in original_child_ids:
subcollection = document.collection(child_id)
update_time, subdoc = subcollection.add({"foo": "bar"})
read_time = update_time if read_time is None or update_time > read_time else read_time
cleanup(subdoc.delete)

update_time, newdoc = document.collection("child3").add({"foo": "bar"})
cleanup(newdoc.delete)
assert update_time > read_time

# Compare the query at read_time to the query at new update time.
original_children = document.collections(read_time=read_time)
assert sorted(child.id for child in original_children) == sorted(original_child_ids)

original_children = document.collections()
assert sorted(child.id for child in original_children) == sorted(original_child_ids + ["child3"])


def assert_timestamp_less(timestamp_pb1, timestamp_pb2):
assert timestamp_pb1 < timestamp_pb2

Expand Down

0 comments on commit 0bc5302

Please sign in to comment.