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.

tornado: Make process_notification hack avoid import loops.

Tim Abbott272e81988b43
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py
index da4195e23be..afbc5c51d87 100644
--- a/zerver/lib/test_classes.py
+++ b/zerver/lib/test_classes.py
@@ -1329,7 +1329,7 @@ Output:
# so mypy doesn't allow assigning lst.append to process_notification
# So explicitly change parameter name to 'notice' to work around this problem
with mock.patch(
- "zerver.tornado.django_api.process_notification", lambda notice: lst.append(notice)
+ "zerver.tornado.event_queue.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
diff --git a/zerver/tornado/django_api.py b/zerver/tornado/django_api.py
index f2b35aef8a3..ae03a2f9d5f 100644
--- a/zerver/tornado/django_api.py
+++ b/zerver/tornado/django_api.py
@@ -11,7 +11,6 @@ from requests.packages.urllib3.util.retry import Retry
from zerver.lib.queue import queue_json_publish
from zerver.models import Client, Realm, UserProfile
-from zerver.tornado.event_queue import process_notification
from zerver.tornado.sharding import get_tornado_port, get_tornado_uri, notify_tornado_queue_name
@@ -127,6 +126,17 @@ def get_user_events(
def send_notification_http(realm: Realm, data: Mapping[str, Any]) -> None:
if not settings.USING_TORNADO or settings.RUNNING_INSIDE_TORNADO:
+ # To allow the backend test suite to not require a separate
+ # Tornado process, we simply call the process_notification
+ # handler directly rather than making the notify_tornado HTTP
+ # request. It would perhaps be better to instead implement
+ # this via some sort of `responses` module configuration, but
+ # perhaps it's more readable to have the logic live here.
+ #
+ # We use an import local to this function to prevent this hack
+ # from creating import cycles.
+ from zerver.tornado.event_queue import process_notification
+
process_notification(data)
else:
tornado_uri = get_tornado_uri(realm)