mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 15:09:34 +00:00
tests: Add capture_event() helper.
For many actions, we make a single call to send_event, and it's kind of heavy now to properly assert we made one call, and we don't need to exercise all the tornado code to prove that the action was written correctly.
This commit is contained in:
@@ -109,6 +109,28 @@ def tornado_redirected_to_list(lst: List[Mapping[str, Any]]) -> Iterator[None]:
|
||||
yield
|
||||
event_queue.process_notification = real_event_queue_process_notification
|
||||
|
||||
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 simulated_empty_cache() -> Generator[
|
||||
List[Tuple[str, Union[str, List[str]], str]], None, None]:
|
||||
|
||||
Reference in New Issue
Block a user