2018-05-10 19:34:01 +02:00
|
|
|
from typing import Any
|
2020-01-14 22:06:24 +01:00
|
|
|
from unittest.mock import patch
|
|
|
|
|
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):
|
|
|
|
STREAM_NAME = 'beeminder'
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/beeminder?api_key={api_key}&stream={stream}"
|
2018-01-08 18:59:16 +01:00
|
|
|
|
2018-03-07 19:18:23 +01:00
|
|
|
@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
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "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",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2018-01-08 18:59:16 +01:00
|
|
|
|
2018-03-07 19:18:23 +01:00
|
|
|
@patch('zerver.webhooks.beeminder.view.time.time')
|
2018-03-17 18:03:42 +01:00
|
|
|
def test_beeminder_derail_worried(self, time: Any) -> None:
|
2018-03-07 19:18:23 +01:00
|
|
|
time.return_value = 1517739100 # 5.6 hours from fixture value
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_topic = "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(
|
|
|
|
"derail_worried", expected_topic, expected_message, content_type="application/json"
|
|
|
|
)
|
2018-01-08 18:59:16 +01:00
|
|
|
|
2018-05-10 19:34:01 +02:00
|
|
|
def get_body(self, fixture_name: str) -> str:
|
2018-04-20 03:57:21 +02:00
|
|
|
return self.webhook_fixture_data("beeminder", fixture_name, file_type="json")
|