2016-09-20 22:51:11 +02:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-05-10 19:34:01 +02:00
|
|
|
from typing import Any, Dict, Optional
|
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
|
|
|
|
|
|
|
class ZenDeskHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'zendesk'
|
2018-03-16 22:53:50 +01:00
|
|
|
URL_TEMPLATE = u"/api/v1/external/zendesk?stream={stream}"
|
2016-09-20 22:51:11 +02:00
|
|
|
|
|
|
|
DEFAULT_TICKET_TITLE = 'User can\'t login'
|
|
|
|
TICKET_TITLE = DEFAULT_TICKET_TITLE
|
|
|
|
|
|
|
|
DEFAULT_TICKET_ID = 54
|
|
|
|
TICKET_ID = DEFAULT_TICKET_ID
|
|
|
|
|
|
|
|
DEFAULT_MESSAGE = 'Message'
|
|
|
|
MESSAGE = DEFAULT_MESSAGE
|
|
|
|
|
2018-05-10 19:34:01 +02:00
|
|
|
def get_body(self, fixture_name: str) -> Dict[str, Any]:
|
2016-09-20 22:51:11 +02:00
|
|
|
return {
|
|
|
|
'ticket_title': self.TICKET_TITLE,
|
|
|
|
'ticket_id': self.TICKET_ID,
|
|
|
|
'message': self.MESSAGE,
|
|
|
|
'stream': self.STREAM_NAME,
|
|
|
|
}
|
|
|
|
|
2018-11-09 20:33:58 +01:00
|
|
|
def do_test(self, expected_topic: Optional[str]=None, expected_message: Optional[str]=None) -> None:
|
|
|
|
self.api_stream_message(self.TEST_USER_EMAIL, "", expected_topic, expected_message,
|
2017-12-14 19:02:45 +01:00
|
|
|
content_type=None)
|
2016-09-20 22:51:11 +02:00
|
|
|
self.TICKET_TITLE = self.DEFAULT_TICKET_TITLE
|
|
|
|
self.TICKET_ID = self.DEFAULT_TICKET_ID
|
|
|
|
self.MESSAGE = self.DEFAULT_MESSAGE
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_subject(self) -> None:
|
2016-09-20 22:51:11 +02:00
|
|
|
self.TICKET_ID = 4
|
|
|
|
self.TICKET_TITLE = "Test ticket"
|
2018-11-09 20:33:58 +01:00
|
|
|
self.do_test(expected_topic='#4: Test ticket')
|
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
|
|
|
|
self.TICKET_TITLE = "Test ticket" + '!' * 80
|
2018-11-09 20:33:58 +01:00
|
|
|
self.do_test(expected_topic='#4: Test ticket' + '!' * 42 + '...')
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_content(self) -> None:
|
2016-09-20 22:51:11 +02:00
|
|
|
self.MESSAGE = 'New comment:\n> It is better\n* here'
|
|
|
|
self.do_test(expected_message='New comment:\n> It is better\n* here')
|