From 01df257e8c9e540055ea2c91891eed3ec074cc03 Mon Sep 17 00:00:00 2001 From: Frank Natividad Date: Fri, 19 Oct 2018 15:40:55 -0700 Subject: [PATCH 1/2] Add snapshot cursors sample --- firestore/cloud-client/snippets.py | 13 +++++++++++++ firestore/cloud-client/snippets_test.py | 4 ++++ 2 files changed, 17 insertions(+) diff --git a/firestore/cloud-client/snippets.py b/firestore/cloud-client/snippets.py index 67545df4ac9..759b8379030 100644 --- a/firestore/cloud-client/snippets.py +++ b/firestore/cloud-client/snippets.py @@ -557,6 +557,19 @@ def cursor_simple_end_at(): return query_end_at +def snapshot_cursors(): + db = firestore.Client() + # [START fs_start_at_snapshot_query_cursor] + doc_ref = db.collection(u'cities').document(u'SF') + + snapshot = doc_ref.get() + start_at_snapshot = db.collection( + u'cities').order_by(u'population').start_at(snapshot) + + return start_at_snapshot.limit(10).get() + # [END fs_start_at_snapshot_query_cursor] + + def cursor_paginate(): db = firestore.Client() # [START cursor_paginate] diff --git a/firestore/cloud-client/snippets_test.py b/firestore/cloud-client/snippets_test.py index f3e6bdaf4b7..4a1172e54ea 100644 --- a/firestore/cloud-client/snippets_test.py +++ b/firestore/cloud-client/snippets_test.py @@ -195,6 +195,10 @@ def test_cursor_simple_end_at(): snippets.cursor_simple_end_at() +def test_snapshot_cursors(): + snippets.snapshot_cursors() + + def test_cursor_paginate(): snippets.cursor_paginate() From 04ed1160338d0210edbffa1de9f93653f532e332 Mon Sep 17 00:00:00 2001 From: Frank Natividad Date: Wed, 24 Oct 2018 15:58:23 -0700 Subject: [PATCH 2/2] Updating sample with a test --- firestore/cloud-client/snippets.py | 7 +++++-- firestore/cloud-client/snippets_test.py | 6 +++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/firestore/cloud-client/snippets.py b/firestore/cloud-client/snippets.py index 759b8379030..bd55e9bac59 100644 --- a/firestore/cloud-client/snippets.py +++ b/firestore/cloud-client/snippets.py @@ -565,9 +565,12 @@ def snapshot_cursors(): snapshot = doc_ref.get() start_at_snapshot = db.collection( u'cities').order_by(u'population').start_at(snapshot) - - return start_at_snapshot.limit(10).get() # [END fs_start_at_snapshot_query_cursor] + results = start_at_snapshot.limit(10).get() + for doc in results: + print('{}'.format(doc.id)) + + return results def cursor_paginate(): diff --git a/firestore/cloud-client/snippets_test.py b/firestore/cloud-client/snippets_test.py index 4a1172e54ea..98bf4be7357 100644 --- a/firestore/cloud-client/snippets_test.py +++ b/firestore/cloud-client/snippets_test.py @@ -195,8 +195,12 @@ def test_cursor_simple_end_at(): snippets.cursor_simple_end_at() -def test_snapshot_cursors(): +def test_snapshot_cursors(capsys): snippets.snapshot_cursors() + out, _ = capsys.readouterr() + assert "SF" in out + assert "TOK" in out + assert "BJ" in out def test_cursor_paginate():