Skip to content

Commit beaa6d7

Browse files
committed
Integration test for rtdb listeners
1 parent 120b056 commit beaa6d7

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

integration/test_db.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import collections
1717
import json
1818
import os
19+
import time
1920

2021
import pytest
2122

@@ -245,6 +246,37 @@ def test_delete(self, testref):
245246
ref.delete()
246247
assert ref.get() is None
247248

249+
class TestListenOperations:
250+
"""Test cases for listening to changes to node values."""
251+
252+
def test_listen(self, testref):
253+
self.events = []
254+
def callback(event):
255+
self.events.append(event)
256+
257+
python = testref.parent
258+
registration = python.listen(callback)
259+
try:
260+
ref = python.child('users').push()
261+
assert ref.path == '/_adminsdk/python/users/' + ref.key
262+
assert ref.get() == ''
263+
264+
self.wait_for(self.events, count=2)
265+
assert len(self.events) == 2
266+
267+
assert self.events[1].event_type == 'put'
268+
assert self.events[1].path == '/users/' + ref.key
269+
assert self.events[1].data == ''
270+
finally:
271+
registration.close()
272+
273+
@classmethod
274+
def wait_for(cls, events, count=1, timeout_seconds=5):
275+
must_end = time.time() + timeout_seconds
276+
while time.time() < must_end:
277+
if len(events) >= count:
278+
return
279+
raise pytest.fail('Timed out while waiting for events')
248280

249281
class TestAdvancedQueries:
250282
"""Test cases for advanced interactions via the db.Query interface."""

0 commit comments

Comments
 (0)