Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhook tests: Introduce get_payload.
Steve Howell7fbe08f515b4
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex e7b46783db9..6969d8ae7f0 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -1055,7 +1055,7 @@ class WebhookTestCase(ZulipTestCase):assert self.STREAM_NAME is not Noneself.subscribe(self.test_user, self.STREAM_NAME)- payload = self.get_body(fixture_name)+ payload = self.get_payload(fixture_name)if content_type is not None:kwargs['content_type'] = content_typeif self.FIXTURE_DIR_NAME is not None:@@ -1102,7 +1102,7 @@ class WebhookTestCase(ZulipTestCase):Most webhooks send to streams, and you will want to look atcheck_webhook."""- payload = self.get_body(fixture_name)+ payload = self.get_payload(fixture_name)kwargs['content_type'] = content_typeif self.FIXTURE_DIR_NAME is not None:@@ -1145,9 +1145,12 @@ class WebhookTestCase(ZulipTestCase):return url[:-1] if has_arguments else url- def get_body(self, fixture_name: str) -> Union[str, Dict[str, str]]:- """Can be implemented either as returning a dictionary containing the- post parameters or as string containing the body of the request."""+ def get_payload(self, fixture_name: str) -> Union[str, Dict[str, str]]:+ """+ Generally webhooks that override this should return dicts."""+ return self.get_body(fixture_name)++ def get_body(self, fixture_name: str) -> str:assert self.FIXTURE_DIR_NAME is not Nonereturn orjson.dumps(orjson.loads(self.webhook_fixture_data(self.FIXTURE_DIR_NAME, fixture_name))).decode()diff --git a/zerver/webhooks/beanstalk/tests.py b/zerver/webhooks/beanstalk/tests.pyindex 6ba55f817a2..d080308b389 100644--- a/zerver/webhooks/beanstalk/tests.py+++ b/zerver/webhooks/beanstalk/tests.py@@ -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)}diff --git a/zerver/webhooks/hellosign/tests.py b/zerver/webhooks/hellosign/tests.pyindex 547b5258915..5cbc3eb30bb 100644--- a/zerver/webhooks/hellosign/tests.py+++ b/zerver/webhooks/hellosign/tests.py@@ -45,5 +45,5 @@ class HelloSignHookTests(WebhookTestCase):topic=expected_topic,)- def get_body(self, fixture_name: str) -> Dict[str, str]:+ def get_payload(self, fixture_name: str) -> Dict[str, str]:return {"json": self.webhook_fixture_data("hellosign", fixture_name, file_type="json")}diff --git a/zerver/webhooks/transifex/tests.py b/zerver/webhooks/transifex/tests.pyindex 4877997af4f..96f0bcda440 100644--- a/zerver/webhooks/transifex/tests.py+++ b/zerver/webhooks/transifex/tests.py@@ -1,4 +1,4 @@-from typing import Any, Dict+from typing import Dictfrom zerver.lib.test_classes import WebhookTestCase@@ -39,5 +39,5 @@ class TransifexHookTests(WebhookTestCase):)self.check_webhook("", expected_topic, expected_message)- def get_body(self, fixture_name: str) -> Dict[str, Any]:+ def get_payload(self, fixture_name: str) -> Dict[str, str]:return {}diff --git a/zerver/webhooks/yo/tests.py b/zerver/webhooks/yo/tests.pyindex 94da2892bda..3fcebf5c78f 100644--- a/zerver/webhooks/yo/tests.py+++ b/zerver/webhooks/yo/tests.py@@ -1,4 +1,4 @@-from typing import Any, Dict+from typing import Dictfrom zerver.lib.test_classes import WebhookTestCase@@ -22,5 +22,5 @@ class YoHookTests(WebhookTestCase):self.send_and_test_private_message('', expected_message=expected_message,content_type="application/x-www-form-urlencoded")- def get_body(self, fixture_name: str) -> Dict[str, Any]:+ def get_payload(self, fixture_name: str) -> Dict[str, str]:return {}diff --git a/zerver/webhooks/zendesk/tests.py b/zerver/webhooks/zendesk/tests.pyindex 571a9916283..c952498fc88 100644--- a/zerver/webhooks/zendesk/tests.py+++ b/zerver/webhooks/zendesk/tests.py@@ -1,4 +1,4 @@-from typing import Any, Dict+from typing import Dictfrom 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,}