mirror of
https://github.com/zulip/zulip.git
synced 2025-11-21 23:19:10 +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.
55 lines
1.8 KiB
Python
55 lines
1.8 KiB
Python
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
class CanarytokenHookTests(WebhookTestCase):
|
|
STREAM_NAME = 'canarytoken'
|
|
URL_TEMPLATE = "/api/v1/external/canarytoken?stream={stream}&api_key={api_key}"
|
|
FIXTURE_DIR_NAME = 'canarytoken'
|
|
|
|
def test_canarytoken_new(self) -> None:
|
|
expected_message = (
|
|
"**:alert: Canarytoken has been triggered on 2020-06-09 14:04:39!**\n\n"
|
|
"Congrats! The newly saved webhook works \n\n"
|
|
"[Manage this canarytoken](http://example.com/test/url/for/webhook)"
|
|
)
|
|
|
|
self.check_webhook(
|
|
"canarytoken_new",
|
|
"canarytoken alert",
|
|
expected_message,
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|
|
|
|
def test_canarytoken_real(self) -> None:
|
|
expected_message = (
|
|
"**:alert: Canarytoken has been triggered on 2020-06-09 14:04:47 "
|
|
"(UTC)!**\n\n"
|
|
"Canarytoken example \n\n"
|
|
"[Manage this canarytoken]"
|
|
"(https://canarytokens.org/manage?token=foo&auth=bar)"
|
|
)
|
|
|
|
self.check_webhook(
|
|
"canarytoken_real",
|
|
"canarytoken alert",
|
|
expected_message,
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|
|
|
|
def test_canarytoken_with_specific_topic(self) -> None:
|
|
self.url = self.build_webhook_url(topic='foo')
|
|
expected_message = (
|
|
"**:alert: Canarytoken has been triggered on 2020-06-09 14:04:47 "
|
|
"(UTC)!**\n\n"
|
|
"Canarytoken example \n\n"
|
|
"[Manage this canarytoken]"
|
|
"(https://canarytokens.org/manage?token=foo&auth=bar)"
|
|
)
|
|
|
|
self.check_webhook(
|
|
"canarytoken_real",
|
|
"foo",
|
|
expected_message,
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|