2021-12-17 07:03:22 +01:00
|
|
|
from unittest.mock import MagicMock, patch
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2018-01-08 18:59:16 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2018-01-08 18:59:16 +01:00
|
|
|
class BeeminderHookTests(WebhookTestCase):
|
2024-05-04 22:02:50 +02:00
|
|
|
CHANNEL_NAME = "beeminder"
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/beeminder?api_key={api_key}&stream={stream}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "beeminder"
|
2018-01-08 18:59:16 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
@patch("zerver.webhooks.beeminder.view.time.time")
|
2021-12-17 07:03:22 +01:00
|
|
|
def test_beeminder_derail(self, time: MagicMock) -> None:
|
2018-03-07 19:18:23 +01:00
|
|
|
time.return_value = 1517739100 # 5.6 hours from fixture value
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "beekeeper"
|
2019-04-12 04:40:28 +02:00
|
|
|
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()
|
2018-03-07 19:18:23 +01:00
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"derail",
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name,
|
2020-08-23 15:49:24 +02:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2018-01-08 18:59:16 +01:00
|
|
|
|
2021-02-12 08:20:45 +01:00
|
|
|
@patch("zerver.webhooks.beeminder.view.time.time")
|
2021-12-17 07:03:22 +01:00
|
|
|
def test_beeminder_derail_worried(self, time: MagicMock) -> None:
|
2018-03-07 19:18:23 +01:00
|
|
|
time.return_value = 1517739100 # 5.6 hours from fixture value
|
2024-01-17 15:53:30 +01:00
|
|
|
expected_topic_name = "beekeeper"
|
2019-04-12 04:40:28 +02:00
|
|
|
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()
|
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2024-01-17 15:53:30 +01:00
|
|
|
"derail_worried", expected_topic_name, expected_message, content_type="application/json"
|
2020-08-23 15:49:24 +02:00
|
|
|
)
|