2017-01-17 19:41:29 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2017-01-17 19:41:29 +01:00
|
|
|
class ZapierHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'zapier'
|
|
|
|
URL_TEMPLATE = "/api/v1/external/zapier?stream={stream}&api_key={api_key}"
|
|
|
|
FIXTURE_DIR_NAME = 'zapier'
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_zapier_when_subject_and_body_are_correct(self) -> None:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "New email from zulip@zulip.com"
|
|
|
|
expected_message = "Your email content is: \nMy Email content."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook("correct_subject_and_body", expected_topic, expected_message)
|
2017-02-01 10:30:32 +01:00
|
|
|
|
2018-03-17 19:38:13 +01:00
|
|
|
def test_zapier_when_topic_and_body_are_correct(self) -> None:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "New email from zulip@zulip.com"
|
|
|
|
expected_message = "Your email content is: \nMy Email content."
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook("correct_topic_and_body", expected_topic, expected_message)
|
2018-03-17 19:38:13 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_zapier_weather_update(self) -> None:
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "Here is your weather update for the day:"
|
2021-02-12 08:19:30 +01:00
|
|
|
expected_message = (
|
|
|
|
"Foggy in the morning.\nMaximum temperature to be 24.\nMinimum temperature to be 12"
|
|
|
|
)
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook("weather_update", expected_topic, expected_message)
|
2019-03-09 01:20:46 +01:00
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2019-03-09 01:20:46 +01:00
|
|
|
class ZapierZulipAppTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'zapier'
|
|
|
|
URL_TEMPLATE = "/api/v1/external/zapier?api_key={api_key}&stream={stream}"
|
|
|
|
FIXTURE_DIR_NAME = 'zapier'
|
|
|
|
|
|
|
|
def test_auth(self) -> None:
|
|
|
|
payload = self.get_body('zapier_zulip_app_auth')
|
2021-02-12 08:19:30 +01:00
|
|
|
result = self.client_post(self.url, payload, content_type='application/json')
|
2019-03-09 01:20:46 +01:00
|
|
|
json_result = self.assert_json_success(result)
|
|
|
|
self.assertEqual(json_result['full_name'], 'Zulip Webhook Bot')
|
|
|
|
self.assertEqual(json_result['email'], 'webhook-bot@zulip.com')
|
|
|
|
self.assertIn('id', json_result)
|