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: Use tornado_redirected_to_list instead of mocking send_event.

Abhijeet Prasad Bodasc19b7b4db3c3
diff --git a/zerver/tests/test_event_system.py b/zerver/tests/test_event_system.py
index d906158e877..28b6c69615b 100644
--- a/zerver/tests/test_event_system.py
+++ b/zerver/tests/test_event_system.py
@@ -1,5 +1,5 @@
import time
-from typing import Any, Callable, Dict, List, Optional
+from typing import Any, Callable, Dict, List, Mapping, Optional
from unittest import mock
import orjson
@@ -1123,18 +1123,19 @@ class TestGetRawUserDataSystemBotRealm(ZulipTestCase):
class TestUserPresenceUpdatesDisabled(ZulipTestCase):
def test_presence_events_diabled_on_larger_realm(self) -> None:
# First check that normally the mocked function gets called.
- with mock.patch("zerver.lib.actions.send_event") as mock_send_event:
+ events: List[Mapping[str, Any]] = []
+ with self.tornado_redirected_to_list(events, expected_num_events=1):
do_update_user_presence(
self.example_user("cordelia"),
get_client("website"),
timezone_now(),
UserPresence.ACTIVE,
)
- mock_send_event.assert_called_once()
# Now check that if the realm has more than the USER_LIMIT_FOR_SENDING_PRESENCE_UPDATE_EVENTS
# amount of active users, send_event doesn't get called.
- with mock.patch("zerver.lib.actions.send_event") as mock_send_event:
+ events = []
+ with self.tornado_redirected_to_list(events, expected_num_events=0):
with self.settings(USER_LIMIT_FOR_SENDING_PRESENCE_UPDATE_EVENTS=1):
do_update_user_presence(
self.example_user("hamlet"),
@@ -1142,4 +1143,3 @@ class TestUserPresenceUpdatesDisabled(ZulipTestCase):
timezone_now(),
UserPresence.ACTIVE,
)
- mock_send_event.assert_not_called()
diff --git a/zerver/tests/test_message_send.py b/zerver/tests/test_message_send.py
index e767f89b5d9..b35b5c71ff0 100644
--- a/zerver/tests/test_message_send.py
+++ b/zerver/tests/test_message_send.py
@@ -1,5 +1,5 @@
import datetime
-from typing import Any, Optional, Set
+from typing import Any, List, Mapping, Optional, Set
from unittest import mock
import orjson
@@ -1660,14 +1660,14 @@ class StreamMessagesTest(ZulipTestCase):
)
def _send_stream_message(self, user: UserProfile, stream_name: str, content: str) -> Set[int]:
- with mock.patch("zerver.lib.actions.send_event") as m:
+ events: List[Mapping[str, Any]] = []
+ with self.tornado_redirected_to_list(events):
self.send_stream_message(
user,
stream_name,
content=content,
)
- self.assertEqual(m.call_count, 1)
- users = m.call_args[0][2]
+ users = events[0]["users"]
user_ids = {u["id"] for u in users}
return user_ids
diff --git a/zerver/tests/test_submessage.py b/zerver/tests/test_submessage.py
index edd4bfe96b4..040e30fdb5e 100644
--- a/zerver/tests/test_submessage.py
+++ b/zerver/tests/test_submessage.py
@@ -1,5 +1,4 @@
-from typing import Any, Dict, List
-from unittest import mock
+from typing import Any, Dict, List, Mapping
from zerver.lib.message import MessageDict
from zerver.lib.test_classes import ZulipTestCase
@@ -114,7 +113,8 @@ class TestBasics(ZulipTestCase):
msg_type="whatever",
content='{"name": "alice", "salary": 20}',
)
- with mock.patch("zerver.lib.actions.send_event") as m:
+ events: List[Mapping[str, Any]] = []
+ with self.tornado_redirected_to_list(events):
result = self.client_post("/json/submessage", payload)
self.assert_json_success(result)
@@ -129,10 +129,9 @@ class TestBasics(ZulipTestCase):
type="submessage",
)
- self.assertEqual(m.call_count, 1)
- data = m.call_args[0][1]
+ data = events[0]["event"]
self.assertEqual(data, expected_data)
- users = m.call_args[0][2]
+ users = events[0]["users"]
self.assertIn(cordelia.id, users)
self.assertIn(hamlet.id, users)