mirror of
https://github.com/zulip/zulip.git
synced 2026-06-24 21:08:25 +08:00
This reduces query counts in some cases, since we no longer need to look up the user again. In particular, it reduces some noise when we count queries for O(N)-related tests. The query count is usually reduced by 2 per API call. We no longer need to look up Realm and UserProfile. In most cases we are saving these lookups for the whole tests, since we usually already have the `user` objects for other reasons. In a few places we are simply moving where that query happens within the test. In some places I shorten names like `test_user` or `user_profile` to just be `user`.
58 lines
2.5 KiB
Python
58 lines
2.5 KiB
Python
# -*- coding: utf-8 -*-
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
# Tests for the Desk.com webhook integration.
|
|
#
|
|
# The stream name must be provided in the url-encoded test fixture data,
|
|
# and must match STREAM_NAME set here.
|
|
#
|
|
# Example:
|
|
#
|
|
# stream=deskdotcom&topic=static%20text%20notification&data=This%20is%20a%20custom%20action.
|
|
#
|
|
|
|
class DeskDotComHookTests(WebhookTestCase):
|
|
STREAM_NAME = 'deskdotcom'
|
|
URL_TEMPLATE = "/api/v1/external/deskdotcom?stream={stream}"
|
|
FIXTURE_DIR_NAME = 'deskdotcom'
|
|
|
|
def test_static_text_message(self) -> None:
|
|
|
|
expected_topic = u"static text notification"
|
|
expected_message = u"This is a custom action."
|
|
|
|
self.api_stream_message(self.test_user, 'static_text', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_case_updated_message(self) -> None:
|
|
expected_topic = u"case updated notification"
|
|
expected_message = (u"Case 2 updated. "
|
|
u"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
|
u"I have a question</a>")
|
|
|
|
self.api_stream_message(self.test_user, 'case_updated', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_unicode_text_italian(self) -> None:
|
|
|
|
expected_topic = u"case updated notification"
|
|
expected_message = (u"Case 2 updated. "
|
|
u"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
|
u"Il mio hovercraft è pieno di anguille.</a>")
|
|
|
|
self.api_stream_message(self.test_user, 'unicode_text_italian', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def test_unicode_text_japanese(self) -> None:
|
|
|
|
expected_topic = u"case updated notification"
|
|
expected_message = (u"Case 2 updated. "
|
|
u"Link: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
|
|
u"私のホバークラフトは鰻でいっぱいです</a>")
|
|
|
|
self.api_stream_message(self.test_user, 'unicode_text_japanese', expected_topic, expected_message,
|
|
content_type="application/x-www-form-urlencoded")
|
|
|
|
def get_body(self, fixture_name: str) -> str:
|
|
return self.webhook_fixture_data("deskdotcom", fixture_name, file_type="txt")
|