Files
zulip/zerver/webhooks/zapier/tests.py
Steve Howell 388053db6b webhook tests: Rename main helper to check_webhook.
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.
2020-08-24 12:34:46 -07:00

37 lines
1.7 KiB
Python

from zerver.lib.test_classes import WebhookTestCase
class ZapierHookTests(WebhookTestCase):
STREAM_NAME = 'zapier'
URL_TEMPLATE = "/api/v1/external/zapier?stream={stream}&api_key={api_key}"
FIXTURE_DIR_NAME = 'zapier'
def test_zapier_when_subject_and_body_are_correct(self) -> None:
expected_topic = "New email from zulip@zulip.com"
expected_message = "Your email content is: \nMy Email content."
self.check_webhook("correct_subject_and_body", expected_topic, expected_message)
def test_zapier_when_topic_and_body_are_correct(self) -> None:
expected_topic = "New email from zulip@zulip.com"
expected_message = "Your email content is: \nMy Email content."
self.check_webhook("correct_topic_and_body", expected_topic, expected_message)
def test_zapier_weather_update(self) -> None:
expected_topic = "Here is your weather update for the day:"
expected_message = "Foggy in the morning.\nMaximum temperature to be 24.\nMinimum temperature to be 12"
self.check_webhook("weather_update", expected_topic, expected_message)
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')
result = self.client_post(self.url, payload,
content_type='application/json')
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)