Files
zulip/zerver/webhooks/transifex/tests.py
Steve Howell 7fbe08f515 webhook tests: Introduce get_payload.
We introduce get_payload for the relatively
exceptional cases where webhooks return payloads
as dicts.

Having a simple "str" type for get_body will
allow us to extract test helpers that use
payloads from get_body() without the ugly
`Union[str, Dict[str, str]]` annotations.

I also tightened up annotations in a few places
where we now call get_payload (using Dict[str, str]
instead of Dict[str, Any]).

In the zendesk test I explicitly stringify
one of the parameters to satisfy mypy.
2020-08-24 12:34:46 -07:00

44 lines
1.5 KiB
Python

from typing import Dict
from zerver.lib.test_classes import WebhookTestCase
class TransifexHookTests(WebhookTestCase):
STREAM_NAME = 'transifex'
URL_TEMPLATE = "/api/v1/external/transifex?stream={stream}&api_key={api_key}"
URL_REVIEWED_METHOD_TEMPLATE = "reviewed=100"
URL_TRANSLATED_METHOD_TEMPLATE = "translated=100"
FIXTURE_DIR_NAME = 'transifex'
PROJECT = 'project-title'
LANGUAGE = 'en'
RESOURCE = 'file'
REVIEWED = True
def test_transifex_reviewed_message(self) -> None:
self.REVIEWED = True
expected_topic = f"{self.PROJECT} in {self.LANGUAGE}"
expected_message = f"Resource {self.RESOURCE} fully reviewed."
self.url = self.build_webhook_url(
self.URL_REVIEWED_METHOD_TEMPLATE,
project=self.PROJECT,
language=self.LANGUAGE,
resource=self.RESOURCE,
)
self.check_webhook("", expected_topic, expected_message)
def test_transifex_translated_message(self) -> None:
self.REVIEWED = False
expected_topic = f"{self.PROJECT} in {self.LANGUAGE}"
expected_message = f"Resource {self.RESOURCE} fully translated."
self.url = self.build_webhook_url(
self.URL_TRANSLATED_METHOD_TEMPLATE,
project=self.PROJECT,
language=self.LANGUAGE,
resource=self.RESOURCE,
)
self.check_webhook("", expected_topic, expected_message)
def get_payload(self, fixture_name: str) -> Dict[str, str]:
return {}