2017-01-17 19:41:29 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
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'
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_zapier_when_subject_and_body_are_correct(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"New email from zulip@zulip.com"
|
2017-02-12 04:22:13 +01:00
|
|
|
expected_message = u"Your email content is: \nMy Email content."
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('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:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"New email from zulip@zulip.com"
|
2018-03-17 19:38:13 +01:00
|
|
|
expected_message = u"Your email content is: \nMy Email content."
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('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:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"Here is your weather update for the day:"
|
2017-02-01 10:30:32 +01:00
|
|
|
expected_message = u"Foggy in the morning.\nMaximum temperature to be 24.\nMinimum temperature to be 12"
|
2018-11-09 20:33:58 +01:00
|
|
|
self.send_and_test_stream_message('weather_update', expected_topic, expected_message)
|
2019-02-01 02:41:57 +01:00
|
|
|
|
|
|
|
class ZapierZulipAppTests(WebhookTestCase):
|
2019-02-01 03:24:35 +01:00
|
|
|
STREAM_NAME = 'zapier'
|
|
|
|
URL_TEMPLATE = "/api/v1/external/zapier?api_key={api_key}&stream={stream}"
|
2019-02-01 02:41:57 +01:00
|
|
|
FIXTURE_DIR_NAME = 'zapier'
|
|
|
|
|
|
|
|
def test_auth(self) -> None:
|
|
|
|
payload = self.get_body('zapier_zulip_app_auth')
|
|
|
|
headers = {'HTTP_USER_AGENT': 'ZapierZulipApp'}
|
|
|
|
result = self.client_post(self.url, payload,
|
|
|
|
content_type='application/json',
|
|
|
|
**headers)
|
2019-02-09 05:05:32 +01:00
|
|
|
json_result = self.assert_json_success(result)
|
|
|
|
self.assertEqual(json_result['bot_name'], 'Zulip Webhook Bot')
|
|
|
|
self.assertEqual(json_result['bot_email'], 'webhook-bot@zulip.com')
|
|
|
|
self.assertIn('bot_id', json_result)
|
2019-02-01 03:24:35 +01:00
|
|
|
|
|
|
|
def test_stream(self) -> None:
|
|
|
|
expected_topic = u"Sample message from Zapier!"
|
|
|
|
expected_message = u"Hi! I am a new sample message from Zapier!"
|
|
|
|
self.send_and_test_stream_message('zapier_zulip_app_stream',
|
|
|
|
expected_topic, expected_message,
|
|
|
|
HTTP_USER_AGENT='ZapierZulipApp')
|
2019-02-02 18:29:24 +01:00
|
|
|
|
|
|
|
def test_private(self) -> None:
|
|
|
|
payload = self.get_body('zapier_zulip_app_private')
|
|
|
|
headers = {'HTTP_USER_AGENT': 'ZapierZulipApp'}
|
|
|
|
result = self.client_post(self.url, payload,
|
|
|
|
content_type='application/json',
|
|
|
|
**headers)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
|
|
|
|
expected_message = "Sample content for private huddle message"
|
|
|
|
msg = self.get_last_message()
|
|
|
|
self.assertEqual(msg.content, expected_message)
|