From 44038fc431be4d9dbd83f12797988a7eb98bbc65 Mon Sep 17 00:00:00 2001 From: Eeshan Garg Date: Thu, 9 May 2019 13:16:25 -0230 Subject: [PATCH] webhooks/raygun: Raise exception for unsupported event types. --- .../fixtures/no_activity_eventType_type.json | 5 ---- .../raygun/fixtures/no_event_type.json | 5 ---- .../no_notification_eventType_type.json | 5 ---- zerver/webhooks/raygun/tests.py | 30 ------------------- zerver/webhooks/raygun/view.py | 7 +++-- 5 files changed, 4 insertions(+), 48 deletions(-) delete mode 100644 zerver/webhooks/raygun/fixtures/no_activity_eventType_type.json delete mode 100644 zerver/webhooks/raygun/fixtures/no_event_type.json delete mode 100644 zerver/webhooks/raygun/fixtures/no_notification_eventType_type.json diff --git a/zerver/webhooks/raygun/fixtures/no_activity_eventType_type.json b/zerver/webhooks/raygun/fixtures/no_activity_eventType_type.json deleted file mode 100644 index 93b0029a8e..0000000000 --- a/zerver/webhooks/raygun/fixtures/no_activity_eventType_type.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "event":"error_activity", - "eventType":"UnimplementedFeature" -} - diff --git a/zerver/webhooks/raygun/fixtures/no_event_type.json b/zerver/webhooks/raygun/fixtures/no_event_type.json deleted file mode 100644 index 0ea811dd39..0000000000 --- a/zerver/webhooks/raygun/fixtures/no_event_type.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "event":"new_event_type", - "eventType":"something_new" -} - diff --git a/zerver/webhooks/raygun/fixtures/no_notification_eventType_type.json b/zerver/webhooks/raygun/fixtures/no_notification_eventType_type.json deleted file mode 100644 index c0f5910e1b..0000000000 --- a/zerver/webhooks/raygun/fixtures/no_notification_eventType_type.json +++ /dev/null @@ -1,5 +0,0 @@ -{ - "event":"error_notification", - "eventType":"UnimplementedFeature" -} - diff --git a/zerver/webhooks/raygun/tests.py b/zerver/webhooks/raygun/tests.py index 75b465d4af..20a968aa95 100644 --- a/zerver/webhooks/raygun/tests.py +++ b/zerver/webhooks/raygun/tests.py @@ -132,35 +132,5 @@ class RaygunHookTests(WebhookTestCase): content_type= "application/x-www-form-urlencoded") - def test_no_event_type_message(self) -> None: - expected_topic = u"test" - expected_message = u"Unsupported event type: new_event_type" - - self.send_and_test_stream_message('no_event_type', - expected_topic, - expected_message, - content_type= - "application/x-www-form-urlencoded") - - def test_unimplemented_notification_feature(self) -> None: - expected_topic = u"test" - expected_message = u"Unsupported event_type type: UnimplementedFeature" - - self.send_and_test_stream_message('no_notification_eventType_type', - expected_topic, - expected_message, - content_type= - "application/x-www-form-urlencoded") - - def test_unimplemented_activity_feature(self) -> None: - expected_topic = u"test" - expected_message = u"Unsupported event_type type: UnimplementedFeature" - - self.send_and_test_stream_message('no_activity_eventType_type', - expected_topic, - expected_message, - content_type= - "application/x-www-form-urlencoded") - def get_body(self, fixture_name: str) -> str: return self.webhook_fixture_data("raygun", fixture_name, file_type="json") diff --git a/zerver/webhooks/raygun/view.py b/zerver/webhooks/raygun/view.py index 3b04f7d6d4..04676c36c2 100644 --- a/zerver/webhooks/raygun/view.py +++ b/zerver/webhooks/raygun/view.py @@ -5,7 +5,8 @@ from django.http import HttpRequest, HttpResponse from zerver.decorator import api_key_only_webhook_view from zerver.lib.request import REQ, has_request_variables from zerver.lib.response import json_success -from zerver.lib.webhooks.common import check_send_webhook_message +from zerver.lib.webhooks.common import check_send_webhook_message, \ + UnexpectedWebhookEventType from zerver.models import UserProfile import time @@ -31,7 +32,7 @@ def api_raygun_webhook(request: HttpRequest, user_profile: UserProfile, elif event == 'error_activity': message = compose_activity_message(payload) else: - message = "Unsupported event type: {}".format(event) + raise UnexpectedWebhookEventType('Raygun', event) topic = 'test' @@ -223,7 +224,7 @@ def compose_notification_message(payload: Dict[str, Any]) -> str: elif "FollowUp" in event_type: return notification_message_follow_up(payload) else: - return "Unsupported event_type type: {}".format(event_type) + raise UnexpectedWebhookEventType('Raygun', event_type) def activity_message(payload: Dict[str, Any]) -> str: