python: Sort webhooks imports with isort.

This commit is contained in:
Tim Abbott
2020-01-14 13:06:24 -08:00
parent 8e7ce7cc79
commit c10cc24ee8
129 changed files with 238 additions and 180 deletions

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class AirbrakeHookTests(WebhookTestCase): class AirbrakeHookTests(WebhookTestCase):
STREAM_NAME = 'airbrake' STREAM_NAME = 'airbrake'
URL_TEMPLATE = u"/api/v1/external/airbrake?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/airbrake?stream={stream}&api_key={api_key}"

View File

@@ -4,9 +4,9 @@ from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
AIRBRAKE_TOPIC_TEMPLATE = '{project_name}' AIRBRAKE_TOPIC_TEMPLATE = '{project_name}'

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class AnsibletowerHookTests(WebhookTestCase): class AnsibletowerHookTests(WebhookTestCase):
STREAM_NAME = 'ansibletower' STREAM_NAME = 'ansibletower'
URL_TEMPLATE = "/api/v1/external/ansibletower?api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/ansibletower?api_key={api_key}&stream={stream}"

View File

@@ -1,14 +1,14 @@
import operator
from typing import Any, Dict, List from typing import Any, Dict, List
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.lib.webhooks.common import check_send_webhook_message from zerver.decorator import REQ, api_key_only_webhook_view, \
has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
import operator
ANSIBLETOWER_DEFAULT_MESSAGE_TEMPLATE = "{friendly_name}: [#{id} {name}]({url}) {status}." ANSIBLETOWER_DEFAULT_MESSAGE_TEMPLATE = "{friendly_name}: [#{id} {name}]({url}) {status}."

View File

@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from django.test import TestCase from django.test import TestCase
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
from zerver.webhooks.appfollow.view import convert_markdown from zerver.webhooks.appfollow.view import convert_markdown
class AppFollowHookTests(WebhookTestCase): class AppFollowHookTests(WebhookTestCase):
STREAM_NAME = 'appfollow' STREAM_NAME = 'appfollow'
URL_TEMPLATE = u"/api/v1/external/appfollow?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/appfollow?stream={stream}&api_key={api_key}"

View File

