mirror of https://github.com/zulip/zulip.git
Make webhooks as separate modules with view and tests.
Create python packege for every webhook with view.py and tests.py
This commit is contained in:
parent
fc965eb5f6
commit
7de45951e2
|
@ -128,6 +128,7 @@ if __name__ == "__main__":
|
|||
|
||||
if len(args) == 0:
|
||||
suites = ["zerver.tests",
|
||||
"zerver.webhooks",
|
||||
"analytics.tests"]
|
||||
else:
|
||||
suites = args
|
||||
|
|
|
@ -48,7 +48,7 @@ class EmailIntegration(Integration):
|
|||
return settings.EMAIL_GATEWAY_BOT != ""
|
||||
|
||||
class WebhookIntegration(Integration):
|
||||
DEFAULT_FUNCTION_PATH = 'zerver.views.webhooks.{name}.api_{name}_webhook'
|
||||
DEFAULT_FUNCTION_PATH = 'zerver.webhooks.{name}.view.api_{name}_webhook'
|
||||
DEFAULT_URL = 'api/v1/external/{name}'
|
||||
DEFAULT_CLIENT_NAME = 'Zulip{name}Webhook'
|
||||
|
||||
|
@ -114,7 +114,7 @@ WEBHOOK_INTEGRATIONS = [
|
|||
WebhookIntegration('freshdesk'),
|
||||
GithubIntegration(
|
||||
'github',
|
||||
function='zerver.views.webhooks.github.api_github_landing',
|
||||
function='zerver.webhooks.github.view.api_github_landing',
|
||||
display_name='GitHub',
|
||||
secondary_line_text='(deprecated)'
|
||||
),
|
||||
|
@ -123,14 +123,14 @@ WEBHOOK_INTEGRATIONS = [
|
|||
display_name='GitHub',
|
||||
logo='static/images/integrations/logos/github.png',
|
||||
secondary_line_text='(webhook)',
|
||||
function='zerver.views.webhooks.github_webhook.api_github_webhook'
|
||||
function='zerver.webhooks.github_webhook.view.api_github_webhook'
|
||||
),
|
||||
WebhookIntegration('gitlab', display_name='GitLab'),
|
||||
WebhookIntegration('gosquared', display_name='GoSquared'),
|
||||
WebhookIntegration('hellosign', display_name='HelloSign'),
|
||||
WebhookIntegration('helloworld', display_name='Hello World'),
|
||||
WebhookIntegration('heroku', display_name='Heroku'),
|
||||
WebhookIntegration('ifttt', function='zerver.views.webhooks.ifttt.api_iftt_app_webhook', display_name='IFTTT'),
|
||||
WebhookIntegration('ifttt', function='zerver.webhooks.ifttt.view.api_iftt_app_webhook', display_name='IFTTT'),
|
||||
WebhookIntegration('jira', secondary_line_text='(hosted or v5.2+)', display_name='JIRA'),
|
||||
WebhookIntegration('librato'),
|
||||
WebhookIntegration('mention', display_name='Mention'),
|
||||
|
@ -152,7 +152,7 @@ WEBHOOK_INTEGRATIONS = [
|
|||
WebhookIntegration('updown'),
|
||||
WebhookIntegration(
|
||||
'yo',
|
||||
function='zerver.views.webhooks.yo.api_yo_app_webhook',
|
||||
function='zerver.webhooks.yo.view.api_yo_app_webhook',
|
||||
logo='static/images/integrations/logos/yo-app.png',
|
||||
display_name='Yo App'
|
||||
),
|
||||
|
|
|
@ -3,7 +3,7 @@ from typing import Text
|
|||
from zerver.lib.test_classes import WebhookTestCase
|
||||
from django.test import TestCase
|
||||
|
||||
from zerver.views.webhooks.appfollow import convert_markdown
|
||||
from zerver.webhooks.appfollow.view import convert_markdown
|
||||
|
||||
class AppFollowHookTests(WebhookTestCase):
|
||||
STREAM_NAME = 'appfollow'
|
|
@ -11,7 +11,7 @@ from zerver.decorator import REQ, has_request_variables, authenticated_rest_api_
|
|||
import base64
|
||||
from functools import wraps
|
||||
|
||||
from .github import build_message_from_gitlog
|
||||
from zerver.webhooks.github.view import build_message_from_gitlog
|
||||
|
||||
from typing import Any, Callable, Dict, TypeVar
|
||||
from zerver.lib.str_utils import force_str, force_bytes
|
|
@ -0,0 +1,50 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from six import text_type
|
||||
from typing import Union
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
|
||||
class BitbucketHookTests(WebhookTestCase):
|
||||
STREAM_NAME = 'bitbucket'
|
||||
URL_TEMPLATE = "/api/v1/external/bitbucket?payload={payload}&stream={stream}"
|
||||
FIXTURE_DIR_NAME = 'bitbucket'
|
||||
EXPECTED_SUBJECT = u"Repository name"
|
||||
EXPECTED_SUBJECT_BRANCH_EVENTS = u"Repository name / master"
|
||||
|
||||
def test_bitbucket_on_push_event(self):
|
||||
# type: () -> None
|
||||
fixture_name = 'push'
|
||||
self.url = self.build_url(fixture_name)
|
||||
commit_info = u'* [25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12): c'
|
||||
expected_message = u"kolaszek pushed to branch master\n\n{}".format(commit_info)
|
||||
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL))
|
||||
|
||||
def test_bitbucket_on_push_commits_above_limit_event(self):
|
||||
# type: () -> None
|
||||
fixture_name = 'push_commits_above_limit'
|
||||
self.url = self.build_url(fixture_name)
|
||||
commit_info = u'* [25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12): c\n'
|
||||
expected_message = u"kolaszek pushed to branch master\n\n{}[and 40 more commit(s)]".format(commit_info * 10)
|
||||
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL))
|
||||
|
||||
def test_bitbucket_on_force_push_event(self):
|
||||
# type: () -> None
|
||||
fixture_name = 'force_push'
|
||||
self.url = self.build_url(fixture_name)
|
||||
expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name)"
|
||||
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT, expected_message, **self.api_auth(self.TEST_USER_EMAIL))
|
||||
|
||||
def get_body(self, fixture_name):
|
||||
# type: (text_type) -> Union[text_type, Dict[str, text_type]]
|
||||
return {}
|
||||
|
||||
def get_payload(self, fixture_name):
|
||||
# type: (text_type) -> Union[text_type, Dict[str, text_type]]
|
||||
return self.fixture_data(self.FIXTURE_DIR_NAME, fixture_name)
|
||||
|
||||
def build_webhook_url(self):
|
||||
# type: () -> text_type
|
||||
return ''
|
||||
|
||||
def build_url(self, fixture_name):
|
||||
# type: (text_type) -> text_type
|
||||
return self.URL_TEMPLATE.format(payload=self.get_payload(fixture_name), stream=self.STREAM_NAME)
|
|
@ -1,6 +1,4 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
from typing import Union, Text
|
||||
from zerver.lib.webhooks.git import COMMITS_LIMIT
|
||||
from zerver.lib.test_classes import WebhookTestCase
|
||||
|
||||
class Bitbucket2HookTests(WebhookTestCase):
|
||||
|
@ -180,49 +178,3 @@ class Bitbucket2HookTests(WebhookTestCase):
|
|||
msg = self.get_last_message()
|
||||
self.do_test_message(msg, 'kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)')
|
||||
self.do_test_subject(msg, self.EXPECTED_SUBJECT)
|
||||
|
||||
class BitbucketHookTests(WebhookTestCase):
|
||||
STREAM_NAME = 'bitbucket'
|
||||
URL_TEMPLATE = "/api/v1/external/bitbucket?payload={payload}&stream={stream}"
|
||||
FIXTURE_DIR_NAME = 'bitbucket'
|
||||
EXPECTED_SUBJECT = u"Repository name"
|
||||
EXPECTED_SUBJECT_BRANCH_EVENTS = u"Repository name / master"
|
||||
|
||||
def test_bitbucket_on_push_event(self):
|
||||
# type: () -> None
|
||||
fixture_name = 'push'
|
||||
self.url = self.build_url(fixture_name)
|
||||
commit_info = u'* [25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12): c'
|
||||
expected_message = u"kolaszek pushed to branch master\n\n{}".format(commit_info)
|
||||
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL))
|
||||
|
||||
def test_bitbucket_on_push_commits_above_limit_event(self):
|
||||
# type: () -> None
|
||||
fixture_name = 'push_commits_above_limit'
|
||||
self.url = self.build_url(fixture_name)
|
||||
commit_info = u'* [25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12): c\n'
|
||||
expected_message = u"kolaszek pushed to branch master\n\n{}[and 40 more commit(s)]".format(commit_info * 10)
|
||||
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL))
|
||||
|
||||
def test_bitbucket_on_force_push_event(self):
|
||||
# type: () -> None
|
||||
fixture_name = 'force_push'
|
||||
self.url = self.build_url(fixture_name)
|
||||
expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name)"
|
||||
self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT, expected_message, **self.api_auth(self.TEST_USER_EMAIL))
|
||||
|
||||
def get_body(self, fixture_name):
|
||||
# type: (Text) -> Union[Text, Dict[str, Text]]
|
||||
return {}
|
||||
|
||||
def get_payload(self, fixture_name):
|
||||
# type: (Text) -> Union[Text, Dict[str, Text]]
|
||||
return self.fixture_data(self.FIXTURE_DIR_NAME, fixture_name)
|
||||
|
||||
def build_webhook_url(self):
|
||||
# type: () -> Text
|
||||
return ''
|
||||
|
||||
def build_url(self, fixture_name):
|
||||
# type: (Text) -> Text
|
||||
return self.URL_TEMPLATE.format(payload=self.get_payload(fixture_name), stream=self.STREAM_NAME)
|
|
@ -1,8 +1,8 @@
|
|||
from __future__ import absolute_import
|
||||
from django.http import HttpRequest, HttpResponse
|
||||
from django.views.decorators.csrf import csrf_exempt
|
||||
from .github_webhook import api_github_webhook
|
||||
from .github import api_github_landing
|
||||
from .github_webhook.view import api_github_webhook
|
||||
from .github.view import api_github_landing
|
||||
|
||||
# Since this dispatcher is an API-style endpoint, it needs to be
|
||||
# explicitly marked as CSRF-exempt
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue