diff --git a/zerver/webhooks/beeminder/tests.py b/zerver/webhooks/beeminder/tests.py index 5272cb9a49..2046a0b2f2 100644 --- a/zerver/webhooks/beeminder/tests.py +++ b/zerver/webhooks/beeminder/tests.py @@ -11,11 +11,10 @@ class BeeminderHookTests(WebhookTestCase): def test_beeminder_derail(self, time: Any) -> None: time.return_value = 1517739100 # 5.6 hours from fixture value expected_topic = u"beekeeper" - expected_message = '\n'.join([ - 'You are going to derail from goal **gainweight** in **{:0.1f} hours**'.format(5.6), - ' You need **+2 in 7 days (60)** to avoid derailing', - ' * Pledge: **0$** :relieved:' - ]) + 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.send_and_test_stream_message('derail', expected_topic, @@ -26,11 +25,11 @@ class BeeminderHookTests(WebhookTestCase): 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 = '\n'.join([ - 'You are going to derail from goal **gainweight** in **{:0.1f} hours**'.format(5.6), - ' You need **+2 in 7 days (60)** to avoid derailing', - ' * Pledge: **5$** :worried:' - ]) + 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, diff --git a/zerver/webhooks/beeminder/view.py b/zerver/webhooks/beeminder/view.py index d78a318dab..4ec0c5bd5f 100644 --- a/zerver/webhooks/beeminder/view.py +++ b/zerver/webhooks/beeminder/view.py @@ -8,6 +8,10 @@ from zerver.lib.webhooks.common import check_send_webhook_message from zerver.models import UserProfile import time +MESSAGE_TEMPLATE = ("You are going to derail from goal **{goal_name}** in **{time:0.1f} hours**. " + "You need **{limsum}** to avoid derailing.\n" + "* Pledge: **{pledge}$** {expression}\n") + def get_time(payload: Dict[str, Any]) -> Any: losedate = payload["goal"]["losedate"] time_remaining = (losedate - time.time())/3600 @@ -29,8 +33,12 @@ def api_beeminder_webhook(request: HttpRequest, user_profile: UserProfile, expression = ':relieved:' topic = u'beekeeper' - body = u"You are going to derail from goal **{}** in **{:0.1f} hours**\n \ -You need **{}** to avoid derailing\n * Pledge: **{}$** {}" - body = body.format(goal_name, time_remain, limsum, pledge, expression) + body = MESSAGE_TEMPLATE.format( + goal_name=goal_name, + time=time_remain, + limsum=limsum, + pledge=pledge, + expression=expression + ) check_send_webhook_message(request, user_profile, topic, body) return json_success()