2018-01-18 18:07:06 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-03-07 19:18:23 +01:00
|
|
|
from unittest.mock import patch
|
2018-05-10 19:34:01 +02:00
|
|
|
from typing import Any
|
2018-01-08 18:59:16 +01:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
|
|
class BeeminderHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'beeminder'
|
2018-03-17 18:03:42 +01:00
|
|
|
URL_TEMPLATE = u"/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
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"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
|
|
|
|
2018-01-08 18:59:16 +01:00
|
|
|
self.send_and_test_stream_message('derail',
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic,
|
2018-01-08 18:59:16 +01:00
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
|
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
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = u"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()
|
|
|
|
|
2018-03-17 18:03:42 +01:00
|
|
|
self.send_and_test_stream_message('derail_worried',
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic,
|
2018-03-17 18:03:42 +01:00
|
|
|
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")
|