mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
test_classes: Use mock.patch in tornado_redirected_to_list.
Signed-off-by: Anders Kaseorg <anders@zulip.com>
This commit is contained in:
committed by
Tim Abbott
parent
1ae56e466b
commit
1a985911ef
@@ -98,7 +98,6 @@ from zerver.models import (
|
|||||||
get_user_by_delivery_email,
|
get_user_by_delivery_email,
|
||||||
)
|
)
|
||||||
from zerver.openapi.openapi import validate_against_openapi_schema, validate_request
|
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
|
from zerver.tornado.event_queue import clear_client_event_queues_for_testing
|
||||||
|
|
||||||
if settings.ZILENCER_ENABLED:
|
if settings.ZILENCER_ENABLED:
|
||||||
@@ -1314,24 +1313,22 @@ Output:
|
|||||||
self, lst: List[Mapping[str, Any]], expected_num_events: int
|
self, lst: List[Mapping[str, Any]], expected_num_events: int
|
||||||
) -> Iterator[None]:
|
) -> Iterator[None]:
|
||||||
lst.clear()
|
lst.clear()
|
||||||
real_event_queue_process_notification = django_tornado_api.process_notification
|
|
||||||
|
|
||||||
# process_notification takes a single parameter called 'notice'.
|
# process_notification takes a single parameter called 'notice'.
|
||||||
# lst.append takes a single argument called 'object'.
|
# lst.append takes a single argument called 'object'.
|
||||||
# Some code might call process_notification using keyword arguments,
|
# Some code might call process_notification using keyword arguments,
|
||||||
# so mypy doesn't allow assigning lst.append to process_notification
|
# so mypy doesn't allow assigning lst.append to process_notification
|
||||||
# So explicitly change parameter name to 'notice' to work around this problem
|
# So explicitly change parameter name to 'notice' to work around this problem
|
||||||
django_tornado_api.process_notification = lambda notice: lst.append(notice)
|
with mock.patch(
|
||||||
|
"zerver.tornado.django_api.process_notification", lambda notice: lst.append(notice)
|
||||||
# Some `send_event` calls need to be executed only after the current transaction
|
):
|
||||||
# commits (using `on_commit` hooks). Because the transaction in Django tests never
|
# Some `send_event` calls need to be executed only after the current transaction
|
||||||
# commits (rather, gets rolled back after the test completes), such events would
|
# commits (using `on_commit` hooks). Because the transaction in Django tests never
|
||||||
# never be sent in tests, and we would be unable to verify them. Hence, we use
|
# commits (rather, gets rolled back after the test completes), such events would
|
||||||
# this helper to make sure the `send_event` calls actually run.
|
# never be sent in tests, and we would be unable to verify them. Hence, we use
|
||||||
with self.captureOnCommitCallbacks(execute=True):
|
# this helper to make sure the `send_event` calls actually run.
|
||||||
yield
|
with self.captureOnCommitCallbacks(execute=True):
|
||||||
|
yield
|
||||||
django_tornado_api.process_notification = real_event_queue_process_notification
|
|
||||||
|
|
||||||
self.assert_length(lst, expected_num_events)
|
self.assert_length(lst, expected_num_events)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user