zulip/zerver/webhooks/beeminder/tests.py

42 lines
1.7 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
from typing import Any
from unittest.mock import patch
2018-01-08 18:59:16 +01:00
from zerver.lib.test_classes import WebhookTestCase
2018-01-08 18:59:16 +01:00
class BeeminderHookTests(WebhookTestCase):
STREAM_NAME = 'beeminder'
URL_TEMPLATE = u"/api/v1/external/beeminder?api_key={api_key}&stream={stream}"
2018-01-08 18:59:16 +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
expected_topic = u"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()
2018-01-08 18:59:16 +01:00
self.send_and_test_stream_message('derail',
expected_topic,
2018-01-08 18:59:16 +01:00
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 = u"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.send_and_test_stream_message('derail_worried',
expected_topic,
expected_message,
content_type="application/json")
2018-01-08 18:59:16 +01:00
def get_body(self, fixture_name: str) -> str:
return self.webhook_fixture_data("beeminder", fixture_name, file_type="json")