@@ -10,6 +10,7 @@ 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
from zerver.models import UserProfile from zerver.models import UserProfile
@api_key_only_webhook_view("AppFollow") @api_key_only_webhook_view("AppFollow")
@has_request_variables @has_request_variables
def api_appfollow_webhook(request: HttpRequest, user_profile: UserProfile, def api_appfollow_webhook(request: HttpRequest, user_profile: UserProfile,

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class AppveyorHookTests(WebhookTestCase): class AppveyorHookTests(WebhookTestCase):
STREAM_NAME = 'appveyor' STREAM_NAME = 'appveyor'
URL_TEMPLATE = "/api/v1/external/appveyor?api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/appveyor?api_key={api_key}&stream={stream}"

View File

@@ -2,9 +2,10 @@ from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.lib.webhooks.common import check_send_webhook_message from zerver.decorator import REQ, api_key_only_webhook_view, \
has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
APPVEYOR_TOPIC_TEMPLATE = '{project_name}' APPVEYOR_TOPIC_TEMPLATE = '{project_name}'

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class BasecampHookTests(WebhookTestCase): class BasecampHookTests(WebhookTestCase):
STREAM_NAME = 'basecamp' STREAM_NAME = 'basecamp'
URL_TEMPLATE = u"/api/v1/external/basecamp?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/basecamp?stream={stream}&api_key={api_key}"

View File

@@ -7,8 +7,8 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
UnexpectedWebhookEventType check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
from .support_event import SUPPORT_EVENTS from .support_event import SUPPORT_EVENTS

View File

@@ -6,6 +6,7 @@ from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
from zerver.lib.webhooks.git import COMMITS_LIMIT from zerver.lib.webhooks.git import COMMITS_LIMIT
class BeanstalkHookTests(WebhookTestCase): class BeanstalkHookTests(WebhookTestCase):
STREAM_NAME = 'commits' STREAM_NAME = 'commits'
URL_TEMPLATE = u"/api/v1/external/beanstalk?stream={stream}" URL_TEMPLATE = u"/api/v1/external/beanstalk?stream={stream}"

View File

@@ -1,22 +1,22 @@
# Webhooks for external integrations. # Webhooks for external integrations.
import base64 import base64
from functools import wraps
from typing import Any, Dict, Optional, List, Tuple
import re import re
from functools import wraps
from typing import Any, Dict, List, Optional, Tuple
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import authenticated_rest_api_view from zerver.decorator import authenticated_rest_api_view
from zerver.lib.types import ViewFuncT
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.types import ViewFuncT
from zerver.lib.validator import check_dict
from zerver.lib.webhooks.common import check_send_webhook_message from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \ from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \
get_push_commits_event_message get_push_commits_event_message
from zerver.lib.validator import check_dict
from zerver.models import UserProfile from zerver.models import UserProfile
def build_message_from_gitlog(user_profile: UserProfile, name: str, ref: str, def build_message_from_gitlog(user_profile: UserProfile, name: str, ref: str,
commits: List[Dict[str, str]], before: str, after: str, commits: List[Dict[str, str]], before: str, after: str,
url: str, pusher: str, forced: Optional[str]=None, url: str, pusher: str, forced: Optional[str]=None,

View File

@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from unittest.mock import patch
from typing import Any from typing import Any
from unittest.mock import patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class BeeminderHookTests(WebhookTestCase): class BeeminderHookTests(WebhookTestCase):
STREAM_NAME = 'beeminder' STREAM_NAME = 'beeminder'
URL_TEMPLATE = u"/api/v1/external/beeminder?api_key={api_key}&stream={stream}" URL_TEMPLATE = u"/api/v1/external/beeminder?api_key={api_key}&stream={stream}"

View File

@@ -1,12 +1,14 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from typing import Dict, Any import time
from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success 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
from zerver.models import UserProfile from zerver.models import UserProfile
import time
MESSAGE_TEMPLATE = ("You are going to derail from goal **{goal_name}** in **{time:0.1f} hours**. " MESSAGE_TEMPLATE = ("You are going to derail from goal **{goal_name}** in **{time:0.1f} hours**. "
"You need **{limsum}** to avoid derailing.\n" "You need **{limsum}** to avoid derailing.\n"

View File

@@ -5,6 +5,7 @@ from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class BitbucketHookTests(WebhookTestCase): class BitbucketHookTests(WebhookTestCase):
STREAM_NAME = 'bitbucket' STREAM_NAME = 'bitbucket'
URL_TEMPLATE = "/api/v1/external/bitbucket?stream={stream}" URL_TEMPLATE = "/api/v1/external/bitbucket?stream={stream}"

View File

@@ -11,6 +11,7 @@ from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \
get_push_commits_event_message get_push_commits_event_message
from zerver.models import UserProfile from zerver.models import UserProfile
@authenticated_rest_api_view(webhook_client_name="Bitbucket") @authenticated_rest_api_view(webhook_client_name="Bitbucket")
@has_request_variables @has_request_variables
def api_bitbucket_webhook(request: HttpRequest, user_profile: UserProfile, def api_bitbucket_webhook(request: HttpRequest, user_profile: UserProfile,

View File

@@ -3,6 +3,7 @@ from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class Bitbucket2HookTests(WebhookTestCase): class Bitbucket2HookTests(WebhookTestCase):
STREAM_NAME = 'bitbucket2' STREAM_NAME = 'bitbucket2'
URL_TEMPLATE = "/api/v1/external/bitbucket2?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/bitbucket2?stream={stream}&api_key={api_key}"

View File

@@ -1,23 +1,22 @@
# Webhooks for external integrations. # Webhooks for external integrations.
import re import re
from functools import partial
import string import string
from typing import Any, Dict, List, Optional from functools import partial
from inspect import signature from inspect import signature
from typing import Any, Dict, List, Optional
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
validate_extract_webhook_http_header, UnexpectedWebhookEventType check_send_webhook_message, validate_extract_webhook_http_header
from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \ from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \ TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_commits_comment_action_message, \
get_commits_comment_action_message, get_force_push_commits_event_message, \ get_force_push_commits_event_message, get_issue_event_message, \
get_issue_event_message, get_pull_request_event_message, \ get_pull_request_event_message, get_push_commits_event_message, \
get_push_commits_event_message, get_push_tag_event_message, \ get_push_tag_event_message, get_remove_branch_event_message
get_remove_branch_event_message
from zerver.models import UserProfile from zerver.models import UserProfile
BITBUCKET_TOPIC_TEMPLATE = '{repository_name}' BITBUCKET_TOPIC_TEMPLATE = '{repository_name}'

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class Bitbucket3HookTests(WebhookTestCase): class Bitbucket3HookTests(WebhookTestCase):
STREAM_NAME = "bitbucket3" STREAM_NAME = "bitbucket3"
URL_TEMPLATE = "/api/v1/external/bitbucket3?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/bitbucket3?stream={stream}&api_key={api_key}"

View File

@@ -1,23 +1,23 @@
from inspect import signature
from functools import partial
import string import string
from typing import Any, Dict, Optional, List, Callable from functools import partial
from inspect import signature
from typing import Any, Callable, Dict, List, Optional
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.models import UserProfile
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
get_push_tag_event_message, get_remove_branch_event_message, \ check_send_webhook_message
get_create_branch_event_message, get_commits_comment_action_message, \ from zerver.lib.webhooks.git import CONTENT_MESSAGE_TEMPLATE, \
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_pull_request_event_message, \ TOPIC_WITH_BRANCH_TEMPLATE, TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \
CONTENT_MESSAGE_TEMPLATE get_commits_comment_action_message, get_create_branch_event_message, \
from zerver.lib.webhooks.common import check_send_webhook_message, \ get_pull_request_event_message, get_push_tag_event_message, \
UnexpectedWebhookEventType get_remove_branch_event_message
from zerver.webhooks.bitbucket2.view import BITBUCKET_TOPIC_TEMPLATE, \ from zerver.models import UserProfile
BITBUCKET_FORK_BODY, BITBUCKET_REPO_UPDATED_CHANGED from zerver.webhooks.bitbucket2.view import BITBUCKET_FORK_BODY, \
BITBUCKET_REPO_UPDATED_CHANGED, BITBUCKET_TOPIC_TEMPLATE
BRANCH_UPDATED_MESSAGE_TEMPLATE = "{user_name} pushed to branch {branch_name}. Head is now {head}." BRANCH_UPDATED_MESSAGE_TEMPLATE = "{user_name} pushed to branch {branch_name}. Head is now {head}."
PULL_REQUEST_MARKED_AS_NEEDS_WORK_TEMPLATE = "{user_name} marked [PR #{number}]({url}) as \"needs work\"." PULL_REQUEST_MARKED_AS_NEEDS_WORK_TEMPLATE = "{user_name} marked [PR #{number}]({url}) as \"needs work\"."

View File

@@ -1,5 +1,6 @@
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class BuildbotHookTests(WebhookTestCase): class BuildbotHookTests(WebhookTestCase):
STREAM_NAME = "buildbot" STREAM_NAME = "buildbot"
URL_TEMPLATE = u"/api/v1/external/buildbot?api_key={api_key}&stream={stream}" URL_TEMPLATE = u"/api/v1/external/buildbot?api_key={api_key}&stream={stream}"

View File

@@ -1,12 +1,13 @@
from typing import Dict, Any from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.models import UserProfile
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
@api_key_only_webhook_view('Buildbot') @api_key_only_webhook_view('Buildbot')
@has_request_variables @has_request_variables

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class CircleCiHookTests(WebhookTestCase): class CircleCiHookTests(WebhookTestCase):
STREAM_NAME = 'circleci' STREAM_NAME = 'circleci'
URL_TEMPLATE = u"/api/v1/external/circleci?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/circleci?stream={stream}&api_key={api_key}"

View File

@@ -1,5 +1,4 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from typing import Any, Dict from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse

View File

@@ -1,8 +1,10 @@
import json import json
from mock import MagicMock, patch from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class ClubhouseWebhookTest(WebhookTestCase): class ClubhouseWebhookTest(WebhookTestCase):
STREAM_NAME = 'clubhouse' STREAM_NAME = 'clubhouse'
URL_TEMPLATE = "/api/v1/external/clubhouse?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/clubhouse?stream={stream}&api_key={api_key}"

View File

@@ -4,13 +4,12 @@ from typing import Any, Dict, Optional
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.webhooks.common import check_send_webhook_message, \
UnexpectedWebhookEventType
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
EPIC_NAME_TEMPLATE = "**{name}**" EPIC_NAME_TEMPLATE = "**{name}**"
STORY_NAME_TEMPLATE = "[{name}]({app_url})" STORY_NAME_TEMPLATE = "[{name}]({app_url})"
COMMENT_ADDED_TEMPLATE = "New comment added to the {entity} {name_template}:\n``` quote\n{text}\n```" COMMENT_ADDED_TEMPLATE = "New comment added to the {entity} {name_template}:\n``` quote\n{text}\n```"

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class CodeshipHookTests(WebhookTestCase): class CodeshipHookTests(WebhookTestCase):
STREAM_NAME = 'codeship' STREAM_NAME = 'codeship'
URL_TEMPLATE = u"/api/v1/external/codeship?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/codeship?stream={stream}&api_key={api_key}"

View File

@@ -1,5 +1,4 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from typing import Any, Dict from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class CrashlyticsHookTests(WebhookTestCase): class CrashlyticsHookTests(WebhookTestCase):
STREAM_NAME = 'crashlytics' STREAM_NAME = 'crashlytics'
URL_TEMPLATE = u"/api/v1/external/crashlytics?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/crashlytics?stream={stream}&api_key={api_key}"

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class DelightedHookTests(WebhookTestCase): class DelightedHookTests(WebhookTestCase):
STREAM_NAME = 'delighted' STREAM_NAME = 'delighted'
URL_TEMPLATE = "/api/v1/external/delighted?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/delighted?stream={stream}&api_key={api_key}"

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
# Tests for the Desk.com webhook integration. # Tests for the Desk.com webhook integration.

View File

@@ -1,5 +1,4 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import authenticated_rest_api_view from zerver.decorator import authenticated_rest_api_view
@@ -8,6 +7,7 @@ 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
from zerver.models import UserProfile from zerver.models import UserProfile
# Desk.com's integrations all make the user supply a template, where it fills # Desk.com's integrations all make the user supply a template, where it fills
# in stuff like {{customer.name}} and posts the result as a "data" parameter. # in stuff like {{customer.name}} and posts the result as a "data" parameter.
# There's no raw JSON for us to work from. Thus, it makes sense to just write # There's no raw JSON for us to work from. Thus, it makes sense to just write

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class DialogflowHookTests(WebhookTestCase): class DialogflowHookTests(WebhookTestCase):
URL_TEMPLATE = u"/api/v1/external/dialogflow?api_key={api_key}&email=AARON@zulip.com" URL_TEMPLATE = u"/api/v1/external/dialogflow?api_key={api_key}&email=AARON@zulip.com"

View File

@@ -1,12 +1,15 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from typing import Any, Dict from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.actions import check_send_private_message from zerver.lib.actions import check_send_private_message
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.models import UserProfile, get_user_profile_by_email from zerver.models import UserProfile, get_user_profile_by_email
@api_key_only_webhook_view("dialogflow") @api_key_only_webhook_view("dialogflow")
@has_request_variables @has_request_variables
def api_dialogflow_webhook(request: HttpRequest, user_profile: UserProfile, def api_dialogflow_webhook(request: HttpRequest, user_profile: UserProfile,

View File

@@ -1,8 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
from zerver.lib.users import get_api_key from zerver.lib.users import get_api_key
class DropboxHookTests(WebhookTestCase): class DropboxHookTests(WebhookTestCase):
STREAM_NAME = 'test' STREAM_NAME = 'test'
URL_TEMPLATE = "/api/v1/external/dropbox?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/dropbox?&api_key={api_key}&stream={stream}"

View File

@@ -1,9 +1,11 @@
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view, has_request_variables
from zerver.lib.response import json_success 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
from zerver.decorator import has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile from zerver.models import UserProfile
@api_key_only_webhook_view('Dropbox', notify_bot_owner_on_invalid_json=False) @api_key_only_webhook_view('Dropbox', notify_bot_owner_on_invalid_json=False)
@has_request_variables @has_request_variables
def api_dropbox_webhook(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: def api_dropbox_webhook(request: HttpRequest, user_profile: UserProfile) -> HttpResponse:

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class FlockHookTests(WebhookTestCase): class FlockHookTests(WebhookTestCase):
STREAM_NAME = 'test' STREAM_NAME = 'test'
URL_TEMPLATE = u"/api/v1/external/flock?api_key={api_key}&stream={stream}" URL_TEMPLATE = u"/api/v1/external/flock?api_key={api_key}&stream={stream}"

View File

@@ -1,10 +1,13 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from typing import Any, Dict
from django.http import HttpRequest, HttpResponse
from zerver.decorator import REQ, api_key_only_webhook_view, \
has_request_variables
from zerver.lib.response import json_success 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
from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view
from zerver.models import UserProfile from zerver.models import UserProfile
from django.http import HttpRequest, HttpResponse
from typing import Dict, Any
CHECK_IS_REPLY = "in reply to" CHECK_IS_REPLY = "in reply to"

View File

@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from mock import MagicMock, patch from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class FreshdeskHookTests(WebhookTestCase): class FreshdeskHookTests(WebhookTestCase):
STREAM_NAME = 'freshdesk' STREAM_NAME = 'freshdesk'
URL_TEMPLATE = u"/api/v1/external/freshdesk?stream={stream}" URL_TEMPLATE = u"/api/v1/external/freshdesk?stream={stream}"

View File

@@ -1,5 +1,4 @@
"""Webhooks for external integrations.""" """Webhooks for external integrations."""
import logging import logging
from typing import Any, Dict, List from typing import Any, Dict, List

View File

@@ -2,6 +2,7 @@ import ujson
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class FrontHookTests(WebhookTestCase): class FrontHookTests(WebhookTestCase):
STREAM_NAME = 'front' STREAM_NAME = 'front'
URL_TEMPLATE = "/api/v1/external/front?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/front?&api_key={api_key}&stream={stream}"

View File

@@ -9,6 +9,7 @@ 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
from zerver.models import UserProfile from zerver.models import UserProfile
def get_message_data(payload: Dict[str, Any]) -> Tuple[str, str, str, str]: def get_message_data(payload: Dict[str, Any]) -> Tuple[str, str, str, str]:
link = "https://app.frontapp.com/open/" + payload['target']['data']['id'] link = "https://app.frontapp.com/open/" + payload['target']['data']['id']
outbox = payload['conversation']['recipient']['handle'] outbox = payload['conversation']['recipient']['handle']

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class GoogleCodeInTests(WebhookTestCase): class GoogleCodeInTests(WebhookTestCase):
STREAM_NAME = 'gci' STREAM_NAME = 'gci'
URL_TEMPLATE = "/api/v1/external/gci?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/gci?&api_key={api_key}&stream={stream}"

View File

@@ -3,6 +3,7 @@ from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class GiteaHookTests(WebhookTestCase): class GiteaHookTests(WebhookTestCase):
STREAM_NAME = 'commits' STREAM_NAME = 'commits'
URL_TEMPLATE = "/api/v1/external/giteae?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/giteae?&api_key={api_key}&stream={stream}"

View File

@@ -12,7 +12,6 @@ from zerver.models import UserProfile
# Gitea is a fork of Gogs, and so the webhook implementation is nearly the same. # Gitea is a fork of Gogs, and so the webhook implementation is nearly the same.
from zerver.webhooks.gogs.view import gogs_webhook_main from zerver.webhooks.gogs.view import gogs_webhook_main
fixture_to_headers = get_http_headers_from_filename("HTTP_X_GITEA_EVENT") fixture_to_headers = get_http_headers_from_filename("HTTP_X_GITEA_EVENT")
def format_pull_request_event(payload: Dict[str, Any], def format_pull_request_event(payload: Dict[str, Any],

View File

@@ -3,6 +3,7 @@ from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
from zerver.lib.webhooks.git import COMMITS_LIMIT from zerver.lib.webhooks.git import COMMITS_LIMIT
class GithubWebhookTest(WebhookTestCase): class GithubWebhookTest(WebhookTestCase):
STREAM_NAME = 'github' STREAM_NAME = 'github'
URL_TEMPLATE = "/api/v1/external/github?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/github?stream={stream}&api_key={api_key}"

View File

@@ -1,23 +1,22 @@
import re import re
from functools import partial from functools import partial
from typing import Any, Dict, Optional
from inspect import signature from inspect import signature
from typing import Any, Dict, Optional
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
validate_extract_webhook_http_header, UnexpectedWebhookEventType check_send_webhook_message, get_http_headers_from_filename, \
validate_extract_webhook_http_header
from zerver.lib.webhooks.git import CONTENT_MESSAGE_TEMPLATE, \ from zerver.lib.webhooks.git import CONTENT_MESSAGE_TEMPLATE, \
TOPIC_WITH_BRANCH_TEMPLATE, TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \ TOPIC_WITH_BRANCH_TEMPLATE, TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \
get_commits_comment_action_message, get_issue_event_message, \ get_commits_comment_action_message, get_issue_event_message, \
get_pull_request_event_message, get_push_commits_event_message, \ get_pull_request_event_message, get_push_commits_event_message, \
get_push_tag_event_message, get_setup_webhook_message get_push_tag_event_message, get_setup_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
from zerver.lib.webhooks.common import \
get_http_headers_from_filename
fixture_to_headers = get_http_headers_from_filename("HTTP_X_GITHUB_EVENT") fixture_to_headers = get_http_headers_from_filename("HTTP_X_GITHUB_EVENT")

View File

@@ -4,6 +4,7 @@ from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
from zerver.lib.webhooks.git import COMMITS_LIMIT from zerver.lib.webhooks.git import COMMITS_LIMIT
class GitlabHookTests(WebhookTestCase): class GitlabHookTests(WebhookTestCase):
STREAM_NAME = 'gitlab' STREAM_NAME = 'gitlab'
URL_TEMPLATE = "/api/v1/external/gitlab?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/gitlab?&api_key={api_key}&stream={stream}"

View File

@@ -1,22 +1,23 @@
from functools import partial
from typing import Any, Dict, Optional
from inspect import signature
import re import re
from functools import partial
from inspect import signature
from typing import Any, Dict, Optional
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
validate_extract_webhook_http_header, UnexpectedWebhookEventType check_send_webhook_message, validate_extract_webhook_http_header
from zerver.lib.webhooks.git import EMPTY_SHA, \ from zerver.lib.webhooks.git import EMPTY_SHA, \
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \ TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_commits_comment_action_message, \
get_commits_comment_action_message, get_issue_event_message, \ get_issue_event_message, get_pull_request_event_message, \
get_pull_request_event_message, get_push_commits_event_message, \ get_push_commits_event_message, get_push_tag_event_message, \
get_push_tag_event_message, get_remove_branch_event_message get_remove_branch_event_message
from zerver.models import UserProfile from zerver.models import UserProfile
def fixture_to_headers(fixture_name: str) -> Dict[str, Any]: def fixture_to_headers(fixture_name: str) -> Dict[str, Any]:
if fixture_name.startswith("build"): if fixture_name.startswith("build"):
return {} # Since there are 2 possible event types. return {} # Since there are 2 possible event types.

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class GocdHookTests(WebhookTestCase): class GocdHookTests(WebhookTestCase):
STREAM_NAME = 'gocd' STREAM_NAME = 'gocd'
URL_TEMPLATE = "/api/v1/external/gocd?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/gocd?stream={stream}&api_key={api_key}"

View File

@@ -1,8 +1,6 @@
# Webhooks for external integrations. # Webhooks for external integrations.
import json import json
import os import os
from typing import Any, Dict from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse

View File

@@ -4,6 +4,7 @@ from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
from zerver.lib.webhooks.git import COMMITS_LIMIT from zerver.lib.webhooks.git import COMMITS_LIMIT
class GogsHookTests(WebhookTestCase): class GogsHookTests(WebhookTestCase):
STREAM_NAME = 'commits' STREAM_NAME = 'commits'
URL_TEMPLATE = "/api/v1/external/gogs?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/gogs?&api_key={api_key}&stream={stream}"

View File

@@ -7,13 +7,13 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
validate_extract_webhook_http_header, UnexpectedWebhookEventType, \ check_send_webhook_message, get_http_headers_from_filename, \
get_http_headers_from_filename validate_extract_webhook_http_header
from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \ from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \
TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_create_branch_event_message, \ TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_create_branch_event_message, \
get_pull_request_event_message, get_push_commits_event_message, \ get_issue_event_message, get_pull_request_event_message, \
get_issue_event_message get_push_commits_event_message
from zerver.models import UserProfile from zerver.models import UserProfile
fixture_to_headers = get_http_headers_from_filename("HTTP_X_GOGS_EVENT") fixture_to_headers = get_http_headers_from_filename("HTTP_X_GOGS_EVENT")

View File

@@ -1,9 +1,8 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
from zerver.webhooks.gosquared.view import CHAT_MESSAGE_TEMPLATE from zerver.webhooks.gosquared.view import CHAT_MESSAGE_TEMPLATE
class GoSquaredHookTests(WebhookTestCase): class GoSquaredHookTests(WebhookTestCase):
STREAM_NAME = 'gosquared' STREAM_NAME = 'gosquared'
URL_TEMPLATE = "/api/v1/external/gosquared?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/gosquared?stream={stream}&api_key={api_key}"

View File

@@ -5,8 +5,8 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
UnexpectedWebhookEventType check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
TRAFFIC_SPIKE_TEMPLATE = '[{website_name}]({website_url}) has {user_num} visitors online.' TRAFFIC_SPIKE_TEMPLATE = '[{website_name}]({website_url}) has {user_num} visitors online.'

View File

@@ -1,9 +1,9 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from mock import MagicMock, patch from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class GreenhouseHookTests(WebhookTestCase): class GreenhouseHookTests(WebhookTestCase):
STREAM_NAME = 'greenhouse' STREAM_NAME = 'greenhouse'
URL_TEMPLATE = "/api/v1/external/greenhouse?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/greenhouse?stream={stream}&api_key={api_key}"

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class GrooveHookTests(WebhookTestCase): class GrooveHookTests(WebhookTestCase):
STREAM_NAME = 'groove' STREAM_NAME = 'groove'
URL_TEMPLATE = '/api/v1/external/groove?stream={stream}&api_key={api_key}' URL_TEMPLATE = '/api/v1/external/groove?stream={stream}&api_key={api_key}'

View File

@@ -1,15 +1,15 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from functools import partial from functools import partial
from typing import Any, Dict, Optional, Callable from typing import Any, Callable, Dict, Optional
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
validate_extract_webhook_http_header, UnexpectedWebhookEventType, \ check_send_webhook_message, get_http_headers_from_filename, \
get_http_headers_from_filename validate_extract_webhook_http_header
from zerver.models import UserProfile from zerver.models import UserProfile
TICKET_STARTED_TEMPLATE = """ TICKET_STARTED_TEMPLATE = """

View File

@@ -3,6 +3,7 @@ from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class HarborHookTests(WebhookTestCase): class HarborHookTests(WebhookTestCase):
STREAM_NAME = "harbor" STREAM_NAME = "harbor"
URL_TEMPLATE = u"/api/v1/external/harbor?api_key={api_key}&stream={stream}" URL_TEMPLATE = u"/api/v1/external/harbor?api_key={api_key}&stream={stream}"

View File

@@ -7,8 +7,8 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
UnexpectedWebhookEventType check_send_webhook_message
from zerver.models import Realm, UserProfile from zerver.models import Realm, UserProfile
IGNORED_EVENTS = [ IGNORED_EVENTS = [

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class HelloSignHookTests(WebhookTestCase): class HelloSignHookTests(WebhookTestCase):
STREAM_NAME = 'hellosign' STREAM_NAME = 'hellosign'
URL_TEMPLATE = "/api/v1/external/hellosign?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/hellosign?stream={stream}&api_key={api_key}"

View File

@@ -8,7 +8,6 @@ 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
from zerver.models import UserProfile from zerver.models import UserProfile
IS_AWAITING_SIGNATURE = "is awaiting the signature of {awaiting_recipients}" IS_AWAITING_SIGNATURE = "is awaiting the signature of {awaiting_recipients}"
WAS_JUST_SIGNED_BY = "was just signed by {signed_recipients}" WAS_JUST_SIGNED_BY = "was just signed by {signed_recipients}"
BODY = "The `{contract_title}` document {actions}." BODY = "The `{contract_title}` document {actions}."

View File

@@ -4,6 +4,7 @@ from django.conf import settings
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
from zerver.models import get_system_bot from zerver.models import get_system_bot
class HelloWorldHookTests(WebhookTestCase): class HelloWorldHookTests(WebhookTestCase):
STREAM_NAME = 'test' STREAM_NAME = 'test'
URL_TEMPLATE = "/api/v1/external/helloworld?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/helloworld?&api_key={api_key}&stream={stream}"

View File

@@ -4,11 +4,12 @@ from typing import Any, Dict, Iterable
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
@api_key_only_webhook_view('HelloWorld') @api_key_only_webhook_view('HelloWorld')
@has_request_variables @has_request_variables
def api_helloworld_webhook( def api_helloworld_webhook(

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class HerokuHookTests(WebhookTestCase): class HerokuHookTests(WebhookTestCase):
STREAM_NAME = 'heroku' STREAM_NAME = 'heroku'
URL_TEMPLATE = u"/api/v1/external/heroku?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/heroku?stream={stream}&api_key={api_key}"

View File

@@ -1,5 +1,4 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view

View File

@@ -1,5 +1,6 @@
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class HomeAssistantHookTests(WebhookTestCase): class HomeAssistantHookTests(WebhookTestCase):
STREAM_NAME = 'homeassistant' STREAM_NAME = 'homeassistant'
URL_TEMPLATE = "/api/v1/external/homeassistant?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/homeassistant?&api_key={api_key}&stream={stream}"

View File

@@ -8,6 +8,7 @@ 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
from zerver.models import UserProfile from zerver.models import UserProfile
@api_key_only_webhook_view('HomeAssistant') @api_key_only_webhook_view('HomeAssistant')
@has_request_variables @has_request_variables
def api_homeassistant_webhook(request: HttpRequest, user_profile: UserProfile, def api_homeassistant_webhook(request: HttpRequest, user_profile: UserProfile,

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class IFTTTHookTests(WebhookTestCase): class IFTTTHookTests(WebhookTestCase):
STREAM_NAME = 'ifttt' STREAM_NAME = 'ifttt'
URL_TEMPLATE = "/api/v1/external/ifttt?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/ifttt?stream={stream}&api_key={api_key}"

View File

@@ -9,6 +9,7 @@ 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
from zerver.models import UserProfile from zerver.models import UserProfile
@api_key_only_webhook_view('IFTTT') @api_key_only_webhook_view('IFTTT')
@has_request_variables @has_request_variables
def api_iftt_app_webhook(request: HttpRequest, user_profile: UserProfile, def api_iftt_app_webhook(request: HttpRequest, user_profile: UserProfile,

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase

View File

@@ -1,14 +1,13 @@
from zerver.lib.response import json_success import time
from zerver.lib.webhooks.common import check_send_webhook_message from typing import Any, Dict
from zerver.decorator import REQ, has_request_variables, \
api_key_only_webhook_view
from zerver.models import UserProfile
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from typing import Dict, Any
import time from zerver.decorator import REQ, api_key_only_webhook_view, \
has_request_variables
from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message
from zerver.models import UserProfile
MESSAGE_TEMPLATE = """ MESSAGE_TEMPLATE = """
State changed to **{state}**: State changed to **{state}**:

View File

@@ -2,6 +2,7 @@ from mock import MagicMock, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class IntercomWebHookTests(WebhookTestCase): class IntercomWebHookTests(WebhookTestCase):
STREAM_NAME = 'test' STREAM_NAME = 'test'
URL_TEMPLATE = "/api/v1/external/intercom?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/intercom?&api_key={api_key}&stream={stream}"

View File

@@ -1,17 +1,16 @@
from functools import partial from functools import partial
from html.parser import HTMLParser from html.parser import HTMLParser
from typing import Any, Dict, Tuple, Callable, List from typing import Any, Callable, Dict, List, Tuple
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
UnexpectedWebhookEventType check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
COMPANY_CREATED = """ COMPANY_CREATED = """
New company **{name}** created: New company **{name}** created:
* **User count**: {user_count} * **User count**: {user_count}

View File

@@ -1,10 +1,10 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from urllib.parse import quote, unquote from urllib.parse import quote, unquote
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
from zerver.lib.users import get_api_key from zerver.lib.users import get_api_key
class JiraHookTests(WebhookTestCase): class JiraHookTests(WebhookTestCase):
STREAM_NAME = 'jira' STREAM_NAME = 'jira'
URL_TEMPLATE = u"/api/v1/external/jira?api_key={api_key}&stream={stream}" URL_TEMPLATE = u"/api/v1/external/jira?api_key={api_key}&stream={stream}"

View File

@@ -1,7 +1,7 @@
# Webhooks for external integrations. # Webhooks for external integrations.
import re import re
import string import string
from typing import Any, Dict, List, Optional, Callable from typing import Any, Callable, Dict, List, Optional
from django.db.models import Q from django.db.models import Q
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
@@ -9,8 +9,8 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
UnexpectedWebhookEventType check_send_webhook_message
from zerver.models import Realm, UserProfile, get_user_by_delivery_email from zerver.models import Realm, UserProfile, get_user_by_delivery_email
IGNORED_EVENTS = [ IGNORED_EVENTS = [

View File

@@ -3,6 +3,7 @@ import urllib
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class LibratoHookTests(WebhookTestCase): class LibratoHookTests(WebhookTestCase):
STREAM_NAME = 'librato' STREAM_NAME = 'librato'
URL_TEMPLATE = u"/api/v1/external/librato?api_key={api_key}&stream={stream}" URL_TEMPLATE = u"/api/v1/external/librato?api_key={api_key}&stream={stream}"

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class MentionHookTests(WebhookTestCase): class MentionHookTests(WebhookTestCase):
STREAM_NAME = 'test' STREAM_NAME = 'test'
URL_TEMPLATE = "/api/v1/external/mention?api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/mention?api_key={api_key}&stream={stream}"

View File

@@ -9,6 +9,7 @@ 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
from zerver.models import UserProfile from zerver.models import UserProfile
@api_key_only_webhook_view('Mention') @api_key_only_webhook_view('Mention')
@has_request_variables @has_request_variables
def api_mention_webhook( def api_mention_webhook(

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class NetlifyHookTests(WebhookTestCase): class NetlifyHookTests(WebhookTestCase):
STREAM_NAME = 'netlify' STREAM_NAME = 'netlify'
URL_TEMPLATE = u"/api/v1/external/netlify?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/netlify?stream={stream}&api_key={api_key}"

View File

@@ -3,11 +3,11 @@ from typing import Any, Dict, Iterable
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.webhooks.common import check_send_webhook_message, \
validate_extract_webhook_http_header, UnexpectedWebhookEventType, \
get_http_headers_from_filename
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
check_send_webhook_message, get_http_headers_from_filename, \
validate_extract_webhook_http_header
from zerver.models import UserProfile from zerver.models import UserProfile
EVENTS = ['deploy_failed', 'deploy_locked', 'deploy_unlocked', 'deploy_building', 'deploy_created'] EVENTS = ['deploy_failed', 'deploy_locked', 'deploy_unlocked', 'deploy_building', 'deploy_created']

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class NewRelicHookTests(WebhookTestCase): class NewRelicHookTests(WebhookTestCase):
STREAM_NAME = 'newrelic' STREAM_NAME = 'newrelic'
URL_TEMPLATE = u"/api/v1/external/newrelic?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/newrelic?stream={stream}&api_key={api_key}"

View File

@@ -6,9 +6,9 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \
UnexpectedWebhookEventType
from zerver.lib.validator import check_dict from zerver.lib.validator import check_dict
from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
ALERT_TEMPLATE = "{long_description} ([view alert]({alert_url}))." ALERT_TEMPLATE = "{long_description} ([view alert]({alert_url}))."

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
from zerver.webhooks.opbeat.view import get_value from zerver.webhooks.opbeat.view import get_value

View File

@@ -1,5 +1,5 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from typing import Dict, Any, List from typing import Any, Dict, List
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class OpsGenieHookTests(WebhookTestCase): class OpsGenieHookTests(WebhookTestCase):
STREAM_NAME = 'opsgenie' STREAM_NAME = 'opsgenie'
URL_TEMPLATE = "/api/v1/external/opsgenie?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/opsgenie?&api_key={api_key}&stream={stream}"

View File

@@ -8,6 +8,7 @@ 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
from zerver.models import UserProfile from zerver.models import UserProfile
@api_key_only_webhook_view('OpsGenie') @api_key_only_webhook_view('OpsGenie')
@has_request_variables @has_request_variables
def api_opsgenie_webhook(request: HttpRequest, user_profile: UserProfile, def api_opsgenie_webhook(request: HttpRequest, user_profile: UserProfile,

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class PagerDutyHookTests(WebhookTestCase): class PagerDutyHookTests(WebhookTestCase):
STREAM_NAME = 'pagerduty' STREAM_NAME = 'pagerduty'
URL_TEMPLATE = u"/api/v1/external/pagerduty?api_key={api_key}&stream={stream}" URL_TEMPLATE = u"/api/v1/external/pagerduty?api_key={api_key}&stream={stream}"

View File

@@ -1,5 +1,4 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from typing import Any, Dict, Iterable from typing import Any, Dict, Iterable
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
@@ -7,8 +6,8 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
UnexpectedWebhookEventType check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
PAGER_DUTY_EVENT_NAMES = { PAGER_DUTY_EVENT_NAMES = {

View File

@@ -2,6 +2,7 @@ from urllib.parse import urlencode
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class PapertrailHookTests(WebhookTestCase): class PapertrailHookTests(WebhookTestCase):
STREAM_NAME = 'papertrail' STREAM_NAME = 'papertrail'
URL_TEMPLATE = "/api/v1/external/papertrail?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/papertrail?&api_key={api_key}&stream={stream}"

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class PingdomHookTests(WebhookTestCase): class PingdomHookTests(WebhookTestCase):
STREAM_NAME = 'pingdom' STREAM_NAME = 'pingdom'
URL_TEMPLATE = u"/api/v1/external/pingdom?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/pingdom?stream={stream}&api_key={api_key}"

View File

@@ -6,8 +6,8 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
UnexpectedWebhookEventType check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
PINGDOM_TOPIC_TEMPLATE = '{name} status.' PINGDOM_TOPIC_TEMPLATE = '{name} status.'

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class PivotalV3HookTests(WebhookTestCase): class PivotalV3HookTests(WebhookTestCase):
STREAM_NAME = 'pivotal' STREAM_NAME = 'pivotal'
URL_TEMPLATE = u"/api/v1/external/pivotal?stream={stream}&api_key={api_key}" URL_TEMPLATE = u"/api/v1/external/pivotal?stream={stream}&api_key={api_key}"

View File

@@ -1,5 +1,4 @@
"""Webhooks for external integrations.""" """Webhooks for external integrations."""
import re import re
from typing import Any, Dict, List, Optional, Tuple from typing import Any, Dict, List, Optional, Tuple
@@ -11,10 +10,11 @@ from django.utils.translation import ugettext as _
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import has_request_variables from zerver.lib.request import has_request_variables
from zerver.lib.response import json_error, json_success 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 UnexpectedWebhookEventType, \
UnexpectedWebhookEventType check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> Tuple[str, str]: def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> Tuple[str, str]:
payload = xml_fromstring(request.body) payload = xml_fromstring(request.body)

View File

@@ -1,5 +1,4 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase

View File

@@ -1,3 +1,4 @@
import time
from typing import Any, Dict from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
@@ -5,12 +6,10 @@ from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import check_send_webhook_message, \ from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
UnexpectedWebhookEventType check_send_webhook_message
from zerver.models import UserProfile from zerver.models import UserProfile
import time
@api_key_only_webhook_view('Raygun') @api_key_only_webhook_view('Raygun')
@has_request_variables @has_request_variables

View File

@@ -3,11 +3,11 @@ from typing import Any, Dict, Iterable
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse
from zerver.decorator import api_key_only_webhook_view from zerver.decorator import api_key_only_webhook_view
from zerver.lib.webhooks.common import check_send_webhook_message, \
validate_extract_webhook_http_header, UnexpectedWebhookEventType, \
get_http_headers_from_filename
from zerver.lib.request import REQ, has_request_variables from zerver.lib.request import REQ, has_request_variables
from zerver.lib.response import json_success from zerver.lib.response import json_success
from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \
check_send_webhook_message, get_http_headers_from_filename, \
validate_extract_webhook_http_header
from zerver.models import UserProfile from zerver.models import UserProfile
REVIEW_REQUEST_PUBLISHED = """ REVIEW_REQUEST_PUBLISHED = """

View File

@@ -1,7 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class SemaphoreHookTests(WebhookTestCase): class SemaphoreHookTests(WebhookTestCase):
STREAM_NAME = 'semaphore' STREAM_NAME = 'semaphore'
URL_TEMPLATE = "/api/v1/external/semaphore?stream={stream}&api_key={api_key}" URL_TEMPLATE = "/api/v1/external/semaphore?stream={stream}&api_key={api_key}"

View File

@@ -1,5 +1,4 @@
# Webhooks for external integrations. # Webhooks for external integrations.
from typing import Any, Dict from typing import Any, Dict
from django.http import HttpRequest, HttpResponse from django.http import HttpRequest, HttpResponse

View File

@@ -1,6 +1,7 @@
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
class SentryHookTests(WebhookTestCase): class SentryHookTests(WebhookTestCase):
STREAM_NAME = 'sentry' STREAM_NAME = 'sentry'
URL_TEMPLATE = "/api/v1/external/sentry?&api_key={api_key}&stream={stream}" URL_TEMPLATE = "/api/v1/external/sentry?&api_key={api_key}&stream={stream}"

Some files were not shown because too many files have changed in this diff Show More