File tree Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Expand file tree Collapse file tree 1 file changed +32
-0
lines changed Original file line number Diff line number Diff line change 16
16
import collections
17
17
import json
18
18
import os
19
+ import time
19
20
20
21
import pytest
21
22
@@ -245,6 +246,37 @@ def test_delete(self, testref):
245
246
ref .delete ()
246
247
assert ref .get () is None
247
248
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' )
248
280
249
281
class TestAdvancedQueries :
250
282
"""Test cases for advanced interactions via the db.Query interface."""
You can’t perform that action at this time.
0 commit comments