Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks: Detect view function with default naming convention.
PIG208987f859681cc
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex 087178b109e..620f42935d0 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -1403,15 +1403,20 @@ class WebhookTestCase(ZulipTestCase):super().setUp()self.url = self.build_webhook_url()- if self.WEBHOOK_DIR_NAME is not None and self.VIEW_FUNCTION_NAME is not None:+ if self.WEBHOOK_DIR_NAME is not None:# If VIEW_FUNCTION_NAME is explicitly specified and# WEBHOOK_DIR_NAME is not None, an exception will be# raised when a test triggers events that are not# explicitly specified via the event_types parameter to# the @webhook_view decorator.- function = import_string(- f"zerver.webhooks.{self.WEBHOOK_DIR_NAME}.view.{self.VIEW_FUNCTION_NAME}"- )+ if self.VIEW_FUNCTION_NAME is None:+ function = import_string(+ f"zerver.webhooks.{self.WEBHOOK_DIR_NAME}.view.api_{self.WEBHOOK_DIR_NAME}_webhook"+ )+ else:+ function = import_string(+ f"zerver.webhooks.{self.WEBHOOK_DIR_NAME}.view.{self.VIEW_FUNCTION_NAME}"+ )all_event_types = Noneif hasattr(function, "_all_event_types"):diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.pyindex 69ecddb9499..6b8af8a08f5 100644--- a/zerver/webhooks/github/tests.py+++ b/zerver/webhooks/github/tests.py@@ -18,7 +18,6 @@ class GitHubWebhookTest(WebhookTestCase):STREAM_NAME = "github"URL_TEMPLATE = "/api/v1/external/github?stream={stream}&api_key={api_key}"WEBHOOK_DIR_NAME = "github"- VIEW_FUNCTION_NAME = "api_github_webhook"def test_ping_event(self) -> None:expected_message = "GitHub webhook has been successfully configured by TomaszKolek."diff --git a/zerver/webhooks/ifttt/tests.py b/zerver/webhooks/ifttt/tests.pyindex 5e9ee9b9aae..a28963ad8e3 100644--- a/zerver/webhooks/ifttt/tests.py+++ b/zerver/webhooks/ifttt/tests.py@@ -5,6 +5,7 @@ class IFTTTHookTests(WebhookTestCase):STREAM_NAME = "ifttt"URL_TEMPLATE = "/api/v1/external/ifttt?stream={stream}&api_key={api_key}"WEBHOOK_DIR_NAME = "ifttt"+ VIEW_FUNCTION_NAME = "api_iftt_app_webhook"def test_ifttt_when_subject_and_body_are_correct(self) -> None:expected_topic = "Email sent from [email protected]"diff --git a/zerver/webhooks/travis/tests.py b/zerver/webhooks/travis/tests.pyindex 7ff58f9a6c1..a288408670a 100644--- a/zerver/webhooks/travis/tests.py+++ b/zerver/webhooks/travis/tests.py@@ -13,7 +13,6 @@ Author: josh_mandelBuild status: Passed :thumbs_up:Details: [changes](https://github.com/hl7-fhir/fhir-svn/compare/6dccb98bcfd9...6c457d366a31), [build log](https://travis-ci.org/hl7-fhir/fhir-svn/builds/92495257)""".strip()- VIEW_FUNCTION_NAME = "api_travis_webhook"def test_travis_message(self) -> None:"""diff --git a/zerver/webhooks/yo/tests.py b/zerver/webhooks/yo/tests.pyindex 1721f2680e8..52a734d055f 100644--- a/zerver/webhooks/yo/tests.py+++ b/zerver/webhooks/yo/tests.py@@ -7,6 +7,7 @@ class YoHookTests(WebhookTestCase):STREAM_NAME = "yo"URL_TEMPLATE = "/api/v1/external/yo?api_key={api_key}"WEBHOOK_DIR_NAME = "yo"+ VIEW_FUNCTION_NAME = "api_yo_app_webhook"def test_yo_message(self) -> None:"""