2016-10-29 04:00:02 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-11-16 00:43:10 +01:00
|
|
|
|
2016-10-29 04:00:02 +02:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
|
|
# Tests for the Desk.com webhook integration.
|
|
|
|
#
|
|
|
|
# The stream name must be provided in the url-encoded test fixture data,
|
|
|
|
# and must match STREAM_NAME set here.
|
|
|
|
#
|
|
|
|
# Example:
|
|
|
|
#
|
|
|
|
# stream=deskdotcom&topic=static%20text%20notification&data=This%20is%20a%20custom%20action.
|
|
|
|
#
|
|
|
|
|
|
|
|
class DeskDotComHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'deskdotcom'
|
2018-03-13 23:43:02 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/deskdotcom?stream={stream}"
|
2016-10-29 04:00:02 +02:00
|
|
|
FIXTURE_DIR_NAME = 'deskdotcom'
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_static_text_message(self) -> None:
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2016-11-17 01:39:47 +01:00
|
|
|
expected_subject = u"static text notification"
|
2017-02-12 04:22:13 +01:00
|
|
|
expected_message = u"This is a custom action."
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-12-14 19:02:45 +01:00
|
|
|
self.api_stream_message(self.TEST_USER_EMAIL, 'static_text', expected_subject, 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:
|
2016-11-17 01:39:47 +01:00
|
|
|
expected_subject = u"case updated notification"
|
2016-10-29 04:00:02 +02:00
|
|
|
expected_message = (u"Case 2 updated. "
|
2016-12-03 00:04:17 +01:00
|
|
|
u"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
2017-02-12 04:22:13 +01:00
|
|
|
u"I have a question</a>")
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-12-14 19:02:45 +01:00
|
|
|
self.api_stream_message(self.TEST_USER_EMAIL, 'case_updated', expected_subject, 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:
|
2016-10-29 04:00:02 +02:00
|
|
|
|
|
|
|
expected_subject = u"case updated notification"
|
|
|
|
expected_message = (u"Case 2 updated. "
|
2016-12-03 00:04:17 +01:00
|
|
|
u"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
2017-02-12 04:22:13 +01:00
|
|
|
u"Il mio hovercraft è pieno di anguille.</a>")
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-12-14 19:02:45 +01:00
|
|
|
self.api_stream_message(self.TEST_USER_EMAIL, 'unicode_text_italian', expected_subject, 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:
|
2016-10-29 04:00:02 +02:00
|
|
|
|
|
|
|
expected_subject = u"case updated notification"
|
|
|
|
expected_message = (u"Case 2 updated. "
|
2016-12-03 00:04:17 +01:00
|
|
|
u"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
2017-02-12 04:22:13 +01:00
|
|
|
u"私のホバークラフトは鰻でいっぱいです</a>")
|
2016-10-29 04:00:02 +02:00
|
|
|
|
2017-12-14 19:02:45 +01:00
|
|
|
self.api_stream_message(self.TEST_USER_EMAIL, 'unicode_text_japanese', expected_subject, 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")
|