webhooks/wordpress: Improve message formatting and punctuation.

This commit is contained in:
Eeshan Garg 2019-04-16 21:39:09 -02:30 committed by Tim Abbott
parent 0a0df3bc58
commit 21cdb6decc
2 changed files with 14 additions and 7 deletions

View File

@ -9,7 +9,7 @@ class WordPressHookTests(WebhookTestCase):
def test_publish_post(self) -> None: def test_publish_post(self) -> None:
expected_topic = u"WordPress Post" expected_topic = u"WordPress Post"
expected_message = u"New post published.\n[New Blog Post](http://example.com\n)" expected_message = u"New post published:\n* [New Blog Post](http://example.com\n)"
self.send_and_test_stream_message('publish_post', expected_topic, expected_message, self.send_and_test_stream_message('publish_post', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded") content_type="application/x-www-form-urlencoded")
@ -17,7 +17,7 @@ class WordPressHookTests(WebhookTestCase):
def test_publish_post_type_not_provided(self) -> None: def test_publish_post_type_not_provided(self) -> None:
expected_topic = u"WordPress Post" expected_topic = u"WordPress Post"
expected_message = u"New post published.\n[New Blog Post](http://example.com\n)" expected_message = u"New post published:\n* [New Blog Post](http://example.com\n)"
self.send_and_test_stream_message('publish_post_type_not_provided', self.send_and_test_stream_message('publish_post_type_not_provided',
expected_topic, expected_message, expected_topic, expected_message,
@ -27,7 +27,7 @@ class WordPressHookTests(WebhookTestCase):
# Note: the fixture includes 'hook=publish_post' because it's always added by HookPress # Note: the fixture includes 'hook=publish_post' because it's always added by HookPress
expected_topic = u"WordPress Notification" expected_topic = u"WordPress Notification"
expected_message = u"New post published.\n" + "[New WordPress Post](WordPress Post URL)" expected_message = u"New post published:\n* [New WordPress Post](WordPress Post URL)"
self.send_and_test_stream_message('publish_post_no_data_provided', self.send_and_test_stream_message('publish_post_no_data_provided',
expected_topic, expected_message, expected_topic, expected_message,
@ -36,7 +36,7 @@ class WordPressHookTests(WebhookTestCase):
def test_publish_page(self) -> None: def test_publish_page(self) -> None:
expected_topic = u"WordPress Page" expected_topic = u"WordPress Page"
expected_message = u"New page published.\n" + "[New Blog Page](http://example.com\n)" expected_message = u"New page published:\n* [New Blog Page](http://example.com\n)"
self.send_and_test_stream_message('publish_page', expected_topic, expected_message, self.send_and_test_stream_message('publish_page', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded") content_type="application/x-www-form-urlencoded")
@ -44,7 +44,7 @@ class WordPressHookTests(WebhookTestCase):
def test_user_register(self) -> None: def test_user_register(self) -> None:
expected_topic = u"New Blog Users" expected_topic = u"New Blog Users"
expected_message = u"New blog user registered.\nName: test_user\nemail: test_user@example.com" expected_message = u"New blog user registered:\n* **Name**: test_user\n* **Email**: test_user@example.com"
self.send_and_test_stream_message('user_register', expected_topic, expected_message, self.send_and_test_stream_message('user_register', expected_topic, expected_message,
content_type="application/x-www-form-urlencoded") content_type="application/x-www-form-urlencoded")

View File

@ -8,8 +8,15 @@ from zerver.lib.response import json_error, json_success
from zerver.lib.webhooks.common import check_send_webhook_message from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
PUBLISH_POST_OR_PAGE_TEMPLATE = 'New {type} published.\n[{title}]({url})' PUBLISH_POST_OR_PAGE_TEMPLATE = """
USER_REGISTER_TEMPLATE = 'New blog user registered.\nName: {name}\nemail: {email}' New {type} published:
* [{title}]({url})
""".strip()
USER_REGISTER_TEMPLATE = """
New blog user registered:
* **Name**: {name}
* **Email**: {email}
""".strip()
WP_LOGIN_TEMPLATE = 'User {name} logged in.' WP_LOGIN_TEMPLATE = 'User {name} logged in.'
@api_key_only_webhook_view("Wordpress", notify_bot_owner_on_invalid_json=False) @api_key_only_webhook_view("Wordpress", notify_bot_owner_on_invalid_json=False)