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):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "zapier"
|
2017-01-17 19:41:29 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/zapier?stream={stream}&api_key={api_key}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "zapier"
|
2017-01-17 19:41:29 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_zapier_when_subject_and_body_are_correct(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "New email from zulip@zulip.com"
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = "Your email content is: \nMy Email content."
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("correct_subject_and_body", expected_topic_name, 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:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "New email from zulip@zulip.com"
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = "Your email content is: \nMy Email content."
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("correct_topic_and_body", expected_topic_name, 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:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "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"
|
|
|
|
)
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("weather_update", expected_topic_name, 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):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "zapier"
|
2019-03-09 01:20:46 +01:00
|
|
|
URL_TEMPLATE = "/api/v1/external/zapier?api_key={api_key}&stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "zapier"
|
2019-03-09 01:20:46 +01:00
|
|
|
|
|
|
|
def test_auth(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
payload = self.get_body("zapier_zulip_app_auth")
|
|
|
|
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)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(json_result["full_name"], "Zulip Webhook Bot")
|
|
|
|
self.assertEqual(json_result["email"], "webhook-bot@zulip.com")
|
|
|
|
self.assertIn("id", json_result)
|