aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'tests/test_streaming.py')
-rw-r--r--tests/test_streaming.py36
1 files changed, 26 insertions, 10 deletions
diff --git a/tests/test_streaming.py b/tests/test_streaming.py
index fb60fe1..721fabc 100644
--- a/tests/test_streaming.py
+++ b/tests/test_streaming.py
@@ -20,7 +20,7 @@ close_connections = False
20def patch_streaming(): 20def patch_streaming():
21 global streaming_is_patched 21 global streaming_is_patched
22 global close_connections 22 global close_connections
23 if streaming_is_patched == True: 23 if streaming_is_patched is True:
24 return 24 return
25 streaming_is_patched = True 25 streaming_is_patched = True
26 26
@@ -35,7 +35,7 @@ def patch_streaming():
35 response = real_connection_real_get_response(*args, **kwargs) 35 response = real_connection_real_get_response(*args, **kwargs)
36 real_body = b"" 36 real_body = b""
37 try: 37 try:
38 while close_connections == False: 38 while close_connections is False:
39 if len(select.select([response], [], [], 0.01)[0]) > 0: 39 if len(select.select([response], [], [], 0.01)[0]) > 0:
40 chunk = response.read(1) 40 chunk = response.read(1)
41 real_body += chunk 41 real_body += chunk
@@ -165,7 +165,7 @@ def test_unknown_event():
165 'data: {}', 165 'data: {}',
166 '', 166 '',
167 ]) 167 ])
168 assert listener.bla_called == True 168 assert listener.bla_called is True
169 assert listener.updates == [] 169 assert listener.updates == []
170 assert listener.notifications == [] 170 assert listener.notifications == []
171 assert listener.deletes == [] 171 assert listener.deletes == []
@@ -195,7 +195,7 @@ def test_dotted_unknown_event():
195 'data: {}', 195 'data: {}',
196 '', 196 '',
197 ]) 197 ])
198 assert listener.do_something_called == True 198 assert listener.do_something_called is True
199 assert listener.updates == [] 199 assert listener.updates == []
200 assert listener.notifications == [] 200 assert listener.notifications == []
201 assert listener.deletes == [] 201 assert listener.deletes == []
@@ -308,21 +308,31 @@ def test_multiline_payload():
308 assert listener.updates == [{"foo": "bar"}] 308 assert listener.updates == [{"foo": "bar"}]
309 309
310@pytest.mark.vcr(match_on=['path']) 310@pytest.mark.vcr(match_on=['path'])
311def test_stream_user(api, api2): 311def test_stream_user_direct(api, api2, api3):
312 patch_streaming() 312 patch_streaming()
313 313
314 # Make sure we are in the right state to not receive updates from api2 314 # Make sure we are in the right state to not receive updates from api2
315 user = api2.account_verify_credentials() 315 user = api2.account_verify_credentials()
316 api.account_unfollow(user) 316 api.account_unfollow(user)
317 time.sleep(2) 317 time.sleep(2)
318 318
319 updates = [] 319 updates = []
320 local_updates = []
320 notifications = [] 321 notifications = []
321 deletes = [] 322 deletes = []
323 conversations = []
322 listener = CallbackStreamListener( 324 listener = CallbackStreamListener(
323 update_handler = lambda x: updates.append(x), 325 update_handler = lambda x: updates.append(x),
326 local_update_handler = lambda x: local_updates.append(x),
324 notification_handler = lambda x: notifications.append(x), 327 notification_handler = lambda x: notifications.append(x),
325 delete_handler = lambda x: deletes.append(x) 328 delete_handler = lambda x: deletes.append(x),
329 conversation_handler = lambda x: conversations.append(x),
330 status_update_handler = lambda x: 0, # TODO
331 filters_changed_handler = lambda x: 0,
332 announcement_handler = lambda x: 0,
333 announcement_reaction_handler = lambda x: 0,
334 announcement_delete_handler = lambda x: 0,
335 encryted_message_handler = lambda x: 0,
326 ) 336 )
327 337
328 posted = [] 338 posted = []
@@ -331,6 +341,8 @@ def test_stream_user(api, api2):
331 posted.append(api.status_post("only real cars respond.")) 341 posted.append(api.status_post("only real cars respond."))
332 posted.append(api2.status_post("@mastodonpy_test beep beep I'm a jeep")) 342 posted.append(api2.status_post("@mastodonpy_test beep beep I'm a jeep"))
333 posted.append(api2.status_post("on the internet, nobody knows you're a plane")) 343 posted.append(api2.status_post("on the internet, nobody knows you're a plane"))
344 posted.append(api.status_post("@mastodonpy_test_2 pssssst", visibility="direct"))
345 posted.append(api3.status_post("@mastodonpy_test pssssst!", visibility="direct", in_reply_to_id=posted[-1]))
334 time.sleep(1) 346 time.sleep(1)
335 api.status_delete(posted[0]) 347 api.status_delete(posted[0])
336 time.sleep(10) 348 time.sleep(10)
@@ -340,13 +352,17 @@ def test_stream_user(api, api2):
340 t.start() 352 t.start()
341 353
342 stream = api.stream_user(listener, run_async=True) 354 stream = api.stream_user(listener, run_async=True)
355 stream2 = api.stream_direct(listener, run_async=True)
343 time.sleep(20) 356 time.sleep(20)
344 stream.close() 357 stream.close()
358 stream2.close()
345 359
346 assert len(updates) == 1 360 assert len(updates) == 2
347 assert len(notifications) == 1 361 assert len(local_updates) == 2
362 assert len(notifications) == 2
348 assert len(deletes) == 1 363 assert len(deletes) == 1
349 364 assert len(conversations) == 2
365
350 assert updates[0].id == posted[0].id 366 assert updates[0].id == posted[0].id
351 assert deletes[0] == posted[0].id 367 assert deletes[0] == posted[0].id
352 assert notifications[0].status.id == posted[1].id 368 assert notifications[0].status.id == posted[1].id
Powered by cgit v1.2.3 (git 2.41.0)