From 3864bbe0859e6c010a3a796467fd48d896734644 Mon Sep 17 00:00:00 2001 From: Lorenz Diener Date: Sun, 6 May 2018 02:00:18 +0200 Subject: More streaming tests --- tests/test_streaming.py | 46 +++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 41 insertions(+), 5 deletions(-) (limited to 'tests/test_streaming.py') 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): updates = [] notifications = [] + deletes = [] listener = CallbackStreamListener( update_handler = lambda x: updates.append(x), - notification_handler = lambda x: notifications.append(x) + notification_handler = lambda x: notifications.append(x), + delete_handler = lambda x: deletes.append(x) ) posted = [] @@ -268,7 +270,9 @@ def test_stream_user(api, api2): posted.append(api.status_post("only real cars respond.")) posted.append(api2.status_post("@mastodonpy_test beep beep I'm a jeep")) posted.append(api2.status_post("on the internet, nobody knows you're a plane")) - time.sleep(3) + time.sleep(1) + api.status_delete(posted[0]) + time.sleep(2) streamingClose() t = threading.Thread(args=(), target=do_activities) @@ -282,13 +286,45 @@ def test_stream_user(api, api2): if stream != None: stream.close() - assert len(updates) == 2 + assert len(updates) == 1 assert len(notifications) == 1 + assert len(deletes) == 1 assert updates[0].id == posted[0].id - assert updates[1].id == posted[0].id + assert deletes[0] == posted[0].id assert notifications[0].status.id == posted[1].id t.join() - \ No newline at end of file +@pytest.mark.vcr(match_on=['path']) +def test_stream_user_local(api, api2): + patchStreaming() + + updates = [] + notifications = [] + listener = CallbackStreamListener( + local_update_handler = lambda x: updates.append(x), + ) + + posted = [] + def do_activities(): + time.sleep(5) + posted.append(api.status_post("it's cool guy")) + time.sleep(3) + streamingClose() + + t = threading.Thread(args=(), target=do_activities) + t.start() + + stream = None + try: + stream = api.stream_user(listener, run_async=True) + time.sleep(13) + finally: + if stream != None: + stream.close() + + assert len(updates) == 1 + assert updates[0].id == posted[0].id + + t.join() \ No newline at end of file -- cgit v1.2.3