zulip/zerver/webhooks/zendesk/tests.py

53 lines
1.6 KiB
Python

from typing import Any, Dict
from zerver.lib.test_classes import WebhookTestCase
class ZenDeskHookTests(WebhookTestCase):
STREAM_NAME = 'zendesk'
URL_TEMPLATE = "/api/v1/external/zendesk?stream={stream}"
def get_body(self, fixture_name: str) -> Dict[str, Any]:
return {
'ticket_title': self.TICKET_TITLE,
'ticket_id': self.TICKET_ID,
'message': self.MESSAGE,
'stream': self.STREAM_NAME,
}
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,
)
def test_short_topic(self) -> None:
self.TICKET_ID = 4
self.TICKET_TITLE = "Test ticket"
self.MESSAGE = "some message"
self.do_test(
expected_topic='#4: Test ticket',
expected_message="some message",
)
def test_long_subject(self) -> None:
self.TICKET_ID = 4
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",
)