Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
test_classes: Require webhooks with event types to pass them.
Niloth P5c01d5c73a26
diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex e22f9baa790..6b31bb923a1 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -2538,6 +2538,10 @@ class WebhookTestCase(ZulipTestCase):* We enforce that all event types are declared in the @webhook_viewdecorator. This is important for ensuring we document all fullysupported event types.++ * For webhooks that declare event types, we enforce that every+ message is sent with its event type, so that the only_events and+ exclude_events parameters can filter it."""TEST_USER_EMAIL = "[email protected]"@@ -2573,6 +2577,15 @@ class WebhookTestCase(ZulipTestCase):return # nocoveragedef side_effect(*args: Any, **kwargs: Any) -> int | None:+ if len(args) < 5 and "complete_event_type" not in kwargs: # nocoverage+ raise Exception(+ """+Error: This test triggered a message without passing complete_event_type to+check_send_webhook_message. Since this webhook registers its event types via+@webhook_view(..., all_event_types=[...]), the event type must be specified. If this message+should be sent regardless of the event filters, pass complete_event_type=None.+""".strip()+ )complete_event_type = (kwargs.get("complete_event_type")if len(args) < 5@@ -2586,7 +2599,7 @@ class WebhookTestCase(ZulipTestCase):raise Exception(f"""Error: This test triggered a message using the event "{complete_event_type}", which was not properly-registered via the @webhook_view(..., event_types=[...]). These registrations are important for Zulip+registered via the @webhook_view(..., all_event_types=[...]). These registrations are important for Zulipself-documenting the supported event types for this integration.You can fix this by adding "{complete_event_type}" to ALL_EVENT_TYPES for this webhook.diff --git a/zerver/webhooks/newrelic/view.py b/zerver/webhooks/newrelic/view.pyindex 7e12db0b77b..ead6f51c6fb 100644--- a/zerver/webhooks/newrelic/view.py+++ b/zerver/webhooks/newrelic/view.py@@ -168,7 +168,7 @@ def api_newrelic_webhook(formatted_missing_fields=formatted_missing_fields,)topic = "New Relic incident alerts"- check_send_webhook_message(request, user_profile, topic, content)+ check_send_webhook_message(request, user_profile, topic, content, complete_event_type=None)return json_success(request)message_context = parse_payload(payload)