diff options
author | Lorenz Diener <[email protected]> | 2019-10-11 22:32:51 +0200 |
---|---|---|
committer | Lorenz Diener <[email protected]> | 2019-10-11 22:32:51 +0200 |
commit | a8e49756f4524f79a8c1269b76e97c00d44051cd (patch) | |
tree | f358e9707781ece6d2ba626c88391ce48eed0db3 /tests/test_streaming.py | |
parent | a36fbd4bc3250bec74e6b304760f000c58d9feb2 (diff) | |
download | mastodon.py-a8e49756f4524f79a8c1269b76e97c00d44051cd.tar.gz |
Add a test case for conversation streaming
Diffstat (limited to 'tests/test_streaming.py')
-rw-r--r-- | tests/test_streaming.py | 34 |
1 files changed, 31 insertions, 3 deletions
diff --git a/tests/test_streaming.py b/tests/test_streaming.py index a471c41..cddb79a 100644 --- a/tests/test_streaming.py +++ b/tests/test_streaming.py | |||
@@ -17,7 +17,7 @@ streaming_is_patched = False | |||
17 | real_connections = [] | 17 | real_connections = [] |
18 | close_connections = False | 18 | close_connections = False |
19 | 19 | ||
20 | def patchStreaming(): | 20 | def 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 == True: |
@@ -281,7 +281,7 @@ def test_multiline_payload(): | |||
281 | 281 | ||
282 | @pytest.mark.vcr(match_on=['path']) | 282 | @pytest.mark.vcr(match_on=['path']) |
283 | def test_stream_user(api, api2): | 283 | def test_stream_user(api, api2): |
284 | patchStreaming() | 284 | patch_streaming() |
285 | 285 | ||
286 | # Make sure we are in the right state to not receive updates from api2 | 286 | # Make sure we are in the right state to not receive updates from api2 |
287 | user = api2.account_verify_credentials() | 287 | user = api2.account_verify_credentials() |
@@ -331,7 +331,7 @@ def test_stream_user(api, api2): | |||
331 | 331 | ||
332 | @pytest.mark.vcr(match_on=['path']) | 332 | @pytest.mark.vcr(match_on=['path']) |
333 | def test_stream_user_local(api, api2): | 333 | def test_stream_user_local(api, api2): |
334 | patchStreaming() | 334 | patch_streaming() |
335 | 335 | ||
336 | # Make sure we are in the right state to not receive updates from api2 | 336 | # Make sure we are in the right state to not receive updates from api2 |
337 | user = api2.account_verify_credentials() | 337 | user = api2.account_verify_credentials() |
@@ -366,6 +366,34 @@ def test_stream_user_local(api, api2): | |||
366 | 366 | ||
367 | t.join() | 367 | t.join() |
368 | 368 | ||
369 | @pytest.mark.vcr(match_on=['path']) | ||
370 | def test_stream_direct(api, api2): | ||
371 | patch_streaming() | ||
372 | |||
373 | conversations = [] | ||
374 | listener = CallbackStreamListener( | ||
375 | conversation_handler = lambda x: conversations.append(x), | ||
376 | ) | ||
377 | |||
378 | def do_activities(): | ||
379 | time.sleep(5) | ||
380 | api2.status_post("@mastodonpy_test todo funny text here", visibility = "direct") | ||
381 | time.sleep(10) | ||
382 | streaming_close() | ||
383 | |||
384 | t = threading.Thread(args=(), target=do_activities) | ||
385 | t.start() | ||
386 | |||
387 | stream = None | ||
388 | try: | ||
389 | stream = api.stream_direct(listener, run_async=True) | ||
390 | time.sleep(20) | ||
391 | finally: | ||
392 | if stream != None: | ||
393 | stream.close() | ||
394 | |||
395 | assert len(conversations) == 1 | ||
396 | |||
369 | @pytest.mark.vcr() | 397 | @pytest.mark.vcr() |
370 | def test_stream_healthy(api_anonymous): | 398 | def test_stream_healthy(api_anonymous): |
371 | assert api_anonymous.stream_healthy() | 399 | assert api_anonymous.stream_healthy() |