forked from zulip/zulip
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
outgoing webhooks: Warn user that PMs are not supported in Slack-form…
…at webhook. Private messages are not supported in Slack-format webhook. Instead of raising a NotImplementedError, we warn the user that PM service is not supported by sending a message to the user. Added tests for the same. Fixes zulip#9239
- Loading branch information
1 parent
2357b1e
commit cf60b88
Showing
3 changed files
with
35 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -71,12 +71,31 @@ def setUp(self) -> None: | |
'sender_full_name': 'Sample User', | ||
} | ||
} | ||
|
||
self.private_message_event = { | ||
u'user_profile_id': 24, | ||
u'service_name': 'test-service', | ||
u'command': 'test content', | ||
u'trigger': 'private_message', | ||
u'message': { | ||
'sender_id': 3, | ||
'sender_realm_str': 'zulip', | ||
'timestamp': 1529821610, | ||
'sender_email': '[email protected]', | ||
'type': 'private', | ||
'sender_realm_id': 1, | ||
'id': 219, | ||
'subject': 'test', | ||
'content': 'test content', | ||
} | ||
} | ||
|
||
self.handler = SlackOutgoingWebhookService(base_url='http://example.domain.com', | ||
token="abcdef", | ||
user_profile=None, | ||
service_name='test-service') | ||
|
||
def test_process_event_stream_message(self, mock_get_service_profile: mock.Mock) -> None: | ||
def test_process_event_stream_message(self) -> None: | ||
rest_operation, request_data = self.handler.process_event(self.stream_message_event) | ||
|
||
self.assertEqual(rest_operation['base_url'], 'http://example.domain.com') | ||
|
@@ -93,6 +112,16 @@ def test_process_event_stream_message(self, mock_get_service_profile: mock.Mock) | |
self.assertEqual(request_data[9][1], "mention") # trigger_word | ||
self.assertEqual(request_data[10][1], 12) # user_profile_id | ||
|
||
@mock.patch('zerver.lib.outgoing_webhook.get_service_profile', return_value=mock_service) | ||
@mock.patch('zerver.lib.outgoing_webhook.fail_with_message') | ||
def test_process_event_private_message(self, mock_fail_with_message: mock.Mock, | ||
mock_get_service_profile: mock.Mock) -> None: | ||
|
||
rest_operation, request_data = self.handler.process_event(self.private_message_event) | ||
self.assertIsNone(request_data) | ||
self.assertIsNone(rest_operation) | ||
self.assertTrue(mock_fail_with_message.called) | ||
|
||
def test_process_success(self) -> None: | ||
response = mock.Mock(spec=Response) | ||
response.text = json.dumps({"response_not_required": True}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters