diff options
Diffstat (limited to 'tests/test_streaming.py')
-rw-r--r-- | tests/test_streaming.py | 46 |
1 files changed, 41 insertions, 5 deletions
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): | |||
257 | 257 | ||
258 | updates = [] | 258 | updates = [] |
259 | notifications = [] | 259 | notifications = [] |
260 | deletes = [] | ||
260 | listener = CallbackStreamListener( | 261 | listener = CallbackStreamListener( |
261 | update_handler = lambda x: updates.append(x), | 262 | update_handler = lambda x: updates.append(x), |
262 | notification_handler = lambda x: notifications.append(x) | 263 | notification_handler = lambda x: notifications.append(x), |
264 | delete_handler = lambda x: deletes.append(x) | ||
263 | ) | 265 | ) |
264 | 266 | ||
265 | posted = [] | 267 | posted = [] |
@@ -268,7 +270,9 @@ def test_stream_user(api, api2): | |||
268 | posted.append(api.status_post("only real cars respond.")) | 270 | posted.append(api.status_post("only real cars respond.")) |
269 | posted.append(api2.status_post("@mastodonpy_test beep beep I'm a jeep")) | 271 | 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")) | 272 | posted.append(api2.status_post("on the internet, nobody knows you're a plane")) |
271 | time.sleep(3) | 273 | time.sleep(1) |
274 | api.status_delete(posted[0]) | ||
275 | time.sleep(2) | ||
272 | streamingClose() | 276 | streamingClose() |
273 | 277 | ||
274 | t = threading.Thread(args=(), target=do_activities) | 278 | t = threading.Thread(args=(), target=do_activities) |
@@ -282,13 +286,45 @@ def test_stream_user(api, api2): | |||
282 | if stream != None: | 286 | if stream != None: |
283 | stream.close() | 287 | stream.close() |
284 | 288 | ||
285 | assert len(updates) == 2 | 289 | assert len(updates) == 1 |
286 | assert len(notifications) == 1 | 290 | assert len(notifications) == 1 |
291 | assert len(deletes) == 1 | ||
287 | 292 | ||
288 | assert updates[0].id == posted[0].id | 293 | assert updates[0].id == posted[0].id |
289 | assert updates[1].id == posted[0].id | 294 | assert deletes[0] == posted[0].id |
290 | assert notifications[0].status.id == posted[1].id | 295 | assert notifications[0].status.id == posted[1].id |
291 | 296 | ||
292 | t.join() | 297 | t.join() |
293 | 298 | ||
294 | \ No newline at end of file | 299 | @pytest.mark.vcr(match_on=['path']) |
300 | def test_stream_user_local(api, api2): | ||
301 | patchStreaming() | ||
302 | |||
303 | updates = [] | ||
304 | notifications = [] | ||
305 | listener = CallbackStreamListener( | ||
306 | local_update_handler = lambda x: updates.append(x), | ||
307 | ) | ||
308 | |||
309 | posted = [] | ||
310 | def do_activities(): | ||
311 | time.sleep(5) | ||
312 | posted.append(api.status_post("it's cool guy")) | ||
313 | time.sleep(3) | ||
314 | streamingClose() | ||
315 | |||
316 | t = threading.Thread(args=(), target=do_activities) | ||
317 | t.start() | ||
318 | |||
319 | stream = None | ||
320 | try: | ||
321 | stream = api.stream_user(listener, run_async=True) | ||
322 | time.sleep(13) | ||
323 | finally: | ||
324 | if stream != None: | ||
325 | stream.close() | ||
326 | |||
327 | assert len(updates) == 1 | ||
328 | assert updates[0].id == posted[0].id | ||
329 | |||
330 | t.join() \ No newline at end of file | ||