webhooks: Migrate to UnexpectedWebhookEventType.

This improves test coverage for a lot of our webhooks that relied
on ad-hoc methods to handle unexpected event types.

Note that I have deliberately skipped github_legacy, it isn't
advertised and is officially deprecated.

Also, I have refrained from making further changes to Trello, I
believe further improvements to test coverage should be covered
in separate per-webhook commits/PRs.
This commit is contained in:
Eeshan Garg
2018-05-22 12:16:45 -02:30
committed by Tim Abbott
parent 3ed20589f2
commit e0ef831993
15 changed files with 40 additions and 70 deletions

View File

@@ -7,7 +7,8 @@ from django.utils.translation import ugettext as _
from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_error, 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.lib.validator import check_dict
from zerver.models import Stream, UserProfile
@@ -30,7 +31,7 @@ def api_newrelic_webhook(request: HttpRequest, user_profile: UserProfile,
%(changelog)s""" % (deployment)
else:
return json_error(_("Unknown webhook request"))
raise UnexpectedWebhookEventType('New Relic', 'Unknown Event Type')
check_send_webhook_message(request, user_profile, subject, content)
return json_success()