diff options
author | halcy <halcy@ARARAGI-KUN> | 2022-11-21 22:17:20 +0200 |
---|---|---|
committer | halcy <halcy@ARARAGI-KUN> | 2022-11-21 22:17:20 +0200 |
commit | 1d5b308016b8762d255290add53f84dbd6f7d439 (patch) | |
tree | affb5c96cef67360910386786dfb19b576b67a7f /tests/test_streaming.py | |
parent | 6d4ec618f2f02a20874973647f34cbca9e9936cc (diff) | |
download | mastodon.py-1d5b308016b8762d255290add53f84dbd6f7d439.tar.gz |
Add more streaming events, some tests
Diffstat (limited to 'tests/test_streaming.py')
-rw-r--r-- | tests/test_streaming.py | 28 |
1 files changed, 22 insertions, 6 deletions
diff --git a/tests/test_streaming.py b/tests/test_streaming.py index 53a71ee..721fabc 100644 --- a/tests/test_streaming.py +++ b/tests/test_streaming.py | |||
@@ -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']) |
311 | def test_stream_user(api, api2): | 311 | def 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 |