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.
This commit is contained in:
Steve Howell
2020-08-20 15:03:43 +00:00
committed by Tim Abbott
parent f7e4cc28eb
commit 7fbe08f515
6 changed files with 21 additions and 18 deletions

View File

@@ -1,4 +1,4 @@
from typing import Any, Dict
from typing import Dict
from zerver.lib.test_classes import WebhookTestCase
@@ -7,10 +7,10 @@ class ZenDeskHookTests(WebhookTestCase):
STREAM_NAME = 'zendesk'
URL_TEMPLATE = "/api/v1/external/zendesk?stream={stream}"
def get_body(self, fixture_name: str) -> Dict[str, Any]:
def get_payload(self, fixture_name: str) -> Dict[str, str]:
return {
'ticket_title': self.TICKET_TITLE,
'ticket_id': self.TICKET_ID,
'ticket_id': str(self.TICKET_ID),
'message': self.MESSAGE,
'stream': self.STREAM_NAME,
}