diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py index b5df226a71..711145c11e 100644 --- a/zerver/lib/test_classes.py +++ b/zerver/lib/test_classes.py @@ -1259,7 +1259,7 @@ Output: @contextmanager def tornado_redirected_to_list( - self, lst: List[Mapping[str, Any]], expected_num_events: int = 1 + self, lst: List[Mapping[str, Any]], expected_num_events: int ) -> Iterator[None]: real_event_queue_process_notification = django_tornado_api.process_notification django_tornado_api.process_notification = lambda notice: lst.append(notice) diff --git a/zerver/tests/test_message_flags.py b/zerver/tests/test_message_flags.py index cf56e283bf..b65944c804 100644 --- a/zerver/tests/test_message_flags.py +++ b/zerver/tests/test_message_flags.py @@ -225,7 +225,7 @@ class UnreadCountTests(ZulipTestCase): ) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_post( "/json/mark_stream_as_read", { @@ -295,7 +295,7 @@ class UnreadCountTests(ZulipTestCase): self.example_user("hamlet"), "Denmark", "hello", "Denmark2" ) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_post( "/json/mark_topic_as_read", { diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.py index b35b5c71ff..5eae500a0e 100644 --- a/zerver/tests/test_message_send.py +++ b/zerver/tests/test_message_send.py @@ -1661,7 +1661,7 @@ class StreamMessagesTest(ZulipTestCase): def _send_stream_message(self, user: UserProfile, stream_name: str, content: str) -> Set[int]: events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): self.send_stream_message( user, stream_name, diff --git a/zerver/tests/test_reactions.py b/zerver/tests/test_reactions.py index b997e362a3..3869d403db 100644 --- a/zerver/tests/test_reactions.py +++ b/zerver/tests/test_reactions.py @@ -418,7 +418,7 @@ class ReactionEventTest(ZulipTestCase): } events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( reaction_sender, f"/api/v1/messages/{pm_id}/reactions", reaction_info ) @@ -462,7 +462,7 @@ class ReactionEventTest(ZulipTestCase): self.assert_json_success(add) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_delete( reaction_sender, f"/api/v1/messages/{pm_id}/reactions", reaction_info ) @@ -500,7 +500,7 @@ class ReactionEventTest(ZulipTestCase): # Hamlet and Polonius joined after the message was sent, and # so only Iago should receive the event. events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info ) @@ -520,7 +520,7 @@ class ReactionEventTest(ZulipTestCase): iago, "test_reactions_stream", "after subscription history private" ) events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( iago, f"/api/v1/messages/{message_after_id}/reactions", reaction_info ) @@ -540,7 +540,7 @@ class ReactionEventTest(ZulipTestCase): # message_before_id should notify all subscribers: # Iago and Hamlet. events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info ) @@ -559,7 +559,7 @@ class ReactionEventTest(ZulipTestCase): # For is_web_public streams, events even on old messages # should go to all subscribers, including guests like polonius. events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info ) @@ -580,7 +580,7 @@ class ReactionEventTest(ZulipTestCase): "hello to single receiver", ) events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( hamlet, f"/api/v1/messages/{private_message_id}/reactions", reaction_info ) @@ -597,7 +597,7 @@ class ReactionEventTest(ZulipTestCase): "hello message to muliple receiver", ) events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( polonius, f"/api/v1/messages/{huddle_message_id}/reactions", reaction_info ) @@ -1027,7 +1027,7 @@ class ReactionAPIEventTest(EmojiReactionBase): "reaction_type": "unicode_emoji", } events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): self.api_post(reaction_sender, f"/api/v1/messages/{pm_id}/reactions", reaction_info) event = events[0]["event"] @@ -1067,7 +1067,7 @@ class ReactionAPIEventTest(EmojiReactionBase): self.assert_json_success(add) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_delete( reaction_sender, f"/api/v1/messages/{pm_id}/reactions", diff --git a/zerver/tests/test_realm.py b/zerver/tests/test_realm.py index 2e5586e0f1..cf3bad953a 100644 --- a/zerver/tests/test_realm.py +++ b/zerver/tests/test_realm.py @@ -69,7 +69,7 @@ class RealmTest(ZulipTestCase): realm = get_realm("zulip") new_name = "Puliz" events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): do_set_realm_property(realm, "name", new_name, acting_user=None) event = events[0]["event"] self.assertEqual( @@ -86,7 +86,7 @@ class RealmTest(ZulipTestCase): realm = get_realm("zulip") new_description = "zulip dev group" events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): do_set_realm_property(realm, "description", new_description, acting_user=None) event = events[0]["event"] self.assertEqual( @@ -104,7 +104,7 @@ class RealmTest(ZulipTestCase): new_description = "zulip dev group" data = dict(description=new_description) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_patch("/json/realm", data) self.assert_json_success(result) realm = get_realm("zulip") diff --git a/zerver/tests/test_submessage.py b/zerver/tests/test_submessage.py index 040e30fdb5..cf1dfe46d7 100644 --- a/zerver/tests/test_submessage.py +++ b/zerver/tests/test_submessage.py @@ -114,7 +114,7 @@ class TestBasics(ZulipTestCase): content='{"name": "alice", "salary": 20}', ) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_post("/json/submessage", payload) self.assert_json_success(result) diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py index 608e284cbd..be0cbde68d 100644 --- a/zerver/tests/test_subs.py +++ b/zerver/tests/test_subs.py @@ -122,7 +122,7 @@ class TestCreateStreams(ZulipTestCase): # Test stream creation events. events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): ensure_stream(realm, "Public stream", invite_only=False, acting_user=None) self.assertEqual(events[0]["event"]["type"], "stream") @@ -132,7 +132,7 @@ class TestCreateStreams(ZulipTestCase): self.assertEqual(events[0]["event"]["streams"][0]["name"], "Public stream") events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): ensure_stream(realm, "Private stream", invite_only=True, acting_user=None) self.assertEqual(events[0]["event"]["type"], "stream") @@ -708,7 +708,7 @@ class StreamAdminTest(ZulipTestCase): self.subscribe(self.example_user("cordelia"), "private_stream") events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): stream_id = get_stream("private_stream", user_profile.realm).id result = self.client_patch( f"/json/streams/{stream_id}", @@ -989,7 +989,7 @@ class StreamAdminTest(ZulipTestCase): self.subscribe(user_profile, "stream_name1") events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): stream_id = get_stream("stream_name1", realm).id result = self.client_patch( f"/json/streams/{stream_id}", @@ -1179,7 +1179,7 @@ class StreamAdminTest(ZulipTestCase): do_change_plan_type(realm, Realm.SELF_HOSTED, acting_user=None) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_patch( f"/json/streams/{stream.id}", {"message_retention_days": orjson.dumps(2).decode()} ) @@ -1207,7 +1207,7 @@ class StreamAdminTest(ZulipTestCase): self.assertEqual(stream.message_retention_days, 2) events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_patch( f"/json/streams/{stream.id}", {"message_retention_days": orjson.dumps("forever").decode()}, @@ -1230,7 +1230,7 @@ class StreamAdminTest(ZulipTestCase): self.assertEqual(stream.message_retention_days, -1) events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_patch( f"/json/streams/{stream.id}", {"message_retention_days": orjson.dumps("realm_default").decode()}, @@ -1380,7 +1380,7 @@ class StreamAdminTest(ZulipTestCase): ensure_stream(realm, "DB32B77" + "!DEACTIVATED:" + active_name, acting_user=None) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_delete("/json/streams/" + str(stream_id)) self.assert_json_success(result) @@ -2532,7 +2532,7 @@ class SubscriptionPropertiesTest(ZulipTestCase): events: List[Mapping[str, Any]] = [] property_name = "is_muted" - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( test_user, "/api/v1/users/me/subscriptions/properties", @@ -2560,7 +2560,7 @@ class SubscriptionPropertiesTest(ZulipTestCase): events = [] legacy_property_name = "in_home_view" - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( test_user, "/api/v1/users/me/subscriptions/properties", @@ -2588,7 +2588,7 @@ class SubscriptionPropertiesTest(ZulipTestCase): self.assertEqual(sub.is_muted, False) events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( test_user, "/api/v1/users/me/subscriptions/properties", diff --git a/zerver/tests/test_typing.py b/zerver/tests/test_typing.py index 6bea5e7099..ce5c94dec3 100644 --- a/zerver/tests/test_typing.py +++ b/zerver/tests/test_typing.py @@ -149,7 +149,7 @@ class TypingHappyPathTestPMs(ZulipTestCase): events: List[Mapping[str, Any]] = [] with queries_captured() as queries: - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post(sender, "/api/v1/typing", params) self.assert_json_success(result) @@ -186,7 +186,7 @@ class TypingHappyPathTestPMs(ZulipTestCase): ) with queries_captured() as queries: - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post(sender, "/api/v1/typing", params) self.assert_json_success(result) self.assert_length(events, 1) @@ -219,7 +219,7 @@ class TypingHappyPathTestPMs(ZulipTestCase): expected_recipient_emails = {email} expected_recipient_ids = {user.id} events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post( user, "/api/v1/typing", @@ -260,7 +260,7 @@ class TypingHappyPathTestPMs(ZulipTestCase): ) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post(sender, "/api/v1/typing", params) self.assert_json_success(result) @@ -289,7 +289,7 @@ class TypingHappyPathTestPMs(ZulipTestCase): expected_recipient_ids = {user.id} events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): params = dict( to=orjson.dumps([user.id]).decode(), op="stop", @@ -323,7 +323,7 @@ class TypingHappyPathTestPMs(ZulipTestCase): expected_recipient_ids = {user.id for user in expected_recipients} events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): params = dict( to=orjson.dumps([recipient.id]).decode(), op="stop", @@ -367,7 +367,7 @@ class TypingHappyPathTestStreams(ZulipTestCase): events: List[Mapping[str, Any]] = [] with queries_captured() as queries: - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post(sender, "/api/v1/typing", params) self.assert_json_success(result) self.assert_length(events, 1) @@ -403,7 +403,7 @@ class TypingHappyPathTestStreams(ZulipTestCase): events: List[Mapping[str, Any]] = [] with queries_captured() as queries: - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.api_post(sender, "/api/v1/typing", params) self.assert_json_success(result) self.assert_length(events, 1) diff --git a/zerver/tests/test_user_status.py b/zerver/tests/test_user_status.py index acaeebc215..f4bd2691ff 100644 --- a/zerver/tests/test_user_status.py +++ b/zerver/tests/test_user_status.py @@ -142,7 +142,7 @@ class UserStatusTest(ZulipTestCase): self, payload: Dict[str, Any], expected_event: Dict[str, Any] ) -> None: events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_post("/json/users/me/status", payload) self.assert_json_success(result) self.assertEqual(events[0]["event"], expected_event) diff --git a/zerver/tests/test_users.py b/zerver/tests/test_users.py index 3330c01614..a814cb8968 100644 --- a/zerver/tests/test_users.py +++ b/zerver/tests/test_users.py @@ -184,7 +184,7 @@ class PermissionTest(ZulipTestCase): req = dict(role=UserProfile.ROLE_REALM_OWNER) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_patch(f"/json/users/{othello.id}", req) self.assert_json_success(result) owner_users = realm.get_human_owner_users() @@ -195,7 +195,7 @@ class PermissionTest(ZulipTestCase): req = dict(role=UserProfile.ROLE_MEMBER) events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_patch(f"/json/users/{othello.id}", req) self.assert_json_success(result) owner_users = realm.get_human_owner_users() @@ -208,7 +208,7 @@ class PermissionTest(ZulipTestCase): self.login("desdemona") req = dict(role=UserProfile.ROLE_MEMBER) events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_patch(f"/json/users/{iago.id}", req) self.assert_json_success(result) owner_users = realm.get_human_owner_users() @@ -249,7 +249,7 @@ class PermissionTest(ZulipTestCase): req = dict(role=orjson.dumps(UserProfile.ROLE_REALM_ADMINISTRATOR).decode()) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_patch(f"/json/users/{othello.id}", req) self.assert_json_success(result) admin_users = realm.get_human_admin_users() @@ -261,7 +261,7 @@ class PermissionTest(ZulipTestCase): # Taketh away req = dict(role=orjson.dumps(UserProfile.ROLE_MEMBER).decode()) events = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_patch(f"/json/users/{othello.id}", req) self.assert_json_success(result) admin_users = realm.get_human_admin_users() @@ -497,7 +497,7 @@ class PermissionTest(ZulipTestCase): req = dict(role=orjson.dumps(new_role).decode()) events: List[Mapping[str, Any]] = [] - with self.tornado_redirected_to_list(events): + with self.tornado_redirected_to_list(events, expected_num_events=1): result = self.client_patch(f"/json/users/{user_profile.id}", req) self.assert_json_success(result)