Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

tests: Move tornado_redirected_list to ZulipTestCase.

Abhijeet Prasad Bodas8bcdbc720e3a
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index d10155f1311..0bb46b1129b 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -15,6 +15,7 @@ from typing import (
Iterable,
Iterator,
List,
+ Mapping,
Optional,
Sequence,
Set,
@@ -90,6 +91,7 @@ from zerver.models import (
get_user_by_delivery_email,
)
from zerver.openapi.openapi import validate_against_openapi_schema, validate_request
+from zerver.tornado import django_api as django_tornado_api
from zerver.tornado.event_queue import clear_client_event_queues_for_testing
if settings.ZILENCER_ENABLED:
@@ -1255,6 +1257,18 @@ Output:
self.assertTrue(validation_func(new_member_user))
self.assertFalse(validation_func(guest_user))
+ @contextmanager
+ def tornado_redirected_to_list(self, lst: List[Mapping[str, Any]]) -> Iterator[None]:
+ real_event_queue_process_notification = django_tornado_api.process_notification
+ django_tornado_api.process_notification = lambda notice: lst.append(notice)
+ # process_notification takes a single parameter called 'notice'.
+ # lst.append takes a single argument called 'object'.
+ # Some code might call process_notification using keyword arguments,
+ # so mypy doesn't allow assigning lst.append to process_notification
+ # So explicitly change parameter name to 'notice' to work around this problem
+ yield
+ django_tornado_api.process_notification = real_event_queue_process_notification
+
class WebhookTestCase(ZulipTestCase):
"""
diff --git a/zerver/lib/test_helpers.py b/zerver/lib/test_helpers.py
index 4a577ecd5e2..dca5ae0a8b0 100644
--- a/zerver/lib/test_helpers.py
+++ b/zerver/lib/test_helpers.py
@@ -15,7 +15,6 @@ from typing import (
Iterable,
Iterator,
List,
- Mapping,
Optional,
Tuple,
TypeVar,
@@ -55,7 +54,6 @@ from zerver.models import (
get_realm,
get_stream,
)
-from zerver.tornado import django_api as django_tornado_api
from zerver.tornado.handlers import AsyncDjangoHandler, allocate_handler_id
from zerver.worker import queue_processors
from zproject.backends import ExternalAuthDataDict, ExternalAuthResult
@@ -94,19 +92,6 @@ def simulated_queue_client(client: Callable[[], object]) -> Iterator[None]:
yield
-@contextmanager
-def tornado_redirected_to_list(lst: List[Mapping[str, Any]]) -> Iterator[None]:
- real_event_queue_process_notification = django_tornado_api.process_notification
- django_tornado_api.process_notification = lambda notice: lst.append(notice)
- # process_notification takes a single parameter called 'notice'.
- # lst.append takes a single argument called 'object'.
- # Some code might call process_notification using keyword arguments,
- # so mypy doesn't allow assigning lst.append to process_notification
- # So explicitly change parameter name to 'notice' to work around this problem
- yield
- django_tornado_api.process_notification = real_event_queue_process_notification
-
-
class EventInfo:
def populate(self, call_args_list: List[Any]) -> None:
args = call_args_list[0][0]
diff --git a/zerver/tests/test_bots.py b/zerver/tests/test_bots.py
index 3e222656935..e270f3eee77 100644
--- a/zerver/tests/test_bots.py
+++ b/zerver/tests/test_bots.py
@@ -17,12 +17,7 @@ from zerver.lib.bot_config import ConfigError, get_bot_config
from zerver.lib.bot_lib import get_bot_handler
from zerver.lib.integrations import EMBEDDED_BOTS, WebhookIntegration
from zerver.lib.test_classes import UploadSerializeMixin, ZulipTestCase
-from zerver.lib.test_helpers import (
- avatar_disk_path,
- get_test_image_file,
- queries_captured,
- tornado_redirected_to_list,
-)
+from zerver.lib.test_helpers import avatar_disk_path, get_test_image_file, queries_captured
from zerver.models import (
Realm,
Service,
@@ -171,7 +166,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
self.login("hamlet")
self.assert_num_bots_equal(0)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.create_bot()
self.assert_num_bots_equal(1)
@@ -337,7 +332,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
self.login_user(user)
self.assert_num_bots_equal(0)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.create_bot()
self.assert_num_bots_equal(1)
@@ -391,7 +386,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
"principals": '["' + iago.email + '"]',
}
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.common_subscribe_to_streams(hamlet, ["Rome"], request_data)
self.assert_json_success(result)
@@ -408,7 +403,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
"principals": '["[email protected]"]',
}
events_bot: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events_bot):
+ with self.tornado_redirected_to_list(events_bot):
result = self.common_subscribe_to_streams(hamlet, ["Rome"], bot_request_data)
self.assert_json_success(result)
@@ -429,7 +424,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
self.assert_num_bots_equal(0)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.create_bot(default_sending_stream="Denmark")
self.assert_num_bots_equal(1)
self.assertEqual(result["default_sending_stream"], "Denmark")
@@ -501,7 +496,7 @@ class BotTest(ZulipTestCase, UploadSerializeMixin):
self.assert_num_bots_equal(0)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.create_bot(default_events_register_stream="Denmark")
self.assert_num_bots_equal(1)
self.assertEqual(result["default_events_register_stream"], "Denmark")
diff --git a/zerver/tests/test_message_flags.py b/zerver/tests/test_message_flags.py
index 93caa0deda6..02d17a93937 100644
--- a/zerver/tests/test_message_flags.py
+++ b/zerver/tests/test_message_flags.py
@@ -16,7 +16,7 @@ from zerver.lib.message import (
get_raw_unread_data,
)
from zerver.lib.test_classes import ZulipTestCase
-from zerver.lib.test_helpers import get_subscription, queries_captured, tornado_redirected_to_list
+from zerver.lib.test_helpers import get_subscription, queries_captured
from zerver.lib.topic_mutes import add_topic_mute
from zerver.models import (
Message,
@@ -225,7 +225,7 @@ class UnreadCountTests(ZulipTestCase):
)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_post(
"/json/mark_stream_as_read",
{
@@ -296,7 +296,7 @@ class UnreadCountTests(ZulipTestCase):
self.example_user("hamlet"), "Denmark", "hello", "Denmark2"
)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_post(
"/json/mark_topic_as_read",
{
diff --git a/zerver/tests/test_reactions.py b/zerver/tests/test_reactions.py
index 8126873c177..f31e17f1fdb 100644
--- a/zerver/tests/test_reactions.py
+++ b/zerver/tests/test_reactions.py
@@ -10,7 +10,7 @@ from zerver.lib.emoji import emoji_name_to_emoji_code
from zerver.lib.message import extract_message_dict
from zerver.lib.request import JsonableError
from zerver.lib.test_classes import ZulipTestCase
-from zerver.lib.test_helpers import tornado_redirected_to_list, zulip_reaction_info
+from zerver.lib.test_helpers import zulip_reaction_info
from zerver.models import Message, Reaction, RealmEmoji, UserMessage, get_realm
@@ -418,7 +418,7 @@ class ReactionEventTest(ZulipTestCase):
}
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
reaction_sender, f"/api/v1/messages/{pm_id}/reactions", reaction_info
)
@@ -463,7 +463,7 @@ class ReactionEventTest(ZulipTestCase):
self.assert_json_success(add)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_delete(
reaction_sender, f"/api/v1/messages/{pm_id}/reactions", reaction_info
)
@@ -502,7 +502,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 tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info
)
@@ -523,7 +523,7 @@ class ReactionEventTest(ZulipTestCase):
iago, "test_reactions_stream", "after subscription history private"
)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
iago, f"/api/v1/messages/{message_after_id}/reactions", reaction_info
)
@@ -544,7 +544,7 @@ class ReactionEventTest(ZulipTestCase):
# message_before_id should notify all subscribers:
# Iago and Hamlet.
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info
)
@@ -564,7 +564,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 tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
iago, f"/api/v1/messages/{message_before_id}/reactions", reaction_info
)
@@ -586,7 +586,7 @@ class ReactionEventTest(ZulipTestCase):
"hello to single receiver",
)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
hamlet, f"/api/v1/messages/{private_message_id}/reactions", reaction_info
)
@@ -604,7 +604,7 @@ class ReactionEventTest(ZulipTestCase):
"hello message to muliple receiver",
)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
polonius, f"/api/v1/messages/{huddle_message_id}/reactions", reaction_info
)
@@ -1035,7 +1035,7 @@ class ReactionAPIEventTest(EmojiReactionBase):
"reaction_type": "unicode_emoji",
}
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
self.api_post(reaction_sender, f"/api/v1/messages/{pm_id}/reactions", reaction_info)
self.assert_length(events, 1)
@@ -1077,7 +1077,7 @@ class ReactionAPIEventTest(EmojiReactionBase):
self.assert_json_success(add)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
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 adb72540b15..2e5586e0f15 100644
--- a/zerver/tests/test_realm.py
+++ b/zerver/tests/test_realm.py
@@ -22,7 +22,6 @@ from zerver.lib.realm_description import get_realm_rendered_description, get_rea
from zerver.lib.send_email import send_future_email
from zerver.lib.streams import create_stream_if_needed
from zerver.lib.test_classes import ZulipTestCase
-from zerver.lib.test_helpers import tornado_redirected_to_list
from zerver.models import (
Attachment,
CustomProfileField,
@@ -70,7 +69,7 @@ class RealmTest(ZulipTestCase):
realm = get_realm("zulip")
new_name = "Puliz"
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
do_set_realm_property(realm, "name", new_name, acting_user=None)
event = events[0]["event"]
self.assertEqual(
@@ -87,7 +86,7 @@ class RealmTest(ZulipTestCase):
realm = get_realm("zulip")
new_description = "zulip dev group"
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
do_set_realm_property(realm, "description", new_description, acting_user=None)
event = events[0]["event"]
self.assertEqual(
@@ -105,7 +104,7 @@ class RealmTest(ZulipTestCase):
new_description = "zulip dev group"
data = dict(description=new_description)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch("/json/realm", data)
self.assert_json_success(result)
realm = get_realm("zulip")
diff --git a/zerver/tests/test_subs.py b/zerver/tests/test_subs.py
index d909cf8922f..50cac47ec2b 100644
--- a/zerver/tests/test_subs.py
+++ b/zerver/tests/test_subs.py
@@ -67,7 +67,6 @@ from zerver.lib.test_helpers import (
most_recent_usermessage,
queries_captured,
reset_emails_in_zulip_realm,
- tornado_redirected_to_list,
)
from zerver.models import (
DefaultStream,
@@ -123,7 +122,7 @@ class TestCreateStreams(ZulipTestCase):
# Test stream creation events.
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
ensure_stream(realm, "Public stream", invite_only=False, acting_user=None)
self.assert_length(events, 1)
@@ -134,7 +133,7 @@ class TestCreateStreams(ZulipTestCase):
self.assertEqual(events[0]["event"]["streams"][0]["name"], "Public stream")
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
ensure_stream(realm, "Private stream", invite_only=True, acting_user=None)
self.assert_length(events, 1)
@@ -711,7 +710,7 @@ class StreamAdminTest(ZulipTestCase):
self.subscribe(self.example_user("cordelia"), "private_stream")
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
stream_id = get_stream("private_stream", user_profile.realm).id
result = self.client_patch(
f"/json/streams/{stream_id}",
@@ -730,7 +729,7 @@ class StreamAdminTest(ZulipTestCase):
self.assertNotIn(prospero.id, notified_user_ids)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
stream_id = get_stream("private_stream", user_profile.realm).id
result = self.client_patch(f"/json/streams/{stream_id}", {"new_name": "whatever"})
self.assert_json_success(result)
@@ -769,7 +768,7 @@ class StreamAdminTest(ZulipTestCase):
self.assert_json_success(result)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
stream_id = get_stream("stream_name1", user_profile.realm).id
result = self.client_patch(f"/json/streams/{stream_id}", {"new_name": "stream_name2"})
self.assert_json_success(result)
@@ -799,7 +798,7 @@ class StreamAdminTest(ZulipTestCase):
# Test case to handle Unicode stream name change
# *NOTE: Here encoding is needed when Unicode string is passed as an argument*
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
stream_id = stream_name2_exists.id
result = self.client_patch(f"/json/streams/{stream_id}", {"new_name": "नया नाम"})
self.assert_json_success(result)
@@ -810,7 +809,7 @@ class StreamAdminTest(ZulipTestCase):
# Test case to handle changing of Unicode stream name to newer name
# NOTE: Unicode string being part of URL is handled cleanly
# by client_patch call, encoding of URL is not needed.
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
stream_id = stream_name_uni_exists.id
result = self.client_patch(
f"/json/streams/{stream_id}",
@@ -824,7 +823,7 @@ class StreamAdminTest(ZulipTestCase):
self.assertTrue(stream_name_new_uni_exists)
# Test case to change name from one language to other.
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
stream_id = stream_name_new_uni_exists.id
result = self.client_patch(f"/json/streams/{stream_id}", {"new_name": "français"})
self.assert_json_success(result)
@@ -832,7 +831,7 @@ class StreamAdminTest(ZulipTestCase):
self.assertTrue(stream_name_fr_exists)
# Test case to change name to mixed language name.
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
stream_id = stream_name_fr_exists.id
result = self.client_patch(f"/json/streams/{stream_id}", {"new_name": "français name"})
self.assert_json_success(result)
@@ -845,7 +844,7 @@ class StreamAdminTest(ZulipTestCase):
)
self.subscribe(self.example_user("cordelia"), "stream_private_name1")
del events[:]
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
stream_id = get_stream("stream_private_name1", realm).id
result = self.client_patch(
f"/json/streams/{stream_id}",
@@ -875,7 +874,7 @@ class StreamAdminTest(ZulipTestCase):
acting_user=None,
)
del events[:]
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch(
f"/json/streams/{new_stream.id}",
{"new_name": "stream_rename"},
@@ -996,7 +995,7 @@ class StreamAdminTest(ZulipTestCase):
self.subscribe(user_profile, "stream_name1")
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
stream_id = get_stream("stream_name1", realm).id
result = self.client_patch(
f"/json/streams/{stream_id}",
@@ -1066,7 +1065,7 @@ class StreamAdminTest(ZulipTestCase):
acting_user=None,
)
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
stream_id = get_stream("stream_name1", realm).id
result = self.client_patch(
f"/json/streams/{stream_id}",
@@ -1186,7 +1185,7 @@ class StreamAdminTest(ZulipTestCase):
do_change_plan_type(realm, Realm.SELF_HOSTED, acting_user=None)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch(
f"/json/streams/{stream.id}", {"message_retention_days": orjson.dumps(2).decode()}
)
@@ -1214,7 +1213,7 @@ class StreamAdminTest(ZulipTestCase):
self.assertEqual(stream.message_retention_days, 2)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch(
f"/json/streams/{stream.id}",
{"message_retention_days": orjson.dumps("forever").decode()},
@@ -1237,7 +1236,7 @@ class StreamAdminTest(ZulipTestCase):
self.assertEqual(stream.message_retention_days, -1)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch(
f"/json/streams/{stream.id}",
{"message_retention_days": orjson.dumps("realm_default").decode()},
@@ -1387,7 +1386,7 @@ class StreamAdminTest(ZulipTestCase):
ensure_stream(realm, "DB32B77" + "!DEACTIVATED:" + active_name, acting_user=None)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_delete("/json/streams/" + str(stream_id))
self.assert_json_success(result)
@@ -2539,7 +2538,7 @@ class SubscriptionPropertiesTest(ZulipTestCase):
events: List[Mapping[str, Any]] = []
property_name = "is_muted"
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
test_user,
"/api/v1/users/me/subscriptions/properties",
@@ -2568,7 +2567,7 @@ class SubscriptionPropertiesTest(ZulipTestCase):
events = []
legacy_property_name = "in_home_view"
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
test_user,
"/api/v1/users/me/subscriptions/properties",
@@ -2597,7 +2596,7 @@ class SubscriptionPropertiesTest(ZulipTestCase):
self.assertEqual(sub.is_muted, False)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
test_user,
"/api/v1/users/me/subscriptions/properties",
@@ -3056,7 +3055,7 @@ class SubscriptionAPITest(ZulipTestCase):
add_streams = ["Verona2", "Denmark5"]
self.assertNotEqual(len(add_streams), 0) # necessary for full test coverage
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
self.helper_check_subs_before_and_after_add(
self.streams + add_streams,
{},
@@ -3087,7 +3086,7 @@ class SubscriptionAPITest(ZulipTestCase):
self.test_realm.notifications_stream_id = notifications_stream.id
self.test_realm.save()
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
self.helper_check_subs_before_and_after_add(
self.streams + add_streams,
other_params,
@@ -3506,7 +3505,7 @@ class SubscriptionAPITest(ZulipTestCase):
streams_to_sub = ["multi_user_stream"]
events: List[Mapping[str, Any]] = []
flush_per_request_caches()
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
with queries_captured() as queries:
self.common_subscribe_to_streams(
self.test_user,
@@ -3533,7 +3532,7 @@ class SubscriptionAPITest(ZulipTestCase):
# Now add ourselves
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
with queries_captured() as queries:
self.common_subscribe_to_streams(
self.test_user,
@@ -3568,7 +3567,7 @@ class SubscriptionAPITest(ZulipTestCase):
user3 = user_profile
realm3 = user_profile.realm
stream = get_stream("multi_user_stream", realm)
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
bulk_add_subscriptions(realm, [stream], [user_profile], acting_user=None)
self.assert_length(events, 2)
@@ -3604,7 +3603,7 @@ class SubscriptionAPITest(ZulipTestCase):
user_profile = self.example_user("cordelia")
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
bulk_add_subscriptions(realm, [stream], [user_profile], acting_user=None)
self.assert_length(events, 3)
@@ -3636,7 +3635,7 @@ class SubscriptionAPITest(ZulipTestCase):
# private stream creation event on stream creation.
new_stream = ensure_stream(realm, "private stream", invite_only=True, acting_user=None)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
bulk_add_subscriptions(
realm, [new_stream], [self.example_user("iago")], acting_user=None
)
@@ -3768,7 +3767,7 @@ class SubscriptionAPITest(ZulipTestCase):
new_user_ids_to_subscribe = [iago.id, cordelia.id]
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
self.common_subscribe_to_streams(
self.test_user,
streams_to_sub,
@@ -3817,7 +3816,7 @@ class SubscriptionAPITest(ZulipTestCase):
self.subscribe(user3, "private_stream")
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
with queries_captured() as query_count:
with cache_tries_captured() as cache_count:
bulk_remove_subscriptions(
@@ -3874,7 +3873,7 @@ class SubscriptionAPITest(ZulipTestCase):
stream.save()
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
with queries_captured() as queries:
self.common_subscribe_to_streams(
mit_user,
@@ -3889,7 +3888,7 @@ class SubscriptionAPITest(ZulipTestCase):
self.assert_length(queries, 4)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
bulk_remove_subscriptions(
users=[mit_user],
streams=streams,
diff --git a/zerver/tests/test_typing.py b/zerver/tests/test_typing.py
index 4c17a65c549..6bea5e70998 100644
--- a/zerver/tests/test_typing.py
+++ b/zerver/tests/test_typing.py
@@ -3,7 +3,7 @@ from typing import Any, List, Mapping
import orjson
from zerver.lib.test_classes import ZulipTestCase
-from zerver.lib.test_helpers import queries_captured, tornado_redirected_to_list
+from zerver.lib.test_helpers import queries_captured
from zerver.models import Huddle, get_huddle_hash
@@ -149,7 +149,7 @@ class TypingHappyPathTestPMs(ZulipTestCase):
events: List[Mapping[str, Any]] = []
with queries_captured() as queries:
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
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 tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
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 tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.api_post(
user,
"/api/v1/typing",
@@ -260,7 +260,7 @@ class TypingHappyPathTestPMs(ZulipTestCase):
)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
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 tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
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 tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
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 tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
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 tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
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_users.py b/zerver/tests/test_users.py
index f7b00e6f058..146f930e41b 100644
--- a/zerver/tests/test_users.py
+++ b/zerver/tests/test_users.py
@@ -42,7 +42,6 @@ from zerver.lib.test_helpers import (
queries_captured,
reset_emails_in_zulip_realm,
simulated_empty_cache,
- tornado_redirected_to_list,
)
from zerver.lib.topic_mutes import add_topic_mute
from zerver.lib.upload import upload_avatar_image
@@ -185,7 +184,7 @@ class PermissionTest(ZulipTestCase):
req = dict(role=UserProfile.ROLE_REALM_OWNER)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch(f"/json/users/{othello.id}", req)
self.assert_json_success(result)
owner_users = realm.get_human_owner_users()
@@ -196,7 +195,7 @@ class PermissionTest(ZulipTestCase):
req = dict(role=UserProfile.ROLE_MEMBER)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch(f"/json/users/{othello.id}", req)
self.assert_json_success(result)
owner_users = realm.get_human_owner_users()
@@ -209,7 +208,7 @@ class PermissionTest(ZulipTestCase):
self.login("desdemona")
req = dict(role=UserProfile.ROLE_MEMBER)
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch(f"/json/users/{iago.id}", req)
self.assert_json_success(result)
owner_users = realm.get_human_owner_users()
@@ -217,7 +216,7 @@ class PermissionTest(ZulipTestCase):
person = events[0]["event"]["person"]
self.assertEqual(person["user_id"], iago.id)
self.assertEqual(person["role"], UserProfile.ROLE_MEMBER)
- with tornado_redirected_to_list([]):
+ with self.tornado_redirected_to_list([]):
result = self.client_patch(f"/json/users/{desdemona.id}", req)
self.assert_json_error(
result, "The owner permission cannot be removed from the only organization owner."
@@ -225,7 +224,7 @@ class PermissionTest(ZulipTestCase):
do_change_user_role(iago, UserProfile.ROLE_REALM_ADMINISTRATOR, acting_user=None)
self.login("iago")
- with tornado_redirected_to_list([]):
+ with self.tornado_redirected_to_list([]):
result = self.client_patch(f"/json/users/{desdemona.id}", req)
self.assert_json_error(result, "Must be an organization owner")
@@ -250,7 +249,7 @@ class PermissionTest(ZulipTestCase):
req = dict(role=orjson.dumps(UserProfile.ROLE_REALM_ADMINISTRATOR).decode())
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch(f"/json/users/{othello.id}", req)
self.assert_json_success(result)
admin_users = realm.get_human_admin_users()
@@ -262,7 +261,7 @@ class PermissionTest(ZulipTestCase):
# Taketh away
req = dict(role=orjson.dumps(UserProfile.ROLE_MEMBER).decode())
events = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch(f"/json/users/{othello.id}", req)
self.assert_json_success(result)
admin_users = realm.get_human_admin_users()
@@ -498,7 +497,7 @@ class PermissionTest(ZulipTestCase):
req = dict(role=orjson.dumps(new_role).decode())
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
result = self.client_patch(f"/json/users/{user_profile.id}", req)
self.assert_json_success(result)
@@ -764,7 +763,7 @@ class QueryCountTest(ZulipTestCase):
with queries_captured() as queries:
with cache_tries_captured() as cache_tries:
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
fred = do_create_user(
password="password",
@@ -1166,7 +1165,7 @@ class UserProfileTest(ZulipTestCase):
UserHotspot.objects.create(user=cordelia, hotspot=hotspot)
events: List[Mapping[str, Any]] = []
- with tornado_redirected_to_list(events):
+ with self.tornado_redirected_to_list(events):
copy_user_settings(cordelia, iago)
# Check that we didn't send an realm_user update events to