aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_streaming.py')
-rw-r--r--tests/test_streaming.py55
1 files changed, 50 insertions, 5 deletions
diff --git a/tests/test_streaming.py b/tests/test_streaming.py
index 8c2160a..883b773 100644
--- a/tests/test_streaming.py
+++ b/tests/test_streaming.py
@@ -154,6 +154,15 @@ def test_unknown_event():
154 assert listener.deletes == [] 154 assert listener.deletes == []
155 assert listener.heartbeats == 0 155 assert listener.heartbeats == 0
156 156
157def test_invalid_event():
158 """But not too tolerant"""
159 listener = Listener()
160 with pytest.raises(MastodonMalformedEventError):
161 listener.handle_stream_([
162 'event: whatup',
163 'data: {}',
164 '',
165 ])
157 166
158def test_missing_event_name(): 167def test_missing_event_name():
159 listener = Listener() 168 listener = Listener()
@@ -257,9 +266,11 @@ def test_stream_user(api, api2):
257 266
258 updates = [] 267 updates = []
259 notifications = [] 268 notifications = []
269 deletes = []
260 listener = CallbackStreamListener( 270 listener = CallbackStreamListener(
261 update_handler = lambda x: updates.append(x), 271 update_handler = lambda x: updates.append(x),
262 notification_handler = lambda x: notifications.append(x) 272 notification_handler = lambda x: notifications.append(x),
273 delete_handler = lambda x: deletes.append(x)
263 ) 274 )
264 275
265 posted = [] 276 posted = []
@@ -268,7 +279,9 @@ def test_stream_user(api, api2):
268 posted.append(api.status_post("only real cars respond.")) 279 posted.append(api.status_post("only real cars respond."))
269 posted.append(api2.status_post("@mastodonpy_test beep beep I'm a jeep")) 280 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")) 281 posted.append(api2.status_post("on the internet, nobody knows you're a plane"))
271 time.sleep(3) 282 time.sleep(1)
283 api.status_delete(posted[0])
284 time.sleep(2)
272 streamingClose() 285 streamingClose()
273 286
274 t = threading.Thread(args=(), target=do_activities) 287 t = threading.Thread(args=(), target=do_activities)
@@ -282,13 +295,45 @@ def test_stream_user(api, api2):
282 if stream != None: 295 if stream != None:
283 stream.close() 296 stream.close()
284 297
285 assert len(updates) == 2 298 assert len(updates) == 1
286 assert len(notifications) == 1 299 assert len(notifications) == 1
300 assert len(deletes) == 1
287 301
288 assert updates[0].id == posted[0].id 302 assert updates[0].id == posted[0].id
289 assert updates[1].id == posted[0].id 303 assert deletes[0] == posted[0].id
290 assert notifications[0].status.id == posted[1].id 304 assert notifications[0].status.id == posted[1].id
291 305
292 t.join() 306 t.join()
293 307
294 \ No newline at end of file 308@pytest.mark.vcr(match_on=['path'])
309def test_stream_user_local(api, api2):
310 patchStreaming()
311
312 updates = []
313 notifications = []
314 listener = CallbackStreamListener(
315 local_update_handler = lambda x: updates.append(x),
316 )
317
318 posted = []
319 def do_activities():
320 time.sleep(5)
321 posted.append(api.status_post("it's cool guy"))
322 time.sleep(3)
323 streamingClose()
324
325 t = threading.Thread(args=(), target=do_activities)
326 t.start()
327
328 stream = None
329 try:
330 stream = api.stream_user(listener, run_async=True)
331 time.sleep(13)
332 finally:
333 if stream != None:
334 stream.close()
335
336 assert len(updates) == 1
337 assert updates[0].id == posted[0].id
338
339 t.join() \ No newline at end of file
Powered by cgit v1.2.3 (git 2.41.0)