mirror of https://github.com/zulip/zulip.git
test_helpers: Remove capture_event helper.
We now consistently use the `tornado_redirected_to_list` helper, which asserts the number of events sent too.
This commit is contained in:
parent
d2bc93f6dd
commit
090f2d6664
|
@ -92,30 +92,6 @@ def simulated_queue_client(client: Callable[[], object]) -> Iterator[None]:
|
|||
yield
|
||||
|
||||
|
||||
class EventInfo:
|
||||
def populate(self, call_args_list: List[Any]) -> None:
|
||||
args = call_args_list[0][0]
|
||||
self.realm_id = args[0]
|
||||
self.payload = args[1]
|
||||
self.user_ids = args[2]
|
||||
|
||||
|
||||
@contextmanager
|
||||
def capture_event(event_info: EventInfo) -> Iterator[None]:
|
||||
# Use this for simple endpoints that throw a single event
|
||||
# in zerver.lib.actions.
|
||||
with mock.patch("zerver.lib.actions.send_event") as m:
|
||||
yield
|
||||
|
||||
if len(m.call_args_list) == 0:
|
||||
raise AssertionError("No event was sent inside actions.py")
|
||||
|
||||
if len(m.call_args_list) > 1:
|
||||
raise AssertionError("Too many events sent by action")
|
||||
|
||||
event_info.populate(m.call_args_list)
|
||||
|
||||
|
||||
@contextmanager
|
||||
def cache_tries_captured() -> Iterator[List[Tuple[str, Union[str, List[str]], Optional[str]]]]:
|
||||
cache_queries: List[Tuple[str, Union[str, List[str]], Optional[str]]] = []
|
||||
|
|
|
@ -1,9 +1,8 @@
|
|||
from typing import Any, Dict, Set
|
||||
from typing import Any, Dict, List, Mapping, Set
|
||||
|
||||
import orjson
|
||||
|
||||
from zerver.lib.test_classes import ZulipTestCase
|
||||
from zerver.lib.test_helpers import EventInfo, capture_event
|
||||
from zerver.lib.user_status import get_user_info_dict, update_user_status
|
||||
from zerver.models import UserProfile, UserStatus, get_client
|
||||
|
||||
|
@ -142,11 +141,11 @@ class UserStatusTest(ZulipTestCase):
|
|||
def update_status_and_assert_event(
|
||||
self, payload: Dict[str, Any], expected_event: Dict[str, Any]
|
||||
) -> None:
|
||||
event_info = EventInfo()
|
||||
with capture_event(event_info):
|
||||
events: List[Mapping[str, Any]] = []
|
||||
with self.tornado_redirected_to_list(events):
|
||||
result = self.client_post("/json/users/me/status", payload)
|
||||
self.assert_json_success(result)
|
||||
self.assertEqual(event_info.payload, expected_event)
|
||||
self.assertEqual(events[0]["event"], expected_event)
|
||||
|
||||
def test_endpoints(self) -> None:
|
||||
hamlet = self.example_user("hamlet")
|
||||
|
|
Loading…
Reference in New Issue