mirror of
https://github.com/zulip/zulip.git
synced 2025-11-02 21:13:36 +00:00
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:
@@ -90,7 +90,7 @@ class BeanstalkHookTests(WebhookTestCase):
|
||||
@patch('zerver.webhooks.beanstalk.view.check_send_webhook_message')
|
||||
def test_git_single_filtered_by_branches_ignore(self, check_send_webhook_message_mock: MagicMock) -> None:
|
||||
self.url = self.build_webhook_url(branches='changes,development')
|
||||
payload = self.get_body('git_singlecommit')
|
||||
payload = self.get_payload('git_singlecommit')
|
||||
result = self.api_post(self.test_user, self.url, payload)
|
||||
self.assertFalse(check_send_webhook_message_mock.called)
|
||||
self.assert_json_success(result)
|
||||
@@ -99,7 +99,7 @@ class BeanstalkHookTests(WebhookTestCase):
|
||||
def test_git_multiple_committers_filtered_by_branches_ignore(
|
||||
self, check_send_webhook_message_mock: MagicMock) -> None:
|
||||
self.url = self.build_webhook_url(branches='changes,development')
|
||||
payload = self.get_body('git_multiple_committers')
|
||||
payload = self.get_payload('git_multiple_committers')
|
||||
result = self.api_post(self.test_user, self.url, payload)
|
||||
self.assertFalse(check_send_webhook_message_mock.called)
|
||||
self.assert_json_success(result)
|
||||
@@ -108,7 +108,7 @@ class BeanstalkHookTests(WebhookTestCase):
|
||||
def test_git_multiple_filtered_by_branches_ignore(
|
||||
self, check_send_webhook_message_mock: MagicMock) -> None:
|
||||
self.url = self.build_webhook_url(branches='changes,development')
|
||||
payload = self.get_body('git_multiple')
|
||||
payload = self.get_payload('git_multiple')
|
||||
result = self.api_post(self.test_user, self.url, payload)
|
||||
self.assertFalse(check_send_webhook_message_mock.called)
|
||||
self.assert_json_success(result)
|
||||
@@ -117,7 +117,7 @@ class BeanstalkHookTests(WebhookTestCase):
|
||||
def test_git_more_than_limit_filtered_by_branches_ignore(
|
||||
self, check_send_webhook_message_mock: MagicMock) -> None:
|
||||
self.url = self.build_webhook_url(branches='changes,development')
|
||||
payload = self.get_body('git_morethanlimitcommits')
|
||||
payload = self.get_payload('git_morethanlimitcommits')
|
||||
result = self.api_post(self.test_user, self.url, payload)
|
||||
self.assertFalse(check_send_webhook_message_mock.called)
|
||||
self.assert_json_success(result)
|
||||
@@ -138,5 +138,5 @@ class BeanstalkHookTests(WebhookTestCase):
|
||||
self.api_stream_message(self.test_user, 'svn_changefile', expected_topic, expected_message,
|
||||
content_type=None)
|
||||
|
||||
def get_body(self, fixture_name: str) -> Dict[str, str]:
|
||||
def get_payload(self, fixture_name: str) -> Dict[str, str]:
|
||||
return {'payload': self.webhook_fixture_data('beanstalk', fixture_name)}
|
||||
|
||||
Reference in New Issue
Block a user