mirror of
https://github.com/zulip/zulip.git
synced 2025-11-18 04:43:58 +00:00
Almost all webhook tests use this helper, except a few webhooks that write to private streams. Being concise is important here, and the name `self.send_and_test_stream_message` always confused me, since it sounds you're sending a stream message, and it leaves out the webhook piece. We should consider renaming `send_and_test_private_message` to something like `check_webhook_private`, but I couldn't decide on a great name, and it's very rarely used. So for now I just made sure the docstrings of the two sibling functions reference each other.
30 lines
1.4 KiB
Python
30 lines
1.4 KiB
Python
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
class IFTTTHookTests(WebhookTestCase):
|
|
STREAM_NAME = 'ifttt'
|
|
URL_TEMPLATE = "/api/v1/external/ifttt?stream={stream}&api_key={api_key}"
|
|
FIXTURE_DIR_NAME = 'ifttt'
|
|
|
|
def test_ifttt_when_subject_and_body_are_correct(self) -> None:
|
|
expected_topic = "Email sent from email@email.com"
|
|
expected_message = "Email subject: Subject"
|
|
self.check_webhook("correct_subject_and_body", expected_topic, expected_message)
|
|
|
|
def test_ifttt_when_topic_and_body_are_correct(self) -> None:
|
|
expected_topic = "Email sent from email@email.com"
|
|
expected_message = "Email subject: Subject"
|
|
self.check_webhook("correct_topic_and_body", expected_topic, expected_message)
|
|
|
|
def test_ifttt_when_topic_is_missing(self) -> None:
|
|
self.url = self.build_webhook_url()
|
|
payload = self.get_body('invalid_payload_with_missing_topic')
|
|
result = self.client_post(self.url, payload, content_type='application/json')
|
|
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()
|
|
payload = self.get_body('invalid_payload_with_missing_content')
|
|
result = self.client_post(self.url, payload, content_type='application/json')
|
|
self.assert_json_error(result, "Content can't be empty")
|