Skip to content

armgit / zulip

Public Imported from GitHub
0

Zulip server and web application. Open-source team chat that helps teams stay productive and focused.

zendesk tests: Fix anti-patterns.

Steve Howellfbef6e3c03b1
diff --git a/zerver/webhooks/zendesk/tests.py b/zerver/webhooks/zendesk/tests.py
index ece248c8b52..571a9916283 100644
--- a/zerver/webhooks/zendesk/tests.py
+++ b/zerver/webhooks/zendesk/tests.py
@@ -1,4 +1,4 @@
-from typing import Any, Dict, Optional
+from typing import Any, Dict
from zerver.lib.test_classes import WebhookTestCase
@@ -7,15 +7,6 @@ class ZenDeskHookTests(WebhookTestCase):
STREAM_NAME = 'zendesk'
URL_TEMPLATE = "/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,
@@ -24,23 +15,38 @@ class ZenDeskHookTests(WebhookTestCase):
'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 do_test(self, expected_topic: str, expected_message: str) -> None:
+ self.api_stream_message(
+ self.test_user,
+ "",
+ expected_topic,
+ expected_message,
+ content_type=None,
+ )
- def test_subject(self) -> None:
+ def test_short_topic(self) -> None:
self.TICKET_ID = 4
self.TICKET_TITLE = "Test ticket"
- self.do_test(expected_topic='#4: Test ticket')
+ self.MESSAGE = "some message"
+ self.do_test(
+ expected_topic='#4: Test ticket',
+ expected_message="some message",
+ )
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')
+ self.TICKET_TITLE = "Test ticket" + "!" * 80
+ self.MESSAGE = "some message"
+ self.do_test(
+ expected_topic="#4: Test ticket" + "!" * 42 + "...",
+ expected_message="some message",
+ )
+
+ def test_long_content(self) -> None:
+ self.TICKET_ID = 5
+ self.TICKET_TITLE = "Some ticket"
+ self.MESSAGE = "New comment:\n> It is better\n* here"
+ self.do_test(
+ expected_topic="#5: Some ticket",
+ expected_message="New comment:\n> It is better\n* here",
+ )