Skip to content

Instantly share code, notes, and snippets.

@mcdonc
Created August 20, 2018 18:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mcdonc/7be3eeff292397b387db5143e1ffa0f4 to your computer and use it in GitHub Desktop.
Save mcdonc/7be3eeff292397b387db5143e1ffa0f4 to your computer and use it in GitHub Desktop.
_____________________________ test_watch_document ______________________________
client = <google.cloud.firestore_v1beta1.client.Client object at 0x7f5b1b24ca90>
cleanup = <built-in method append of list object at 0x7f5b18983d88>
def test_watch_document(client, cleanup):
db = client
doc_ref = db.collection(u'users').document(
u'alovelace' + unique_resource_id())
# Initial setting
doc_ref.set({
u'first': u'Jane',
u'last': u'Doe',
u'born': 1900
})
sleep(1)
# Setup listener
def on_response(response):
on_response.called_count += 1
print(f'Response: {response}')
print(type(response))
on_response.called_count = 0
doc_ref.on_snapshot(on_response)
# Alter document
doc_ref.set({
u'first': u'Ada',
u'last': u'Lovelace',
u'born': 1815
})
sleep(1)
if on_response.called_count != 1:
> raise AssertionError("Failed to get exactly one document change")
E AssertionError: Failed to get exactly one document change
tests/system.py:784: AssertionError
----------------------------- Captured stdout call -----------------------------
request generator created
------------------------------ Captured log call -------------------------------
bidi.py 506 ERROR Thread-ConsumeBidirectionalStream caught unexpected exception on_response() takes 1 positional argument but 3 were given and will exit.
Traceback (most recent call last):
File "/home/chrism/projects/gcloud/google-cloud-python-crwilcox/firestore/.nox/sys-3-6/lib/python3.6/site-packages/google/cloud/firestore_v1beta1/bidi.py", line 494, in _thread_main
self._on_response(response)
File "/home/chrism/projects/gcloud/google-cloud-python-crwilcox/firestore/.nox/sys-3-6/lib/python3.6/site-packages/google/cloud/firestore_v1beta1/watch.py", line 392, in on_snapshot
self.push(change.read_time, change.resume_token)
File "/home/chrism/projects/gcloud/google-cloud-python-crwilcox/firestore/.nox/sys-3-6/lib/python3.6/site-packages/google/cloud/firestore_v1beta1/watch.py", line 539, in push
datetime.datetime.fromtimestamp(read_time.seconds)
TypeError: on_response() takes 1 positional argument but 3 were given
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment