2016-10-29 04:00:02 +02:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
|
|
# Tests for the Desk.com webhook integration.
|
|
|
|
#
|
2020-10-23 02:43:28 +02:00
|
|
|
# The stream name must be provided in the URL-encoded test fixture data,
|
2016-10-29 04:00:02 +02:00
|
|
|
# and must match STREAM_NAME set here.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# stream=deskdotcom&topic=static%20text%20notification&data=This%20is%20a%20custom%20action.
|
|
|
|
#
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2016-10-29 04:00:02 +02:00
|
|
|
class DeskDotComHookTests(WebhookTestCase):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "deskdotcom"
|
2018-03-13 23:43:02 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/deskdotcom?stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "deskdotcom"
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_static_text_message(self) -> None:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "static text notification"
|
|
|
|
expected_message = "This is a custom action."
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
self.api_stream_message(
|
|
|
|
self.test_user,
|
2021-02-12 08:20:45 +01:00
|
|
|
"static_text",
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_case_updated_message(self) -> None:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "case updated notification"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Case 2 updated. "
|
|
|
|
"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
|
|
|
"I have a question</a>"
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
self.api_stream_message(
|
|
|
|
self.test_user,
|
2021-02-12 08:20:45 +01:00
|
|
|
"case_updated",
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_unicode_text_italian(self) -> None:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "case updated notification"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Case 2 updated. "
|
|
|
|
"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
|
|
|
"Il mio hovercraft è pieno di anguille.</a>"
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
self.api_stream_message(
|
|
|
|
self.test_user,
|
2021-02-12 08:20:45 +01:00
|
|
|
"unicode_text_italian",
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_unicode_text_japanese(self) -> None:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "case updated notification"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Case 2 updated. "
|
|
|
|
"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
|
|
|
"私のホバークラフトは鰻でいっぱいです</a>"
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
self.api_stream_message(
|
|
|
|
self.test_user,
|
2021-02-12 08:20:45 +01:00
|
|
|
"unicode_text_japanese",
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2018-05-10 19:34:01 +02:00
|
|
|
def get_body(self, fixture_name: str) -> str:
|
2018-04-20 03:57:21 +02:00
|
|
|
return self.webhook_fixture_data("deskdotcom", fixture_name, file_type="txt")
|