2016-09-20 22:51:11 +02:00
# -*- coding: utf-8 -*-
2016-12-04 18:38:56 +01:00
from typing import Text
2017-11-16 00:43:10 +01: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 FreshdeskHookTests ( WebhookTestCase ) :
STREAM_NAME = ' freshdesk '
URL_TEMPLATE = u " /api/v1/external/freshdesk?stream= {stream} "
2017-11-04 07:47:46 +01:00
def test_ticket_creation ( self ) - > None :
2016-09-20 22:51:11 +02:00
"""
Messages are generated on ticket creation through Freshdesk ' s
" Dispatch ' r " service .
"""
expected_subject = u " #11: Test ticket subject ☃ "
expected_message = u """ Requester ☃ Bob <requester-bob@example.com> created [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11):
~ ~ ~ quote
Test ticket description ☃ .
~ ~ ~
Type : * * Incident * *
Priority : * * High * *
Status : * * Pending * * """
2017-12-14 19:02:45 +01:00
self . api_stream_message ( self . TEST_USER_EMAIL , ' ticket_created ' , expected_subject , expected_message ,
content_type = " application/x-www-form-urlencoded " )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_status_change ( self ) - > None :
2016-09-20 22:51:11 +02:00
"""
Messages are generated when a ticket ' s status changes through
Freshdesk ' s " Observer " service.
"""
expected_subject = u " #11: Test ticket subject ☃ "
expected_message = """ Requester Bob <requester-bob@example.com> updated [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11):
Status : * * Resolved * * = > * * Waiting on Customer * * """
2017-12-14 19:02:45 +01:00
self . api_stream_message ( self . TEST_USER_EMAIL , ' status_changed ' , expected_subject , expected_message ,
content_type = " application/x-www-form-urlencoded " )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_priority_change ( self ) - > None :
2016-09-20 22:51:11 +02:00
"""
Messages are generated when a ticket ' s priority changes through
Freshdesk ' s " Observer " service.
"""
expected_subject = u " #11: Test ticket subject "
expected_message = """ Requester Bob <requester-bob@example.com> updated [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11):
Priority : * * High * * = > * * Low * * """
2017-12-14 19:02:45 +01:00
self . api_stream_message ( self . TEST_USER_EMAIL , ' priority_changed ' , expected_subject , expected_message ,
content_type = " application/x-www-form-urlencoded " )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def note_change ( self , fixture : Text , note_type : Text ) - > None :
2016-09-20 22:51:11 +02:00
"""
Messages are generated when a note gets added to a ticket through
Freshdesk ' s " Observer " service.
"""
expected_subject = u " #11: Test ticket subject "
expected_message = """ Requester Bob <requester-bob@example.com> added a {} note to [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11). """ . format ( note_type )
2017-12-14 19:02:45 +01:00
self . api_stream_message ( self . TEST_USER_EMAIL , fixture , expected_subject , expected_message ,
content_type = " application/x-www-form-urlencoded " )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_private_note_change ( self ) - > None :
2016-09-20 22:51:11 +02:00
self . note_change ( " private_note " , " private " )
2017-11-04 07:47:46 +01:00
def test_public_note_change ( self ) - > None :
2016-09-20 22:51:11 +02:00
self . note_change ( " public_note " , " public " )
2017-11-04 07:47:46 +01:00
def test_inline_image ( self ) - > None :
2016-09-20 22:51:11 +02:00
"""
Freshdesk sends us descriptions as HTML , so we have to make the
descriptions Zulip markdown - friendly while still doing our best to
preserve links and images .
"""
expected_subject = u " #12: Not enough ☃ guinea pigs "
expected_message = u " Requester \u2603 Bob <requester-bob@example.com> created [ticket #12](http://test1234zzz.freshdesk.com/helpdesk/tickets/12): \n \n ~~~ quote \n There are too many cat pictures on the internet \u2603 . We need more guinea pigs. Exhibit 1: \n \n \n \n \n [guinea_pig.png](http://cdn.freshdesk.com/data/helpdesk/attachments/production/12744808/original/guinea_pig.png) \n ~~~ \n \n Type: **Problem** \n Priority: **Urgent** \n Status: **Open** "
2017-12-14 19:02:45 +01:00
self . api_stream_message ( self . TEST_USER_EMAIL , " inline_images " , expected_subject , expected_message ,
content_type = " application/x-www-form-urlencoded " )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def get_body ( self , fixture_name : Text ) - > Text :
2016-09-20 22:51:11 +02:00
return self . fixture_data ( " freshdesk " , fixture_name , file_type = " json " )