bots: Pass through widget_content if passed in.
This commit is contained in:
parent
488dcb4219
commit
fcd39204a9
|
@ -142,12 +142,13 @@ class ExternalBotHandler(object):
|
||||||
self._rate_limit.show_error_and_exit()
|
self._rate_limit.show_error_and_exit()
|
||||||
return self._client.send_message(message)
|
return self._client.send_message(message)
|
||||||
|
|
||||||
def send_reply(self, message: Dict[str, Any], response: str) -> Dict[str, Any]:
|
def send_reply(self, message: Dict[str, Any], response: str, widget_content: Optional[str]=None) -> Dict[str, Any]:
|
||||||
if message['type'] == 'private':
|
if message['type'] == 'private':
|
||||||
return self.send_message(dict(
|
return self.send_message(dict(
|
||||||
type='private',
|
type='private',
|
||||||
to=[x['email'] for x in message['display_recipient'] if self.email != x['email']],
|
to=[x['email'] for x in message['display_recipient'] if self.email != x['email']],
|
||||||
content=response,
|
content=response,
|
||||||
|
widget_content=widget_content,
|
||||||
))
|
))
|
||||||
else:
|
else:
|
||||||
return self.send_message(dict(
|
return self.send_message(dict(
|
||||||
|
@ -155,6 +156,7 @@ class ExternalBotHandler(object):
|
||||||
to=message['display_recipient'],
|
to=message['display_recipient'],
|
||||||
subject=message['subject'],
|
subject=message['subject'],
|
||||||
content=response,
|
content=response,
|
||||||
|
widget_content=widget_content,
|
||||||
))
|
))
|
||||||
|
|
||||||
def update_message(self, message: Dict[str, Any]) -> Dict[str, Any]:
|
def update_message(self, message: Dict[str, Any]) -> Dict[str, Any]:
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
from typing import List, Dict, Any, Tuple
|
from typing import List, Dict, Any, Tuple, Optional
|
||||||
|
|
||||||
from zulip_bots.custom_exceptions import (
|
from zulip_bots.custom_exceptions import (
|
||||||
ConfigValidationError,
|
ConfigValidationError,
|
||||||
|
@ -41,9 +41,11 @@ class StubBotHandler:
|
||||||
self.transcript.append(('send_message', message))
|
self.transcript.append(('send_message', message))
|
||||||
return self.message_server.send(message)
|
return self.message_server.send(message)
|
||||||
|
|
||||||
def send_reply(self, message: Dict[str, Any], response: str) -> Dict[str, Any]:
|
def send_reply(self, message: Dict[str, Any], response: str,
|
||||||
|
widget_content: Optional[str]=None) -> Dict[str, Any]:
|
||||||
response_message = dict(
|
response_message = dict(
|
||||||
content=response
|
content=response,
|
||||||
|
widget_content=widget_content
|
||||||
)
|
)
|
||||||
self.transcript.append(('send_reply', response_message))
|
self.transcript.append(('send_reply', response_message))
|
||||||
return self.message_server.send(response_message)
|
return self.message_server.send(response_message)
|
||||||
|
|
|
@ -110,16 +110,17 @@ class LibTest(TestCase):
|
||||||
)
|
)
|
||||||
to = {'email': 'Some@User'}
|
to = {'email': 'Some@User'}
|
||||||
expected = [({'type': 'private', 'display_recipient': [to]},
|
expected = [({'type': 'private', 'display_recipient': [to]},
|
||||||
{'type': 'private', 'to': [to['email']]}),
|
{'type': 'private', 'to': [to['email']]}, None),
|
||||||
({'type': 'private', 'display_recipient': [to, profile]},
|
({'type': 'private', 'display_recipient': [to, profile]},
|
||||||
{'type': 'private', 'to': [to['email']]}),
|
{'type': 'private', 'to': [to['email']]}, 'widget_content'),
|
||||||
({'type': 'stream', 'display_recipient': 'Stream name', 'subject': 'Topic'},
|
({'type': 'stream', 'display_recipient': 'Stream name', 'subject': 'Topic'},
|
||||||
{'type': 'stream', 'to': 'Stream name', 'subject': 'Topic'})]
|
{'type': 'stream', 'to': 'Stream name', 'subject': 'Topic'}, 'test widget')]
|
||||||
response_text = "Response"
|
response_text = "Response"
|
||||||
for test in expected:
|
for test in expected:
|
||||||
client.send_message = MagicMock()
|
client.send_message = MagicMock()
|
||||||
handler.send_reply(test[0], response_text)
|
handler.send_reply(test[0], response_text, test[2])
|
||||||
client.send_message.assert_called_once_with(dict(test[1], content=response_text))
|
client.send_message.assert_called_once_with(dict(
|
||||||
|
test[1], content=response_text, widget_content=test[2]))
|
||||||
|
|
||||||
def test_content_and_full_content(self):
|
def test_content_and_full_content(self):
|
||||||
client = FakeClient()
|
client = FakeClient()
|
||||||
|
|
Loading…
Reference in a new issue