2016-12-24 15:50:46 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2017-11-16 00:43:10 +01:00
|
|
|
|
2018-10-20 03:19:31 +02:00
|
|
|
from mock import MagicMock, patch
|
|
|
|
|
2016-12-24 15:50:46 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
|
|
class GreenhouseHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'greenhouse'
|
|
|
|
URL_TEMPLATE = "/api/v1/external/greenhouse?stream={stream}&api_key={api_key}"
|
|
|
|
FIXTURE_DIR_NAME = 'greenhouse'
|
|
|
|
CONTENT_TYPE = "application/x-www-form-urlencoded"
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_message_candidate_hired(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "Hire Candidate - 19"
|
2016-12-24 15:50:46 +01:00
|
|
|
expected_message = ("Hire Candidate\n>Johnny Smith\nID: 19"
|
|
|
|
"\nApplying for role:\nDeveloper\n**Emails:**"
|
|
|
|
"\nPersonal\npersonal@example.com\nWork\nwork@example.com\n\n\n>"
|
2017-02-12 04:22:13 +01:00
|
|
|
"**Attachments:**\n[Resume](https://prod-heroku.s3.amazonaws.com/...)")
|
2016-12-24 15:50:46 +01:00
|
|
|
|
|
|
|
self.send_and_test_stream_message('candidate_hired',
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic,
|
2016-12-24 15:50:46 +01:00
|
|
|
expected_message,
|
|
|
|
content_type=self.CONTENT_TYPE)
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_message_candidate_rejected(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "Reject Candidate - 265788"
|
2016-12-24 15:50:46 +01:00
|
|
|
expected_message = ("Reject Candidate\n>Hector Porter\nID: "
|
|
|
|
"265788\nApplying for role:\nDesigner"
|
|
|
|
"\n**Emails:**\nPersonal\n"
|
|
|
|
"hector.porter.265788@example.com\n\n\n>"
|
2017-02-12 04:22:13 +01:00
|
|
|
"**Attachments:**\n[Resume](https://prod-heroku.s3.amazonaws.com/...)")
|
2016-12-24 15:50:46 +01:00
|
|
|
|
|
|
|
self.send_and_test_stream_message('candidate_rejected',
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic,
|
2016-12-24 15:50:46 +01:00
|
|
|
expected_message,
|
|
|
|
content_type=self.CONTENT_TYPE)
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_message_candidate_stage_change(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "Candidate Stage Change - 265772"
|
2016-12-24 15:50:46 +01:00
|
|
|
expected_message = ("Candidate Stage Change\n>Giuseppe Hurley"
|
|
|
|
"\nID: 265772\nApplying for role:\n"
|
|
|
|
"Designer\n**Emails:**\nPersonal"
|
|
|
|
"\ngiuseppe.hurley@example.com\n\n\n>"
|
|
|
|
"**Attachments:**\n[Resume](https://prod-heroku.s3.amazonaws.com/...)"
|
|
|
|
"\n[Cover_Letter](https://prod-heroku.s3.amazonaws.com/...)"
|
2017-02-12 04:22:13 +01:00
|
|
|
"\n[Attachment](https://prod-heroku.s3.amazonaws.com/...)")
|
2016-12-24 15:50:46 +01:00
|
|
|
|
|
|
|
self.send_and_test_stream_message('candidate_stage_change',
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic,
|
2016-12-24 15:50:46 +01:00
|
|
|
expected_message,
|
|
|
|
content_type=self.CONTENT_TYPE)
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_message_prospect_created(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "New Prospect Application - 968190"
|
2016-12-24 15:50:46 +01:00
|
|
|
expected_message = ("New Prospect Application\n>Trisha Troy"
|
|
|
|
"\nID: 968190\nApplying for role:\n"
|
|
|
|
"Designer\n**Emails:**\nPersonal"
|
|
|
|
"\nt.troy@example.com\n\n\n>**Attachments:**"
|
2017-02-12 04:22:13 +01:00
|
|
|
"\n[Resume](https://prod-heroku.s3.amazonaws.com/...)")
|
2016-12-24 15:50:46 +01:00
|
|
|
|
|
|
|
self.send_and_test_stream_message('prospect_created',
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic,
|
2016-12-24 15:50:46 +01:00
|
|
|
expected_message,
|
|
|
|
content_type=self.CONTENT_TYPE)
|
|
|
|
|
2018-10-20 03:19:31 +02:00
|
|
|
@patch('zerver.webhooks.greenhouse.view.check_send_webhook_message')
|
|
|
|
def test_ping_message_ignore(
|
|
|
|
self, check_send_webhook_message_mock: MagicMock) -> None:
|
|
|
|
self.url = self.build_webhook_url()
|
|
|
|
payload = self.get_body('ping_event')
|
|
|
|
result = self.client_post(self.url, payload, content_type=self.CONTENT_TYPE)
|
|
|
|
self.assertFalse(check_send_webhook_message_mock.called)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
2018-05-10 19:34:01 +02:00
|
|
|
def get_body(self, fixture_name: str) -> str:
|
2018-04-20 03:57:21 +02:00
|
|
|
return self.webhook_fixture_data("greenhouse", fixture_name, file_type="json")
|