mirror of
https://github.com/zulip/zulip.git
synced 2025-11-01 12:33:40 +00:00
webhooks/basecamp: Improve message formatting and punctuation.
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
"app_url": "https://3.basecamp.com/3688623/buckets/2957043/questions/432527747/answers/2017-03-16#__recording_432529636",
|
||||
"parent": {
|
||||
"id": 432527747,
|
||||
"title": "Question",
|
||||
"title": "Question?",
|
||||
"type": "Question",
|
||||
"url": "https://3.basecampapi.com/3688623/buckets/2957043/questions/432527747.json",
|
||||
"app_url": "https://3.basecamp.com/3688623/buckets/2957043/questions/432527747"
|
||||
|
@@ -9,123 +9,123 @@ class BasecampHookTests(WebhookTestCase):
|
||||
EXPECTED_TOPIC = "Zulip HQ"
|
||||
|
||||
def test_basecamp_makes_doc_active(self) -> None:
|
||||
expected_message = u"Tomasz activated the document [New doc](https://3.basecamp.com/3688623/buckets/2957043/documents/432522214)"
|
||||
expected_message = u"Tomasz activated the document [New doc](https://3.basecamp.com/3688623/buckets/2957043/documents/432522214)."
|
||||
self._send_and_test_message('doc_active', expected_message)
|
||||
|
||||
def test_basecamp_makes_doc_archived(self) -> None:
|
||||
expected_message = u"Tomasz archived the document [new doc](https://3.basecamp.com/3688623/buckets/2957043/documents/434455988)"
|
||||
expected_message = u"Tomasz archived the document [new doc](https://3.basecamp.com/3688623/buckets/2957043/documents/434455988)."
|
||||
self._send_and_test_message('doc_archived', expected_message)
|
||||
|
||||
def test_basecamp_makes_doc_changed_content(self) -> None:
|
||||
expected_message = u"Tomasz changed content of the document [New doc edit](https://3.basecamp.com/3688623/buckets/2957043/documents/432522214)"
|
||||
expected_message = u"Tomasz changed content of the document [New doc edit](https://3.basecamp.com/3688623/buckets/2957043/documents/432522214)."
|
||||
self._send_and_test_message('doc_content_changed', expected_message)
|
||||
|
||||
def test_basecamp_makes_doc_changed_title(self) -> None:
|
||||
expected_message = u"Tomasz changed title of the document [New doc edit](https://3.basecamp.com/3688623/buckets/2957043/documents/432522214)"
|
||||
expected_message = u"Tomasz changed title of the document [New doc edit](https://3.basecamp.com/3688623/buckets/2957043/documents/432522214)."
|
||||
self._send_and_test_message('doc_title_changed', expected_message)
|
||||
|
||||
def test_basecamp_makes_doc_publicized(self) -> None:
|
||||
expected_message = u"Tomasz publicized the document [new doc](https://3.basecamp.com/3688623/buckets/2957043/documents/434455988)"
|
||||
expected_message = u"Tomasz publicized the document [new doc](https://3.basecamp.com/3688623/buckets/2957043/documents/434455988)."
|
||||
self._send_and_test_message('doc_publicized', expected_message)
|
||||
|
||||
def test_basecamp_makes_doc_created(self) -> None:
|
||||
expected_message = u"Tomasz created the document [new doc](https://3.basecamp.com/3688623/buckets/2957043/documents/434455988)"
|
||||
expected_message = u"Tomasz created the document [new doc](https://3.basecamp.com/3688623/buckets/2957043/documents/434455988)."
|
||||
self._send_and_test_message('doc_created', expected_message)
|
||||
|
||||
def test_basecamp_makes_doc_trashed(self) -> None:
|
||||
expected_message = u"Tomasz trashed the document [new doc](https://3.basecamp.com/3688623/buckets/2957043/documents/434455988)"
|
||||
expected_message = u"Tomasz trashed the document [new doc](https://3.basecamp.com/3688623/buckets/2957043/documents/434455988)."
|
||||
self._send_and_test_message('doc_trashed', expected_message)
|
||||
|
||||
def test_basecamp_makes_doc_unarchived(self) -> None:
|
||||
expected_message = u"Tomasz unarchived the document [new doc](https://3.basecamp.com/3688623/buckets/2957043/documents/434455988)"
|
||||
expected_message = u"Tomasz unarchived the document [new doc](https://3.basecamp.com/3688623/buckets/2957043/documents/434455988)."
|
||||
self._send_and_test_message('doc_unarchive', expected_message)
|
||||
|
||||
def test_basecamp_makes_questions_answer_archived(self) -> None:
|
||||
expected_message = u"Tomasz archived the [answer](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747/answers/2017-03-16#__recording_432529636) of the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)"
|
||||
expected_message = u"Tomasz archived the [answer](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747/answers/2017-03-16#__recording_432529636) of the question [Question?](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)"
|
||||
self._send_and_test_message('questions_answer_archived', expected_message)
|
||||
|
||||
def test_basecamp_makes_questions_answer_content_changed(self) -> None:
|
||||
expected_message = u"Tomasz changed content of the [answer](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747/answers/2017-03-16#__recording_432529636) of the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)"
|
||||
expected_message = u"Tomasz changed content of the [answer](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747/answers/2017-03-16#__recording_432529636) of the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)."
|
||||
self._send_and_test_message('questions_answer_content_changed', expected_message)
|
||||
|
||||
def test_basecamp_makes_questions_answer_created(self) -> None:
|
||||
expected_message = u"Tomasz created the [answer](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747/answers/2017-03-16#__recording_432529636) of the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)"
|
||||
expected_message = u"Tomasz created the [answer](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747/answers/2017-03-16#__recording_432529636) of the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)."
|
||||
self._send_and_test_message('questions_answer_created', expected_message)
|
||||
|
||||
def test_basecamp_makes_questions_answer_trashed(self) -> None:
|
||||
expected_message = u"Tomasz trashed the [answer](https://3.basecamp.com/3688623/buckets/2957043/question_answers/432529636) of the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)"
|
||||
expected_message = u"Tomasz trashed the [answer](https://3.basecamp.com/3688623/buckets/2957043/question_answers/432529636) of the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)."
|
||||
self._send_and_test_message('questions_answer_trashed', expected_message)
|
||||
|
||||
def test_basecamp_makes_questions_answer_unarchived(self) -> None:
|
||||
expected_message = u"Tomasz unarchived the [answer](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747/answers/2017-03-16#__recording_432529636) of the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)"
|
||||
expected_message = u"Tomasz unarchived the [answer](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747/answers/2017-03-16#__recording_432529636) of the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)."
|
||||
self._send_and_test_message('questions_answer_unarchived', expected_message)
|
||||
|
||||
def test_basecamp_makes_question_archived(self) -> None:
|
||||
expected_message = u"Tomasz archived the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)"
|
||||
expected_message = u"Tomasz archived the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)."
|
||||
self._send_and_test_message('question_archived', expected_message)
|
||||
|
||||
def test_basecamp_makes_question_created(self) -> None:
|
||||
expected_message = u"Tomasz created the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)"
|
||||
expected_message = u"Tomasz created the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)."
|
||||
self._send_and_test_message('question_created', expected_message)
|
||||
|
||||
def test_basecamp_makes_question_trashed(self) -> None:
|
||||
expected_message = u"Tomasz trashed the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)"
|
||||
expected_message = u"Tomasz trashed the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)."
|
||||
self._send_and_test_message('question_trashed', expected_message)
|
||||
|
||||
def test_basecamp_makes_question_unarchived(self) -> None:
|
||||
expected_message = u"Tomasz unarchived the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)"
|
||||
expected_message = u"Tomasz unarchived the question [Question](https://3.basecamp.com/3688623/buckets/2957043/questions/432527747)."
|
||||
self._send_and_test_message('question_unarchived', expected_message)
|
||||
|
||||
def test_basecamp_makes_message_archived(self) -> None:
|
||||
expected_message = u"Tomasz archived the message [Message Title new](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)"
|
||||
expected_message = u"Tomasz archived the message [Message Title new](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)."
|
||||
self._send_and_test_message('message_archived', expected_message)
|
||||
|
||||
def test_basecamp_makes_message_content_change(self) -> None:
|
||||
expected_message = u"Tomasz changed content of the message [Message Title new](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)"
|
||||
expected_message = u"Tomasz changed content of the message [Message Title new](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)."
|
||||
self._send_and_test_message('message_content_changed', expected_message)
|
||||
|
||||
def test_basecamp_makes_message_created(self) -> None:
|
||||
expected_message = u"Tomasz created the message [Message Title](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)"
|
||||
expected_message = u"Tomasz created the message [Message Title](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)."
|
||||
self._send_and_test_message('message_created', expected_message)
|
||||
|
||||
def test_basecamp_makes_message_title_change(self) -> None:
|
||||
expected_message = u"Tomasz changed subject of the message [Message Title new](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)"
|
||||
expected_message = u"Tomasz changed subject of the message [Message Title new](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)."
|
||||
self._send_and_test_message('message_title_changed', expected_message)
|
||||
|
||||
def test_basecamp_makes_message_trashed(self) -> None:
|
||||
expected_message = u"Tomasz trashed the message [Message Title new](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)"
|
||||
expected_message = u"Tomasz trashed the message [Message Title new](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)."
|
||||
self._send_and_test_message('message_trashed', expected_message)
|
||||
|
||||
def test_basecamp_makes_message_unarchived(self) -> None:
|
||||
expected_message = u"Tomasz unarchived the message [Message Title new](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)"
|
||||
expected_message = u"Tomasz unarchived the message [Message Title new](https://3.basecamp.com/3688623/buckets/2957043/messages/430680605)."
|
||||
self._send_and_test_message('message_unarchived', expected_message)
|
||||
|
||||
def test_basecamp_makes_todo_list_created(self) -> None:
|
||||
expected_message = u"Tomasz created the todo list [NEW TO DO LIST](https://3.basecamp.com/3688623/buckets/2957043/todolists/427050190)"
|
||||
expected_message = u"Tomasz created the todo list [NEW TO DO LIST](https://3.basecamp.com/3688623/buckets/2957043/todolists/427050190)."
|
||||
self._send_and_test_message('todo_list_created', expected_message)
|
||||
|
||||
def test_basecamp_makes_todo_list_description_changed(self) -> None:
|
||||
expected_message = u"Tomasz changed description of the todo list [NEW TO DO LIST](https://3.basecamp.com/3688623/buckets/2957043/todolists/427050190)"
|
||||
expected_message = u"Tomasz changed description of the todo list [NEW TO DO LIST](https://3.basecamp.com/3688623/buckets/2957043/todolists/427050190)."
|
||||
self._send_and_test_message('todo_list_description_changed', expected_message)
|
||||
|
||||
def test_basecamp_makes_todo_list_modified(self) -> None:
|
||||
expected_message = u"Tomasz changed name of the todo list [NEW Name TO DO LIST](https://3.basecamp.com/3688623/buckets/2957043/todolists/427050190)"
|
||||
expected_message = u"Tomasz changed name of the todo list [NEW Name TO DO LIST](https://3.basecamp.com/3688623/buckets/2957043/todolists/427050190)."
|
||||
self._send_and_test_message('todo_list_name_changed', expected_message)
|
||||
|
||||
def test_basecamp_makes_todo_assignment_changed(self) -> None:
|
||||
expected_message = u"Tomasz changed assignment of the todo task [New task](https://3.basecamp.com/3688623/buckets/2957043/todos/427055624)"
|
||||
expected_message = u"Tomasz changed assignment of the todo task [New task](https://3.basecamp.com/3688623/buckets/2957043/todos/427055624)."
|
||||
self._send_and_test_message('todo_assignment_changed', expected_message)
|
||||
|
||||
def test_basecamp_makes_todo_completed(self) -> None:
|
||||
expected_message = u"Tomasz completed the todo task [New task](https://3.basecamp.com/3688623/buckets/2957043/todos/427055624)"
|
||||
expected_message = u"Tomasz completed the todo task [New task](https://3.basecamp.com/3688623/buckets/2957043/todos/427055624)."
|
||||
self._send_and_test_message('todo_completed', expected_message)
|
||||
|
||||
def test_basecamp_makes_todo_created(self) -> None:
|
||||
expected_message = u"Tomasz created the todo task [New task](https://3.basecamp.com/3688623/buckets/2957043/todos/427055624)"
|
||||
expected_message = u"Tomasz created the todo task [New task](https://3.basecamp.com/3688623/buckets/2957043/todos/427055624)."
|
||||
self._send_and_test_message('todo_created', expected_message)
|
||||
|
||||
def test_basecamp_makes_comment_created(self) -> None:
|
||||
expected_message = u"Tomasz created the [comment](https://3.basecamp.com/3688623/buckets/2957043/todos/427055624#__recording_427058780) of the task [New task](https://3.basecamp.com/3688623/buckets/2957043/todos/427055624)"
|
||||
expected_message = u"Tomasz created the [comment](https://3.basecamp.com/3688623/buckets/2957043/todos/427055624#__recording_427058780) of the task [New task](https://3.basecamp.com/3688623/buckets/2957043/todos/427055624)."
|
||||
self._send_and_test_message('comment_created', expected_message)
|
||||
|
||||
def _send_and_test_message(self, fixture_name: str, expected_message: str) -> None:
|
||||
|
@@ -1,4 +1,5 @@
|
||||
import re
|
||||
import string
|
||||
from typing import Any, Dict
|
||||
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
@@ -77,26 +78,34 @@ def get_verb(event: str, prefix: str) -> str:
|
||||
return "changed {} of".format(matched.group('subject'))
|
||||
return verb
|
||||
|
||||
def add_punctuation_if_necessary(body: str, title: str) -> str:
|
||||
if title[-1] not in string.punctuation:
|
||||
body = '{}.'.format(body)
|
||||
return body
|
||||
|
||||
def get_document_body(event: str, payload: Dict[str, Any]) -> str:
|
||||
return get_generic_body(event, payload, 'document_', DOCUMENT_TEMPLATE)
|
||||
|
||||
def get_questions_answer_body(event: str, payload: Dict[str, Any]) -> str:
|
||||
verb = get_verb(event, 'question_answer_')
|
||||
question = payload['recording']['parent']
|
||||
title = question['title']
|
||||
template = add_punctuation_if_necessary(QUESTIONS_ANSWER_TEMPLATE, title)
|
||||
|
||||
return QUESTIONS_ANSWER_TEMPLATE.format(
|
||||
return template.format(
|
||||
user_name=get_event_creator(payload),
|
||||
verb=verb,
|
||||
answer_url=get_subject_url(payload),
|
||||
question_title=question['title'],
|
||||
question_title=title,
|
||||
question_url=question['app_url']
|
||||
)
|
||||
|
||||
def get_comment_body(event: str, payload: Dict[str, Any]) -> str:
|
||||
verb = get_verb(event, 'comment_')
|
||||
task = payload['recording']['parent']
|
||||
template = add_punctuation_if_necessary(COMMENT_TEMPLATE, task['title'])
|
||||
|
||||
return COMMENT_TEMPLATE.format(
|
||||
return template.format(
|
||||
user_name=get_event_creator(payload),
|
||||
verb=verb,
|
||||
answer_url=get_subject_url(payload),
|
||||
@@ -118,6 +127,8 @@ def get_todo_body(event: str, payload: Dict[str, Any]) -> str:
|
||||
|
||||
def get_generic_body(event: str, payload: Dict[str, Any], prefix: str, template: str) -> str:
|
||||
verb = get_verb(event, prefix)
|
||||
title = get_subject_title(payload)
|
||||
template = add_punctuation_if_necessary(template, title)
|
||||
|
||||
return template.format(
|
||||
user_name=get_event_creator(payload),
|
||||
|
Reference in New Issue
Block a user