Files
zulip/zerver/webhooks/zendesk/tests.py
Steve Howell c235333041 test performance: Pass in users to api_* helpers.
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`.
2020-03-11 14:18:29 -07:00

48 lines
1.6 KiB
Python

# -*- coding: utf-8 -*-
from typing import Any, Dict, Optional
from zerver.lib.test_classes import WebhookTestCase
class ZenDeskHookTests(WebhookTestCase):
STREAM_NAME = 'zendesk'
URL_TEMPLATE = u"/api/v1/external/zendesk?stream={stream}"
DEFAULT_TICKET_TITLE = 'User can\'t login'
TICKET_TITLE = DEFAULT_TICKET_TITLE
DEFAULT_TICKET_ID = 54
TICKET_ID = DEFAULT_TICKET_ID
DEFAULT_MESSAGE = 'Message'
MESSAGE = DEFAULT_MESSAGE
def get_body(self, fixture_name: str) -> Dict[str, Any]:
return {
'ticket_title': self.TICKET_TITLE,
'ticket_id': self.TICKET_ID,
'message': self.MESSAGE,
'stream': self.STREAM_NAME,
}
def do_test(self, expected_topic: Optional[str]=None, expected_message: Optional[str]=None) -> None:
self.api_stream_message(self.test_user, "", expected_topic, expected_message,
content_type=None)
self.TICKET_TITLE = self.DEFAULT_TICKET_TITLE
self.TICKET_ID = self.DEFAULT_TICKET_ID
self.MESSAGE = self.DEFAULT_MESSAGE
def test_subject(self) -> None:
self.TICKET_ID = 4
self.TICKET_TITLE = "Test ticket"
self.do_test(expected_topic='#4: Test ticket')
def test_long_subject(self) -> None:
self.TICKET_ID = 4
self.TICKET_TITLE = "Test ticket" + '!' * 80
self.do_test(expected_topic='#4: Test ticket' + '!' * 42 + '...')
def test_content(self) -> None:
self.MESSAGE = 'New comment:\n> It is better\n* here'
self.do_test(expected_message='New comment:\n> It is better\n* here')