Add tests for the Freshdesk webhook.

(imported from commit 5b745ef1a590812d4b3c1adbba7d43d25983c4ad)
This commit is contained in:
Jessica McKellar 2013-11-08 15:17:11 -05:00
parent 3adb9c6d80
commit 30151eff92
6 changed files with 137 additions and 0 deletions

View File

@ -0,0 +1,14 @@
{"freshdesk_webhook":
{
"triggered_event":"{priority:{from:3,to:1}}",
"ticket_id":"11",
"ticket_url":"http://test1234zzz.freshdesk.com/helpdesk/tickets/11",
"ticket_type":"Incident",
"ticket_subject":"Test ticket subject",
"ticket_description":"<div>Test ticket description.</div>",
"ticket_status":"Resolved",
"ticket_priority":"Low",
"requester_name":"Requester Bob",
"requester_email":"requester-bob@example.com",
}
}

View File

@ -0,0 +1,14 @@
{"freshdesk_webhook":
{
"triggered_event":"{note_type:private}",
"ticket_id":"11",
"ticket_url":"http://test1234zzz.freshdesk.com/helpdesk/tickets/11",
"ticket_type":"Incident",
"ticket_subject":"Test ticket subject",
"ticket_description":"<div>Test ticket description.</div>",
"ticket_status":"Open",
"ticket_priority":"Medium",
"requester_name":"Requester Bob",
"requester_email":"requester-bob@example.com",
}
}

View File

@ -0,0 +1,14 @@
{"freshdesk_webhook":
{
"triggered_event":"{note_type:public}",
"ticket_id":"11",
"ticket_url":"http://test1234zzz.freshdesk.com/helpdesk/tickets/11",
"ticket_type":"Incident",
"ticket_subject":"Test ticket subject",
"ticket_description":"<div>Test ticket description.</div>",
"ticket_status":"Open",
"ticket_priority":"Medium",
"requester_name":"Requester Bob",
"requester_email":"requester-bob@example.com",
}
}

View File

@ -0,0 +1,14 @@
{"freshdesk_webhook":
{
"triggered_event":"{status:{from:4,to:6}}",
"ticket_id":"11",
"ticket_url":"http://test1234zzz.freshdesk.com/helpdesk/tickets/11",
"ticket_type":"Incident",
"ticket_subject":"Test ticket subject",
"ticket_description":"<div>Test ticket description.</div>",
"ticket_status":"Waiting on Customer",
"ticket_priority":"Low",
"requester_name":"Requester Bob",
"requester_email":"requester-bob@example.com",
}
}

View File

@ -0,0 +1,14 @@
{"freshdesk_webhook":
{
"triggered_event":"{ticket_action:created}",
"ticket_id":"11",
"ticket_url":"http://test1234zzz.freshdesk.com/helpdesk/tickets/11",
"ticket_type":"Incident",
"ticket_subject":"Test ticket subject",
"ticket_description":"<div>Test ticket description.</div>",
"ticket_status":"Pending",
"ticket_priority":"High",
"requester_name":"Requester Bob",
"requester_email":"requester-bob@example.com",
}
}

View File

@ -4044,6 +4044,73 @@ class StashHookTests(AuthedTestCase):
* `f259e90`: Updating poms ...""")
class FreshdeskHookTests(AuthedTestCase):
def generate_webhook_response(self, fixture):
"""
Helper function to handle the webhook boilerplate.
"""
email = "hamlet@zulip.com"
return self.send_json_payload(
email, "/api/v1/external/freshdesk?stream=freshdesk",
self.fixture_data("freshdesk", fixture, file_type="json"),
stream_name="freshdesk",
content_type="application/x-www-form-urlencoded",
**self.api_auth(email))
def test_ticket_creation(self):
"""
Messages are generated on ticket creation through Freshdesk's
"Dispatch'r" service.
"""
msg = self.generate_webhook_response("ticket_created")
self.assertEqual(msg.subject, u"#11: Test ticket subject")
self.assertEqual(msg.content, """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**""")
def test_status_change(self):
"""
Messages are generated when a ticket's status changes through
Freshdesk's "Observer" service.
"""
msg = self.generate_webhook_response("status_changed")
self.assertEqual(msg.subject, u"#11: Test ticket subject")
self.assertEqual(msg.content, """Requester Bob <requester-bob@example.com> updated [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11):
Status: **Resolved** => **Waiting on Customer**""")
def test_priority_change(self):
"""
Messages are generated when a ticket's priority changes through
Freshdesk's "Observer" service.
"""
msg = self.generate_webhook_response("priority_changed")
self.assertEqual(msg.subject, u"#11: Test ticket subject")
self.assertEqual(msg.content, """Requester Bob <requester-bob@example.com> updated [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11):
Priority: **High** => **Low**""")
def note_change(self, fixture, note_type):
"""
Messages are generated when a note gets added to a ticket through
Freshdesk's "Observer" service.
"""
msg = self.generate_webhook_response(fixture)
self.assertEqual(msg.subject, u"#11: Test ticket subject")
self.assertEqual(msg.content, """Requester Bob <requester-bob@example.com> added a %s note to [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11).""" % (note_type,))
def test_private_note_change(self):
self.note_change("private_note", "private")
def test_public_note_change(self):
self.note_change("public_note", "public")
class RateLimitTests(AuthedTestCase):
def setUp(self):