mirror of
https://github.com/zulip/zulip.git
synced 2025-10-24 00:23:49 +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.
42 lines
1.5 KiB
Python
42 lines
1.5 KiB
Python
from typing import Any
|
|
from unittest.mock import patch
|
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
class BeeminderHookTests(WebhookTestCase):
|
|
STREAM_NAME = 'beeminder'
|
|
URL_TEMPLATE = "/api/v1/external/beeminder?api_key={api_key}&stream={stream}"
|
|
|
|
@patch('zerver.webhooks.beeminder.view.time.time')
|
|
def test_beeminder_derail(self, time: Any) -> None:
|
|
time.return_value = 1517739100 # 5.6 hours from fixture value
|
|
expected_topic = "beekeeper"
|
|
expected_message = """
|
|
You are going to derail from goal **gainweight** in **5.6 hours**. You need **+2 in 7 days (60)** to avoid derailing.
|
|
* Pledge: **0$** :relieved:
|
|
""".strip()
|
|
|
|
self.check_webhook(
|
|
"derail",
|
|
expected_topic,
|
|
expected_message,
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|
|
|
|
@patch('zerver.webhooks.beeminder.view.time.time')
|
|
def test_beeminder_derail_worried(self, time: Any) -> None:
|
|
time.return_value = 1517739100 # 5.6 hours from fixture value
|
|
expected_topic = "beekeeper"
|
|
expected_message = """
|
|
You are going to derail from goal **gainweight** in **5.6 hours**. You need **+2 in 7 days (60)** to avoid derailing.
|
|
* Pledge: **5$** :worried:
|
|
""".strip()
|
|
|
|
self.check_webhook(
|
|
"derail_worried", expected_topic, expected_message, content_type="application/json"
|
|
)
|
|
|
|
def get_body(self, fixture_name: str) -> str:
|
|
return self.webhook_fixture_data("beeminder", fixture_name, file_type="json")
|