aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLorenz Diener <[email protected]>2018-05-06 02:00:18 +0200
committerLorenz Diener <[email protected]>2018-05-06 02:00:18 +0200
commit3864bbe0859e6c010a3a796467fd48d896734644 (patch)
tree3749708e98f01e9e3c945d1ef2e3d8962d75107c /tests/test_streaming.py
parent4088e16dec90adfcf0352bb3242ba8557f6b73c6 (diff)
downloadmastodon.py-3864bbe0859e6c010a3a796467fd48d896734644.tar.gz
More streaming tests
Diffstat (limited to 'tests/test_streaming.py')
-rw-r--r--tests/test_streaming.py46
1 files changed, 41 insertions, 5 deletions
diff --git a/tests/test_streaming.py b/tests/test_streaming.py
index 8c2160a..08d05b3 100644
--- a/tests/test_streaming.py
+++ b/tests/test_streaming.py
@@ -257,9 +257,11 @@ def test_stream_user(api, api2):
257 257
258 updates = [] 258 updates = []
259 notifications = [] 259 notifications = []
260 deletes = []
260 listener = CallbackStreamListener( 261 listener = CallbackStreamListener(
261 update_handler = lambda x: updates.append(x), 262 update_handler = lambda x: updates.append(x),
262 notification_handler = lambda x: notifications.append(x) 263 notification_handler = lambda x: notifications.append(x),
264 delete_handler = lambda x: deletes.append(x)
263 ) 265 )
264 266
265 posted = [] 267 posted = []
@@ -268,7 +270,9 @@ def test_stream_user(api, api2):
268 posted.append(api.status_post("only real cars respond.")) 270 posted.append(api.status_post("only real cars respond."))
269 posted.append(api2.status_post("@mastodonpy_test beep beep I'm a jeep")) 271 posted.append(api2.status_post("@mastodonpy_test beep beep I'm a jeep"))
270 posted.append(api2.status_post("on the internet, nobody knows you're a plane")) 272 posted.append(api2.status_post("on the internet, nobody knows you're a plane"))
271 time.sleep(3) 273 time.sleep(1)
274 api.status_delete(posted[0])
275 time.sleep(2)
272 streamingClose() 276 streamingClose()
273 277
274 t = threading.Thread(args=(), target=do_activities) 278 t = threading.Thread(args=(), target=do_activities)
@@ -282,13 +286,45 @@ def test_stream_user(api, api2):
282 if stream != None: 286 if stream != None:
283 stream.close() 287 stream.close()
284 288
285 assert len(updates) == 2 289 assert len(updates) == 1
286 assert len(notifications) == 1 290 assert len(notifications) == 1
291 assert len(deletes) == 1
287 292
288 assert updates[0].id == posted[0].id 293 assert updates[0].id == posted[0].id
289 assert updates[1].id == posted[0].id 294 assert deletes[0] == posted[0].id
290 assert notifications[0].status.id == posted[1].id 295 assert notifications[0].status.id == posted[1].id
291 296
292 t.join() 297 t.join()
293 298
294 \ No newline at end of file 299@pytest.mark.vcr(match_on=['path'])
300def test_stream_user_local(api, api2):
301 patchStreaming()
302
303 updates = []
304 notifications = []
305 listener = CallbackStreamListener(
306 local_update_handler = lambda x: updates.append(x),
307 )
308
309 posted = []
310 def do_activities():
311 time.sleep(5)
312 posted.append(api.status_post("it's cool guy"))
313 time.sleep(3)
314 streamingClose()
315
316 t = threading.Thread(args=(), target=do_activities)
317 t.start()
318
319 stream = None
320 try:
321 stream = api.stream_user(listener, run_async=True)
322 time.sleep(13)
323 finally:
324 if stream != None:
325 stream.close()
326
327 assert len(updates) == 1
328 assert updates[0].id == posted[0].id
329
330 t.join() \ No newline at end of file
Powered by cgit v1.2.3 (git 2.41.0)