2020-07-01 04:19:54 +02:00
|
|
|
from zerver.lib.test_classes import WebhookTestCase, ZulipTestCase
|
2016-11-23 20:15:23 +01:00
|
|
|
from zerver.webhooks.appfollow.view import convert_markdown
|
2016-12-13 15:50:24 +01:00
|
|
|
|
2020-01-14 22:06:24 +01:00
|
|
|
|
2016-12-13 15:50:24 +01:00
|
|
|
class AppFollowHookTests(WebhookTestCase):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "appfollow"
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/appfollow?stream={stream}&api_key={api_key}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "appfollow"
|
2016-12-13 15:50:24 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_sample(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "Webhook integration was successful."
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = """Webhook integration was successful.
|
2016-12-13 15:50:24 +01:00
|
|
|
Test User / Acme (Google Play)"""
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"sample",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2016-12-13 15:50:24 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_reviews(self) -> None:
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "Acme - Group chat"
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = """Acme - Group chat
|
2016-12-13 15:50:24 +01:00
|
|
|
App Store, Acme Technologies, Inc.
|
|
|
|
★★★★★ United States
|
|
|
|
**Great for Information Management**
|
|
|
|
Acme enables me to manage the flow of information quite well. I only wish I could create and edit my Acme Post files in the iOS app.
|
|
|
|
*by* **Mr RESOLUTIONARY** *for v3.9*
|
|
|
|
[Permalink](http://appfollow.io/permalink) · [Add tag](http://watch.appfollow.io/add_tag)"""
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"review",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2016-12-13 15:50:24 +01:00
|
|
|
|
2017-11-21 19:33:34 +01:00
|
|
|
def test_reviews_with_topic(self) -> None:
|
|
|
|
# This temporary patch of URL_TEMPLATE is code smell but required due to the way
|
|
|
|
# WebhookTestCase is built.
|
|
|
|
original_url_template = self.URL_TEMPLATE
|
|
|
|
self.URL_TEMPLATE = original_url_template + "&topic=foo"
|
|
|
|
self.url = self.build_webhook_url()
|
2018-11-09 20:33:58 +01:00
|
|
|
expected_topic = "foo"
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = """Acme - Group chat
|
2017-11-21 19:33:34 +01:00
|
|
|
App Store, Acme Technologies, Inc.
|
|
|
|
★★★★★ United States
|
|
|
|
**Great for Information Management**
|
|
|
|
Acme enables me to manage the flow of information quite well. I only wish I could create and edit my Acme Post files in the iOS app.
|
|
|
|
*by* **Mr RESOLUTIONARY** *for v3.9*
|
|
|
|
[Permalink](http://appfollow.io/permalink) · [Add tag](http://watch.appfollow.io/add_tag)"""
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"review",
|
|
|
|
expected_topic,
|
|
|
|
expected_message,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
2017-11-21 19:33:34 +01:00
|
|
|
self.URL_TEMPLATE = original_url_template
|
|
|
|
|
2021-02-12 08:19:30 +01:00
|
|
|
|
2020-07-01 04:19:54 +02:00
|
|
|
class ConvertMarkdownTest(ZulipTestCase):
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_convert_bold(self) -> None:
|
2016-12-16 02:01:34 +01:00
|
|
|
self.assertEqual(convert_markdown("*test message*"), "**test message**")
|
2016-12-13 15:50:24 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_convert_italics(self) -> None:
|
2016-12-16 02:01:34 +01:00
|
|
|
self.assertEqual(convert_markdown("_test message_"), "*test message*")
|
|
|
|
self.assertEqual(convert_markdown("_ spaced message _"), " *spaced message* ")
|
2016-12-13 15:50:24 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_convert_strikethrough(self) -> None:
|
2016-12-16 02:01:34 +01:00
|
|
|
self.assertEqual(convert_markdown("~test message~"), "~~test message~~")
|