2020-08-20 17:03:43 +02:00
|
|
|
from typing import Dict
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2016-11-10 19:30:09 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2016-09-20 22:51:11 +02:00
|
|
|
class ZenDeskHookTests(WebhookTestCase):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "zendesk"
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/zendesk?stream={stream}"
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2020-08-20 17:03:43 +02:00
|
|
|
def get_payload(self, fixture_name: str) -> Dict[str, str]:
|
2016-09-20 22:51:11 +02:00
|
|
|
return {
|
2021-02-12 08:20:45 +01:00
|
|
|
"ticket_title": self.TICKET_TITLE,
|
|
|
|
"ticket_id": str(self.TICKET_ID),
|
|
|
|
"message": self.MESSAGE,
|
|
|
|
"stream": self.STREAM_NAME,
|
2016-09-20 22:51:11 +02:00
|
|
|
}
|
|
|
|
|
2020-08-24 18:22:16 +02:00
|
|
|
def do_test(self, expected_topic: str, expected_message: str) -> None:
|
|
|
|
self.api_stream_message(
|
|
|
|
self.test_user,
|
|
|
|
"",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type=None,
|
|
|
|
)
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2020-08-24 18:22:16 +02:00
|
|
|
def test_short_topic(self) -> None:
|
2016-09-20 22:51:11 +02:00
|
|
|
self.TICKET_ID = 4
|
|
|
|
self.TICKET_TITLE = "Test ticket"
|
2020-08-24 18:22:16 +02:00
|
|
|
self.MESSAGE = "some message"
|
|
|
|
self.do_test(
|
2021-02-12 08:20:45 +01:00
|
|
|
expected_topic="#4: Test ticket",
|
2020-08-24 18:22:16 +02:00
|
|
|
expected_message="some message",
|
|
|
|
)
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_long_subject(self) -> None:
|
2016-09-20 22:51:11 +02:00
|
|
|
self.TICKET_ID = 4
|
2020-08-24 18:22:16 +02:00
|
|
|
self.TICKET_TITLE = "Test ticket" + "!" * 80
|
|
|
|
self.MESSAGE = "some message"
|
|
|
|
self.do_test(
|
|
|
|
expected_topic="#4: Test ticket" + "!" * 42 + "...",
|
|
|
|
expected_message="some message",
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_long_content(self) -> None:
|
|
|
|
self.TICKET_ID = 5
|
|
|
|
self.TICKET_TITLE = "Some ticket"
|
|
|
|
self.MESSAGE = "New comment:\n> It is better\n* here"
|
|
|
|
self.do_test(
|
|
|
|
expected_topic="#5: Some ticket",
|
|
|
|
expected_message="New comment:\n> It is better\n* here",
|
|
|
|
)
|