mirror of
https://github.com/zulip/zulip.git
synced 2025-11-04 14:03:30 +00:00
tests: Inline TestOutgoingWebhookMessaging.setUp().
It's more readable if you just have the two lines at the top of each function telling you who's the bot owner and how you're creating the bot.
This commit is contained in:
@@ -139,36 +139,43 @@ I'm a generic exception :(
|
|||||||
self.assertEqual(bot_owner_notification.recipient_id, self.bot_user.bot_owner.id)
|
self.assertEqual(bot_owner_notification.recipient_id, self.bot_user.bot_owner.id)
|
||||||
|
|
||||||
class TestOutgoingWebhookMessaging(ZulipTestCase):
|
class TestOutgoingWebhookMessaging(ZulipTestCase):
|
||||||
def setUp(self) -> None:
|
def create_outgoing_bot(self, bot_owner: UserProfile) -> UserProfile:
|
||||||
super().setUp()
|
return self.create_test_bot(
|
||||||
self.user_profile = self.example_user("othello")
|
'outgoing-webhook',
|
||||||
self.bot_profile = self.create_test_bot('outgoing-webhook', self.user_profile,
|
bot_owner,
|
||||||
full_name='Outgoing Webhook bot',
|
full_name='Outgoing Webhook bot',
|
||||||
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
|
bot_type=UserProfile.OUTGOING_WEBHOOK_BOT,
|
||||||
service_name='foo-service')
|
service_name='foo-service'
|
||||||
|
)
|
||||||
|
|
||||||
@mock.patch('requests.request', return_value=ResponseMock(200, {"response_string": "Hidley ho, I'm a webhook responding!"}))
|
@mock.patch('requests.request', return_value=ResponseMock(200, {"response_string": "Hidley ho, I'm a webhook responding!"}))
|
||||||
def test_pm_to_outgoing_webhook_bot(self, mock_requests_request: mock.Mock) -> None:
|
def test_pm_to_outgoing_webhook_bot(self, mock_requests_request: mock.Mock) -> None:
|
||||||
self.send_personal_message(self.user_profile, self.bot_profile,
|
bot_owner = self.example_user("othello")
|
||||||
|
bot = self.create_outgoing_bot(bot_owner)
|
||||||
|
|
||||||
|
self.send_personal_message(bot_owner, bot,
|
||||||
content="foo")
|
content="foo")
|
||||||
last_message = self.get_last_message()
|
last_message = self.get_last_message()
|
||||||
self.assertEqual(last_message.content, "Hidley ho, I'm a webhook responding!")
|
self.assertEqual(last_message.content, "Hidley ho, I'm a webhook responding!")
|
||||||
self.assertEqual(last_message.sender_id, self.bot_profile.id)
|
self.assertEqual(last_message.sender_id, bot.id)
|
||||||
display_recipient = get_display_recipient(last_message.recipient)
|
display_recipient = get_display_recipient(last_message.recipient)
|
||||||
# The next two lines error on mypy because the display_recipient is of type Union[str, List[Dict[str, Any]]].
|
# The next two lines error on mypy because the display_recipient is of type Union[str, List[Dict[str, Any]]].
|
||||||
# In this case, we know that display_recipient will be of type List[Dict[str, Any]].
|
# In this case, we know that display_recipient will be of type List[Dict[str, Any]].
|
||||||
# Otherwise this test will error, which is wanted behavior anyway.
|
# Otherwise this test will error, which is wanted behavior anyway.
|
||||||
self.assert_length(display_recipient, 1) # type: ignore
|
self.assert_length(display_recipient, 1) # type: ignore
|
||||||
self.assertEqual(display_recipient[0]['email'], self.user_profile.email) # type: ignore
|
self.assertEqual(display_recipient[0]['email'], bot_owner.email) # type: ignore
|
||||||
|
|
||||||
@mock.patch('requests.request', return_value=ResponseMock(200, {"response_string": "Hidley ho, I'm a webhook responding!"}))
|
@mock.patch('requests.request', return_value=ResponseMock(200, {"response_string": "Hidley ho, I'm a webhook responding!"}))
|
||||||
def test_stream_message_to_outgoing_webhook_bot(self, mock_requests_request: mock.Mock) -> None:
|
def test_stream_message_to_outgoing_webhook_bot(self, mock_requests_request: mock.Mock) -> None:
|
||||||
self.send_stream_message(self.user_profile, "Denmark",
|
bot_owner = self.example_user("othello")
|
||||||
content="@**{}** foo".format(self.bot_profile.full_name),
|
bot = self.create_outgoing_bot(bot_owner)
|
||||||
|
|
||||||
|
self.send_stream_message(bot_owner, "Denmark",
|
||||||
|
content="@**{}** foo".format(bot.full_name),
|
||||||
topic_name="bar")
|
topic_name="bar")
|
||||||
last_message = self.get_last_message()
|
last_message = self.get_last_message()
|
||||||
self.assertEqual(last_message.content, "Hidley ho, I'm a webhook responding!")
|
self.assertEqual(last_message.content, "Hidley ho, I'm a webhook responding!")
|
||||||
self.assertEqual(last_message.sender_id, self.bot_profile.id)
|
self.assertEqual(last_message.sender_id, bot.id)
|
||||||
self.assertEqual(last_message.topic_name(), "bar")
|
self.assertEqual(last_message.topic_name(), "bar")
|
||||||
display_recipient = get_display_recipient(last_message.recipient)
|
display_recipient = get_display_recipient(last_message.recipient)
|
||||||
self.assertEqual(display_recipient, "Denmark")
|
self.assertEqual(display_recipient, "Denmark")
|
||||||
|
|||||||
Reference in New Issue
Block a user