mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 22:13:26 +00:00
Deliver messages inside Tornado when running tests
This saves us from having to run queue processors while testing. (imported from commit 927bfa497a47b34603761a148c57d82b2f34f813)
This commit is contained in:
@@ -11,8 +11,10 @@ import ujson
|
|||||||
import logging
|
import logging
|
||||||
import time
|
import time
|
||||||
|
|
||||||
from zerver.models import UserProfile
|
from zerver.models import UserProfile, get_user_profile_by_id, get_client
|
||||||
from zerver.lib.queue import queue_json_publish
|
from zerver.lib.queue import queue_json_publish
|
||||||
|
from zerver.lib.actions import check_send_message, extract_recipients
|
||||||
|
from zerver.decorator import JsonableError
|
||||||
|
|
||||||
djsession_engine = import_module(settings.SESSION_ENGINE)
|
djsession_engine = import_module(settings.SESSION_ENGINE)
|
||||||
def get_user_profile(session_id):
|
def get_user_profile(session_id):
|
||||||
@@ -127,7 +129,7 @@ class SocketConnection(sockjs.tornado.SockJSConnection):
|
|||||||
server_meta=dict(connection_id=self.connection_id,
|
server_meta=dict(connection_id=self.connection_id,
|
||||||
return_queue="tornado_return",
|
return_queue="tornado_return",
|
||||||
start_time=start_time)),
|
start_time=start_time)),
|
||||||
lambda e: None)
|
fake_message_sender)
|
||||||
|
|
||||||
def on_close(self):
|
def on_close(self):
|
||||||
deregister_connection(self)
|
deregister_connection(self)
|
||||||
@@ -138,6 +140,23 @@ class SocketConnection(sockjs.tornado.SockJSConnection):
|
|||||||
fake_log_line(self.session.conn_info, 0, 200,
|
fake_log_line(self.session.conn_info, 0, 200,
|
||||||
'Connection closed', 'unknown')
|
'Connection closed', 'unknown')
|
||||||
|
|
||||||
|
def fake_message_sender(event):
|
||||||
|
req = event['request']
|
||||||
|
try:
|
||||||
|
sender = get_user_profile_by_id(req['sender_id'])
|
||||||
|
client = get_client(req['client_name'])
|
||||||
|
|
||||||
|
msg_id = check_send_message(sender, client, req['type'],
|
||||||
|
extract_recipients(req['to']),
|
||||||
|
req['subject'], req['content'])
|
||||||
|
resp = {"result": "success", "msg": "", "id": msg_id}
|
||||||
|
except JsonableError as e:
|
||||||
|
resp = {"result": "error", "msg": str(e)}
|
||||||
|
|
||||||
|
result = {'response': resp, 'client_meta': event['client_meta'],
|
||||||
|
'server_meta': event['server_meta']}
|
||||||
|
respond_send_message(None, None, None, result)
|
||||||
|
|
||||||
def respond_send_message(chan, method, props, data):
|
def respond_send_message(chan, method, props, data):
|
||||||
connection = get_connection(data['server_meta']['connection_id'])
|
connection = get_connection(data['server_meta']['connection_id'])
|
||||||
if connection is not None:
|
if connection is not None:
|
||||||
|
|||||||
@@ -456,7 +456,7 @@ def process_notification(data):
|
|||||||
# different types and for compatibility with non-HTTP transports.
|
# different types and for compatibility with non-HTTP transports.
|
||||||
|
|
||||||
def send_notification_http(data):
|
def send_notification_http(data):
|
||||||
if settings.TORNADO_SERVER:
|
if settings.TORNADO_SERVER and not settings.RUNNING_INSIDE_TORNADO:
|
||||||
requests.post(settings.TORNADO_SERVER + '/notify_tornado', data=dict(
|
requests.post(settings.TORNADO_SERVER + '/notify_tornado', data=dict(
|
||||||
data = ujson.dumps(data),
|
data = ujson.dumps(data),
|
||||||
secret = settings.SHARED_SECRET))
|
secret = settings.SHARED_SECRET))
|
||||||
|
|||||||
Reference in New Issue
Block a user