webhooks/raygun: Raise exception for unsupported event types.

This commit is contained in:
Eeshan Garg 2019-05-09 13:16:25 -02:30 committed by Tim Abbott
parent 5a1f70f6e8
commit 44038fc431
5 changed files with 4 additions and 48 deletions

View File

@ -1,5 +0,0 @@
{
"event":"error_activity",
"eventType":"UnimplementedFeature"
}

View File

@ -1,5 +0,0 @@
{
"event":"new_event_type",
"eventType":"something_new"
}

View File

@ -1,5 +0,0 @@
{
"event":"error_notification",
"eventType":"UnimplementedFeature"
}

View File

@ -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")

View File

@ -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: