2016-11-10 19:30:09 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2016-09-20 22:51:11 +02:00
|
|
|
class IFTTTHookTests(WebhookTestCase):
|
2024-05-04 22:02:50 +02:00
|
|
|
CHANNEL_NAME = "ifttt"
|
2016-09-20 22:51:11 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/ifttt?stream={stream}&api_key={api_key}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "ifttt"
|
2021-07-17 18:05:15 +02:00
|
|
|
VIEW_FUNCTION_NAME = "api_iftt_app_webhook"
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_ifttt_when_subject_and_body_are_correct(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Email sent from email@email.com"
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = "Email subject: Subject"
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("correct_subject_and_body", expected_topic_name, expected_message)
|
2018-03-17 21:11:54 +01:00
|
|
|
|
|
|
|
def test_ifttt_when_topic_and_body_are_correct(self) -> None:
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "Email sent from email@email.com"
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = "Email subject: Subject"
|
2024-01-17 15:53:30 +01:00
|
|
|
self.check_webhook("correct_topic_and_body", expected_topic_name, expected_message)
|
2018-10-04 18:29:35 +02:00
|
|
|
|
|
|
|
def test_ifttt_when_topic_is_missing(self) -> None:
|
|
|
|
self.url = self.build_webhook_url()
|
2021-02-12 08:20:45 +01:00
|
|
|
payload = self.get_body("invalid_payload_with_missing_topic")
|
|
|
|
result = self.client_post(self.url, payload, content_type="application/json")
|
2018-10-04 18:29:35 +02:00
|
|
|
self.assert_json_error(result, "Topic can't be empty")
|
|
|
|
|
|
|
|
def test_ifttt_when_content_is_missing(self) -> None:
|
|
|
|
self.url = self.build_webhook_url()
|
2021-02-12 08:20:45 +01:00
|
|
|
payload = self.get_body("invalid_payload_with_missing_content")
|
|
|
|
result = self.client_post(self.url, payload, content_type="application/json")
|
2018-10-04 18:29:35 +02:00
|
|
|
self.assert_json_error(result, "Content can't be empty")
|
2021-12-13 20:06:21 +01:00
|
|
|
|
|
|
|
def test_ifttt_when_topic_is_dict(self) -> None:
|
|
|
|
self.url = self.build_webhook_url()
|
|
|
|
payload = self.get_body("invalid_payload_with_dict_topic")
|
|
|
|
result = self.client_post(self.url, payload, content_type="application/json")
|
2022-10-08 19:27:08 +02:00
|
|
|
self.assert_json_error(result, "Malformed payload")
|
2021-12-13 20:06:21 +01:00
|
|
|
|
|
|
|
def test_ifttt_when_content_is_dict(self) -> None:
|
|
|
|
self.url = self.build_webhook_url()
|
|
|
|
payload = self.get_body("invalid_payload_with_dict_content")
|
|
|
|
result = self.client_post(self.url, payload, content_type="application/json")
|
2022-10-08 19:27:08 +02:00
|
|
|
self.assert_json_error(result, "Malformed payload")
|