From c10cc24ee848f11c64d4f7dd9876e7585f547702 Mon Sep 17 00:00:00 2001 From: Tim Abbott Date: Tue, 14 Jan 2020 13:06:24 -0800 Subject: [PATCH] python: Sort webhooks imports with isort. --- zerver/webhooks/airbrake/tests.py | 1 + zerver/webhooks/airbrake/view.py | 2 +- zerver/webhooks/ansibletower/tests.py | 1 + zerver/webhooks/ansibletower/view.py | 8 ++++---- zerver/webhooks/appfollow/tests.py | 2 +- zerver/webhooks/appfollow/view.py | 1 + zerver/webhooks/appveyor/tests.py | 1 + zerver/webhooks/appveyor/view.py | 5 +++-- zerver/webhooks/basecamp/tests.py | 2 +- zerver/webhooks/basecamp/view.py | 4 ++-- zerver/webhooks/beanstalk/tests.py | 1 + zerver/webhooks/beanstalk/view.py | 10 +++++----- zerver/webhooks/beeminder/tests.py | 4 +++- zerver/webhooks/beeminder/view.py | 6 ++++-- zerver/webhooks/bitbucket/tests.py | 1 + zerver/webhooks/bitbucket/view.py | 1 + zerver/webhooks/bitbucket2/tests.py | 1 + zerver/webhooks/bitbucket2/view.py | 17 ++++++++-------- zerver/webhooks/bitbucket3/tests.py | 1 + zerver/webhooks/bitbucket3/view.py | 26 ++++++++++++------------- zerver/webhooks/buildbot/tests.py | 1 + zerver/webhooks/buildbot/view.py | 7 ++++--- zerver/webhooks/circleci/tests.py | 1 + zerver/webhooks/circleci/view.py | 1 - zerver/webhooks/clubhouse/tests.py | 2 ++ zerver/webhooks/clubhouse/view.py | 5 ++--- zerver/webhooks/codeship/tests.py | 1 + zerver/webhooks/codeship/view.py | 1 - zerver/webhooks/crashlytics/tests.py | 1 + zerver/webhooks/delighted/tests.py | 2 +- zerver/webhooks/deskdotcom/tests.py | 1 - zerver/webhooks/deskdotcom/view.py | 2 +- zerver/webhooks/dialogflow/tests.py | 1 + zerver/webhooks/dialogflow/view.py | 3 +++ zerver/webhooks/dropbox/tests.py | 2 +- zerver/webhooks/dropbox/view.py | 4 +++- zerver/webhooks/flock/tests.py | 1 + zerver/webhooks/flock/view.py | 9 ++++++--- zerver/webhooks/freshdesk/tests.py | 2 +- zerver/webhooks/freshdesk/view.py | 1 - zerver/webhooks/front/tests.py | 1 + zerver/webhooks/front/view.py | 1 + zerver/webhooks/gci/tests.py | 1 + zerver/webhooks/gitea/tests.py | 1 + zerver/webhooks/gitea/view.py | 1 - zerver/webhooks/github/tests.py | 1 + zerver/webhooks/github/view.py | 9 ++++----- zerver/webhooks/gitlab/tests.py | 1 + zerver/webhooks/gitlab/view.py | 19 +++++++++--------- zerver/webhooks/gocd/tests.py | 1 + zerver/webhooks/gocd/view.py | 2 -- zerver/webhooks/gogs/tests.py | 1 + zerver/webhooks/gogs/view.py | 10 +++++----- zerver/webhooks/gosquared/tests.py | 3 +-- zerver/webhooks/gosquared/view.py | 4 ++-- zerver/webhooks/greenhouse/tests.py | 2 +- zerver/webhooks/groove/tests.py | 1 + zerver/webhooks/groove/view.py | 8 ++++---- zerver/webhooks/harbor/tests.py | 1 + zerver/webhooks/harbor/view.py | 4 ++-- zerver/webhooks/hellosign/tests.py | 2 +- zerver/webhooks/hellosign/view.py | 1 - zerver/webhooks/helloworld/tests.py | 1 + zerver/webhooks/helloworld/view.py | 3 ++- zerver/webhooks/heroku/tests.py | 2 +- zerver/webhooks/heroku/view.py | 1 - zerver/webhooks/homeassistant/tests.py | 1 + zerver/webhooks/homeassistant/view.py | 1 + zerver/webhooks/ifttt/tests.py | 1 + zerver/webhooks/ifttt/view.py | 1 + zerver/webhooks/insping/tests.py | 1 - zerver/webhooks/insping/view.py | 15 +++++++------- zerver/webhooks/intercom/tests.py | 1 + zerver/webhooks/intercom/view.py | 7 +++---- zerver/webhooks/jira/tests.py | 2 +- zerver/webhooks/jira/view.py | 6 +++--- zerver/webhooks/librato/tests.py | 1 + zerver/webhooks/mention/tests.py | 2 +- zerver/webhooks/mention/view.py | 1 + zerver/webhooks/netlify/tests.py | 1 + zerver/webhooks/netlify/view.py | 6 +++--- zerver/webhooks/newrelic/tests.py | 2 +- zerver/webhooks/newrelic/view.py | 4 ++-- zerver/webhooks/opbeat/tests.py | 1 - zerver/webhooks/opbeat/view.py | 2 +- zerver/webhooks/opsgenie/tests.py | 2 +- zerver/webhooks/opsgenie/view.py | 1 + zerver/webhooks/pagerduty/tests.py | 2 +- zerver/webhooks/pagerduty/view.py | 5 ++--- zerver/webhooks/papertrail/tests.py | 1 + zerver/webhooks/pingdom/tests.py | 1 + zerver/webhooks/pingdom/view.py | 4 ++-- zerver/webhooks/pivotal/tests.py | 2 +- zerver/webhooks/pivotal/view.py | 6 +++--- zerver/webhooks/raygun/tests.py | 1 - zerver/webhooks/raygun/view.py | 7 +++---- zerver/webhooks/reviewboard/view.py | 6 +++--- zerver/webhooks/semaphore/tests.py | 2 +- zerver/webhooks/semaphore/view.py | 1 - zerver/webhooks/sentry/tests.py | 1 + zerver/webhooks/slack/tests.py | 1 + zerver/webhooks/solano/tests.py | 1 + zerver/webhooks/solano/view.py | 1 - zerver/webhooks/splunk/tests.py | 2 +- zerver/webhooks/statuspage/tests.py | 1 + zerver/webhooks/statuspage/view.py | 9 ++++++--- zerver/webhooks/stripe/tests.py | 2 +- zerver/webhooks/stripe/view.py | 5 +++-- zerver/webhooks/taiga/tests.py | 1 + zerver/webhooks/taiga/view.py | 4 ++-- zerver/webhooks/teamcity/tests.py | 8 +++++--- zerver/webhooks/teamcity/view.py | 3 +-- zerver/webhooks/transifex/tests.py | 1 + zerver/webhooks/transifex/view.py | 5 +++-- zerver/webhooks/travis/tests.py | 1 + zerver/webhooks/travis/view.py | 3 +-- zerver/webhooks/trello/tests.py | 1 + zerver/webhooks/trello/view/__init__.py | 18 ++++++++++------- zerver/webhooks/updown/tests.py | 1 + zerver/webhooks/updown/view.py | 4 ++-- zerver/webhooks/wordpress/tests.py | 1 + zerver/webhooks/yo/tests.py | 1 + zerver/webhooks/yo/view.py | 1 + zerver/webhooks/zabbix/tests.py | 6 +++--- zerver/webhooks/zabbix/view.py | 9 +++++---- zerver/webhooks/zapier/tests.py | 1 + zerver/webhooks/zapier/view.py | 1 + zerver/webhooks/zendesk/tests.py | 1 + zerver/webhooks/zendesk/view.py | 2 +- 129 files changed, 238 insertions(+), 180 deletions(-) diff --git a/zerver/webhooks/airbrake/tests.py b/zerver/webhooks/airbrake/tests.py index 76fa287330..cd75f97494 100644 --- a/zerver/webhooks/airbrake/tests.py +++ b/zerver/webhooks/airbrake/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class AirbrakeHookTests(WebhookTestCase): STREAM_NAME = 'airbrake' URL_TEMPLATE = u"/api/v1/external/airbrake?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/airbrake/view.py b/zerver/webhooks/airbrake/view.py index 05ce3cfc51..914d4ac7f1 100644 --- a/zerver/webhooks/airbrake/view.py +++ b/zerver/webhooks/airbrake/view.py @@ -4,9 +4,9 @@ from typing import Any, Dict from django.http import HttpRequest, HttpResponse 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.response import json_success +from zerver.lib.webhooks.common import check_send_webhook_message from zerver.models import UserProfile AIRBRAKE_TOPIC_TEMPLATE = '{project_name}' diff --git a/zerver/webhooks/ansibletower/tests.py b/zerver/webhooks/ansibletower/tests.py index 87dfd607f7..8a0718dda6 100644 --- a/zerver/webhooks/ansibletower/tests.py +++ b/zerver/webhooks/ansibletower/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class AnsibletowerHookTests(WebhookTestCase): STREAM_NAME = 'ansibletower' URL_TEMPLATE = "/api/v1/external/ansibletower?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/ansibletower/view.py b/zerver/webhooks/ansibletower/view.py index eadfd64661..f7ee85b37a 100644 --- a/zerver/webhooks/ansibletower/view.py +++ b/zerver/webhooks/ansibletower/view.py @@ -1,14 +1,14 @@ +import operator from typing import Any, Dict, List 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.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 -import operator - ANSIBLETOWER_DEFAULT_MESSAGE_TEMPLATE = "{friendly_name}: [#{id} {name}]({url}) {status}." diff --git a/zerver/webhooks/appfollow/tests.py b/zerver/webhooks/appfollow/tests.py index 66df310258..2825cab91b 100644 --- a/zerver/webhooks/appfollow/tests.py +++ b/zerver/webhooks/appfollow/tests.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- - from django.test import TestCase from zerver.lib.test_classes import WebhookTestCase from zerver.webhooks.appfollow.view import convert_markdown + class AppFollowHookTests(WebhookTestCase): STREAM_NAME = 'appfollow' URL_TEMPLATE = u"/api/v1/external/appfollow?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/appfollow/view.py b/zerver/webhooks/appfollow/view.py index 4e1c49b142..b889bfae5e 100644 --- a/zerver/webhooks/appfollow/view.py +++ b/zerver/webhooks/appfollow/view.py @@ -10,6 +10,7 @@ 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("AppFollow") @has_request_variables def api_appfollow_webhook(request: HttpRequest, user_profile: UserProfile, diff --git a/zerver/webhooks/appveyor/tests.py b/zerver/webhooks/appveyor/tests.py index 4e62f88dbe..c3a294492b 100644 --- a/zerver/webhooks/appveyor/tests.py +++ b/zerver/webhooks/appveyor/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class AppveyorHookTests(WebhookTestCase): STREAM_NAME = 'appveyor' URL_TEMPLATE = "/api/v1/external/appveyor?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/appveyor/view.py b/zerver/webhooks/appveyor/view.py index c9281f48ee..a5903d74e6 100644 --- a/zerver/webhooks/appveyor/view.py +++ b/zerver/webhooks/appveyor/view.py @@ -2,9 +2,10 @@ from typing import Any, Dict 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.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 APPVEYOR_TOPIC_TEMPLATE = '{project_name}' diff --git a/zerver/webhooks/basecamp/tests.py b/zerver/webhooks/basecamp/tests.py index f3edce4c43..d8a91a0986 100644 --- a/zerver/webhooks/basecamp/tests.py +++ b/zerver/webhooks/basecamp/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class BasecampHookTests(WebhookTestCase): STREAM_NAME = 'basecamp' URL_TEMPLATE = u"/api/v1/external/basecamp?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/basecamp/view.py b/zerver/webhooks/basecamp/view.py index fb41d41db1..f76a2d976c 100644 --- a/zerver/webhooks/basecamp/view.py +++ b/zerver/webhooks/basecamp/view.py @@ -7,8 +7,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, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile from .support_event import SUPPORT_EVENTS diff --git a/zerver/webhooks/beanstalk/tests.py b/zerver/webhooks/beanstalk/tests.py index 48ae0e48cb..42dfecd323 100644 --- a/zerver/webhooks/beanstalk/tests.py +++ b/zerver/webhooks/beanstalk/tests.py @@ -6,6 +6,7 @@ from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase from zerver.lib.webhooks.git import COMMITS_LIMIT + class BeanstalkHookTests(WebhookTestCase): STREAM_NAME = 'commits' URL_TEMPLATE = u"/api/v1/external/beanstalk?stream={stream}" diff --git a/zerver/webhooks/beanstalk/view.py b/zerver/webhooks/beanstalk/view.py index 69ed4b8049..903fdea2c1 100644 --- a/zerver/webhooks/beanstalk/view.py +++ b/zerver/webhooks/beanstalk/view.py @@ -1,22 +1,22 @@ # Webhooks for external integrations. - import base64 -from functools import wraps -from typing import Any, Dict, Optional, List, Tuple import re +from functools import wraps +from typing import Any, Dict, List, Optional, Tuple from django.http import HttpRequest, HttpResponse 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.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.git import TOPIC_WITH_BRANCH_TEMPLATE, \ get_push_commits_event_message -from zerver.lib.validator import check_dict from zerver.models import UserProfile + def build_message_from_gitlog(user_profile: UserProfile, name: str, ref: str, commits: List[Dict[str, str]], before: str, after: str, url: str, pusher: str, forced: Optional[str]=None, diff --git a/zerver/webhooks/beeminder/tests.py b/zerver/webhooks/beeminder/tests.py index 2046a0b2f2..676ed5278a 100644 --- a/zerver/webhooks/beeminder/tests.py +++ b/zerver/webhooks/beeminder/tests.py @@ -1,8 +1,10 @@ # -*- coding: utf-8 -*- -from unittest.mock import patch from typing import Any +from unittest.mock import patch + from zerver.lib.test_classes import WebhookTestCase + class BeeminderHookTests(WebhookTestCase): STREAM_NAME = 'beeminder' URL_TEMPLATE = u"/api/v1/external/beeminder?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/beeminder/view.py b/zerver/webhooks/beeminder/view.py index 4ec0c5bd5f..0d1fc28538 100644 --- a/zerver/webhooks/beeminder/view.py +++ b/zerver/webhooks/beeminder/view.py @@ -1,12 +1,14 @@ # Webhooks for external integrations. -from typing import Dict, Any +import time +from typing import Any, Dict + 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.models import UserProfile -import time MESSAGE_TEMPLATE = ("You are going to derail from goal **{goal_name}** in **{time:0.1f} hours**. " "You need **{limsum}** to avoid derailing.\n" diff --git a/zerver/webhooks/bitbucket/tests.py b/zerver/webhooks/bitbucket/tests.py index 709843d4db..f6901f5e9e 100644 --- a/zerver/webhooks/bitbucket/tests.py +++ b/zerver/webhooks/bitbucket/tests.py @@ -5,6 +5,7 @@ from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase + class BitbucketHookTests(WebhookTestCase): STREAM_NAME = 'bitbucket' URL_TEMPLATE = "/api/v1/external/bitbucket?stream={stream}" diff --git a/zerver/webhooks/bitbucket/view.py b/zerver/webhooks/bitbucket/view.py index e06e0cc906..f3e8e74523 100644 --- a/zerver/webhooks/bitbucket/view.py +++ b/zerver/webhooks/bitbucket/view.py @@ -11,6 +11,7 @@ from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \ get_push_commits_event_message from zerver.models import UserProfile + @authenticated_rest_api_view(webhook_client_name="Bitbucket") @has_request_variables def api_bitbucket_webhook(request: HttpRequest, user_profile: UserProfile, diff --git a/zerver/webhooks/bitbucket2/tests.py b/zerver/webhooks/bitbucket2/tests.py index 37e55e94c9..ff2864bf82 100644 --- a/zerver/webhooks/bitbucket2/tests.py +++ b/zerver/webhooks/bitbucket2/tests.py @@ -3,6 +3,7 @@ from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase + class Bitbucket2HookTests(WebhookTestCase): STREAM_NAME = 'bitbucket2' URL_TEMPLATE = "/api/v1/external/bitbucket2?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/bitbucket2/view.py b/zerver/webhooks/bitbucket2/view.py index ad06cafdbb..ca5c851fe6 100644 --- a/zerver/webhooks/bitbucket2/view.py +++ b/zerver/webhooks/bitbucket2/view.py @@ -1,23 +1,22 @@ # Webhooks for external integrations. import re -from functools import partial import string -from typing import Any, Dict, List, Optional +from functools import partial from inspect import signature +from typing import Any, Dict, List, Optional 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, \ - validate_extract_webhook_http_header, UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message, validate_extract_webhook_http_header from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \ - TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \ - get_commits_comment_action_message, get_force_push_commits_event_message, \ - get_issue_event_message, get_pull_request_event_message, \ - get_push_commits_event_message, get_push_tag_event_message, \ - get_remove_branch_event_message + TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_commits_comment_action_message, \ + get_force_push_commits_event_message, get_issue_event_message, \ + get_pull_request_event_message, get_push_commits_event_message, \ + get_push_tag_event_message, get_remove_branch_event_message from zerver.models import UserProfile BITBUCKET_TOPIC_TEMPLATE = '{repository_name}' diff --git a/zerver/webhooks/bitbucket3/tests.py b/zerver/webhooks/bitbucket3/tests.py index a342b324a1..f2983063d3 100644 --- a/zerver/webhooks/bitbucket3/tests.py +++ b/zerver/webhooks/bitbucket3/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class Bitbucket3HookTests(WebhookTestCase): STREAM_NAME = "bitbucket3" URL_TEMPLATE = "/api/v1/external/bitbucket3?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/bitbucket3/view.py b/zerver/webhooks/bitbucket3/view.py index 02e1f25ab4..cd34c4f868 100644 --- a/zerver/webhooks/bitbucket3/view.py +++ b/zerver/webhooks/bitbucket3/view.py @@ -1,23 +1,23 @@ -from inspect import signature -from functools import partial 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 zerver.models import UserProfile 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.git import TOPIC_WITH_BRANCH_TEMPLATE, \ - get_push_tag_event_message, get_remove_branch_event_message, \ - get_create_branch_event_message, get_commits_comment_action_message, \ - TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_pull_request_event_message, \ - CONTENT_MESSAGE_TEMPLATE -from zerver.lib.webhooks.common import check_send_webhook_message, \ - UnexpectedWebhookEventType -from zerver.webhooks.bitbucket2.view import BITBUCKET_TOPIC_TEMPLATE, \ - BITBUCKET_FORK_BODY, BITBUCKET_REPO_UPDATED_CHANGED +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message +from zerver.lib.webhooks.git import CONTENT_MESSAGE_TEMPLATE, \ + TOPIC_WITH_BRANCH_TEMPLATE, TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \ + get_commits_comment_action_message, get_create_branch_event_message, \ + get_pull_request_event_message, get_push_tag_event_message, \ + get_remove_branch_event_message +from zerver.models import UserProfile +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}." PULL_REQUEST_MARKED_AS_NEEDS_WORK_TEMPLATE = "{user_name} marked [PR #{number}]({url}) as \"needs work\"." diff --git a/zerver/webhooks/buildbot/tests.py b/zerver/webhooks/buildbot/tests.py index f8e0007fb2..c1cd787259 100644 --- a/zerver/webhooks/buildbot/tests.py +++ b/zerver/webhooks/buildbot/tests.py @@ -1,5 +1,6 @@ from zerver.lib.test_classes import WebhookTestCase + class BuildbotHookTests(WebhookTestCase): STREAM_NAME = "buildbot" URL_TEMPLATE = u"/api/v1/external/buildbot?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/buildbot/view.py b/zerver/webhooks/buildbot/view.py index ae69ecdccf..4a7d514993 100644 --- a/zerver/webhooks/buildbot/view.py +++ b/zerver/webhooks/buildbot/view.py @@ -1,12 +1,13 @@ -from typing import Dict, Any +from typing import Any, Dict from django.http import HttpRequest, HttpResponse 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.models import UserProfile 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') @has_request_variables diff --git a/zerver/webhooks/circleci/tests.py b/zerver/webhooks/circleci/tests.py index 009588fee7..057b1881ff 100644 --- a/zerver/webhooks/circleci/tests.py +++ b/zerver/webhooks/circleci/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class CircleCiHookTests(WebhookTestCase): STREAM_NAME = 'circleci' URL_TEMPLATE = u"/api/v1/external/circleci?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/circleci/view.py b/zerver/webhooks/circleci/view.py index bc306855b6..df450e5a36 100644 --- a/zerver/webhooks/circleci/view.py +++ b/zerver/webhooks/circleci/view.py @@ -1,5 +1,4 @@ # Webhooks for external integrations. - from typing import Any, Dict from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/clubhouse/tests.py b/zerver/webhooks/clubhouse/tests.py index a6dc60b5e9..de2cb25ce6 100644 --- a/zerver/webhooks/clubhouse/tests.py +++ b/zerver/webhooks/clubhouse/tests.py @@ -1,8 +1,10 @@ import json + from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase + class ClubhouseWebhookTest(WebhookTestCase): STREAM_NAME = 'clubhouse' URL_TEMPLATE = "/api/v1/external/clubhouse?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/clubhouse/view.py b/zerver/webhooks/clubhouse/view.py index e6e14f6cfb..2c09e8c13b 100644 --- a/zerver/webhooks/clubhouse/view.py +++ b/zerver/webhooks/clubhouse/view.py @@ -4,13 +4,12 @@ from typing import Any, Dict, Optional from django.http import HttpRequest, HttpResponse 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.response import json_success +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile - EPIC_NAME_TEMPLATE = "**{name}**" STORY_NAME_TEMPLATE = "[{name}]({app_url})" COMMENT_ADDED_TEMPLATE = "New comment added to the {entity} {name_template}:\n``` quote\n{text}\n```" diff --git a/zerver/webhooks/codeship/tests.py b/zerver/webhooks/codeship/tests.py index 603eadae46..00edc936c6 100644 --- a/zerver/webhooks/codeship/tests.py +++ b/zerver/webhooks/codeship/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class CodeshipHookTests(WebhookTestCase): STREAM_NAME = 'codeship' URL_TEMPLATE = u"/api/v1/external/codeship?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/codeship/view.py b/zerver/webhooks/codeship/view.py index 0287014e2d..9e1edb9312 100644 --- a/zerver/webhooks/codeship/view.py +++ b/zerver/webhooks/codeship/view.py @@ -1,5 +1,4 @@ # Webhooks for external integrations. - from typing import Any, Dict from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/crashlytics/tests.py b/zerver/webhooks/crashlytics/tests.py index aa261a778d..99f9ea9742 100644 --- a/zerver/webhooks/crashlytics/tests.py +++ b/zerver/webhooks/crashlytics/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class CrashlyticsHookTests(WebhookTestCase): STREAM_NAME = 'crashlytics' URL_TEMPLATE = u"/api/v1/external/crashlytics?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/delighted/tests.py b/zerver/webhooks/delighted/tests.py index b1cff07c4e..be3d197af3 100644 --- a/zerver/webhooks/delighted/tests.py +++ b/zerver/webhooks/delighted/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class DelightedHookTests(WebhookTestCase): STREAM_NAME = 'delighted' URL_TEMPLATE = "/api/v1/external/delighted?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/deskdotcom/tests.py b/zerver/webhooks/deskdotcom/tests.py index daf556e87f..a8d7b74c92 100644 --- a/zerver/webhooks/deskdotcom/tests.py +++ b/zerver/webhooks/deskdotcom/tests.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase # Tests for the Desk.com webhook integration. diff --git a/zerver/webhooks/deskdotcom/view.py b/zerver/webhooks/deskdotcom/view.py index b2c7f3454d..f4f0debbfe 100644 --- a/zerver/webhooks/deskdotcom/view.py +++ b/zerver/webhooks/deskdotcom/view.py @@ -1,5 +1,4 @@ # Webhooks for external integrations. - from django.http import HttpRequest, HttpResponse 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.models import UserProfile + # 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. # There's no raw JSON for us to work from. Thus, it makes sense to just write diff --git a/zerver/webhooks/dialogflow/tests.py b/zerver/webhooks/dialogflow/tests.py index 9b47c22010..0899f50536 100644 --- a/zerver/webhooks/dialogflow/tests.py +++ b/zerver/webhooks/dialogflow/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class DialogflowHookTests(WebhookTestCase): URL_TEMPLATE = u"/api/v1/external/dialogflow?api_key={api_key}&email=AARON@zulip.com" diff --git a/zerver/webhooks/dialogflow/view.py b/zerver/webhooks/dialogflow/view.py index 7f1e956c3e..f76ab644da 100644 --- a/zerver/webhooks/dialogflow/view.py +++ b/zerver/webhooks/dialogflow/view.py @@ -1,12 +1,15 @@ # Webhooks for external integrations. from typing import Any, Dict + from django.http import HttpRequest, HttpResponse + from zerver.decorator import api_key_only_webhook_view from zerver.lib.actions import check_send_private_message from zerver.lib.request import REQ, has_request_variables from zerver.lib.response import json_success from zerver.models import UserProfile, get_user_profile_by_email + @api_key_only_webhook_view("dialogflow") @has_request_variables def api_dialogflow_webhook(request: HttpRequest, user_profile: UserProfile, diff --git a/zerver/webhooks/dropbox/tests.py b/zerver/webhooks/dropbox/tests.py index 070a00ba15..1a725b5ae2 100644 --- a/zerver/webhooks/dropbox/tests.py +++ b/zerver/webhooks/dropbox/tests.py @@ -1,8 +1,8 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase from zerver.lib.users import get_api_key + class DropboxHookTests(WebhookTestCase): STREAM_NAME = 'test' URL_TEMPLATE = "/api/v1/external/dropbox?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/dropbox/view.py b/zerver/webhooks/dropbox/view.py index fc742299d7..8957b4bd1a 100644 --- a/zerver/webhooks/dropbox/view.py +++ b/zerver/webhooks/dropbox/view.py @@ -1,9 +1,11 @@ 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.webhooks.common import check_send_webhook_message -from zerver.decorator import has_request_variables, api_key_only_webhook_view from zerver.models import UserProfile + @api_key_only_webhook_view('Dropbox', notify_bot_owner_on_invalid_json=False) @has_request_variables def api_dropbox_webhook(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: diff --git a/zerver/webhooks/flock/tests.py b/zerver/webhooks/flock/tests.py index 0266f240c7..24763e8a3f 100644 --- a/zerver/webhooks/flock/tests.py +++ b/zerver/webhooks/flock/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class FlockHookTests(WebhookTestCase): STREAM_NAME = 'test' URL_TEMPLATE = u"/api/v1/external/flock?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/flock/view.py b/zerver/webhooks/flock/view.py index 72a98fedb3..45a3b0f52c 100644 --- a/zerver/webhooks/flock/view.py +++ b/zerver/webhooks/flock/view.py @@ -1,10 +1,13 @@ # 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.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 django.http import HttpRequest, HttpResponse -from typing import Dict, Any CHECK_IS_REPLY = "in reply to" diff --git a/zerver/webhooks/freshdesk/tests.py b/zerver/webhooks/freshdesk/tests.py index d0af898ea9..b54657b20b 100644 --- a/zerver/webhooks/freshdesk/tests.py +++ b/zerver/webhooks/freshdesk/tests.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- - from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase + class FreshdeskHookTests(WebhookTestCase): STREAM_NAME = 'freshdesk' URL_TEMPLATE = u"/api/v1/external/freshdesk?stream={stream}" diff --git a/zerver/webhooks/freshdesk/view.py b/zerver/webhooks/freshdesk/view.py index 090220f73e..c62989434a 100644 --- a/zerver/webhooks/freshdesk/view.py +++ b/zerver/webhooks/freshdesk/view.py @@ -1,5 +1,4 @@ """Webhooks for external integrations.""" - import logging from typing import Any, Dict, List diff --git a/zerver/webhooks/front/tests.py b/zerver/webhooks/front/tests.py index 9584535201..14f48b8957 100644 --- a/zerver/webhooks/front/tests.py +++ b/zerver/webhooks/front/tests.py @@ -2,6 +2,7 @@ import ujson from zerver.lib.test_classes import WebhookTestCase + class FrontHookTests(WebhookTestCase): STREAM_NAME = 'front' URL_TEMPLATE = "/api/v1/external/front?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/front/view.py b/zerver/webhooks/front/view.py index f20a423e56..3506d90ee7 100644 --- a/zerver/webhooks/front/view.py +++ b/zerver/webhooks/front/view.py @@ -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.models import UserProfile + def get_message_data(payload: Dict[str, Any]) -> Tuple[str, str, str, str]: link = "https://app.frontapp.com/open/" + payload['target']['data']['id'] outbox = payload['conversation']['recipient']['handle'] diff --git a/zerver/webhooks/gci/tests.py b/zerver/webhooks/gci/tests.py index f7c1958e8e..8e294f452c 100644 --- a/zerver/webhooks/gci/tests.py +++ b/zerver/webhooks/gci/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class GoogleCodeInTests(WebhookTestCase): STREAM_NAME = 'gci' URL_TEMPLATE = "/api/v1/external/gci?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/gitea/tests.py b/zerver/webhooks/gitea/tests.py index c5f57b8900..05a36b0d32 100644 --- a/zerver/webhooks/gitea/tests.py +++ b/zerver/webhooks/gitea/tests.py @@ -3,6 +3,7 @@ from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase + class GiteaHookTests(WebhookTestCase): STREAM_NAME = 'commits' URL_TEMPLATE = "/api/v1/external/giteae?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/gitea/view.py b/zerver/webhooks/gitea/view.py index 479fbc3caa..510f76e96e 100644 --- a/zerver/webhooks/gitea/view.py +++ b/zerver/webhooks/gitea/view.py @@ -12,7 +12,6 @@ from zerver.models import UserProfile # Gitea is a fork of Gogs, and so the webhook implementation is nearly the same. from zerver.webhooks.gogs.view import gogs_webhook_main - fixture_to_headers = get_http_headers_from_filename("HTTP_X_GITEA_EVENT") def format_pull_request_event(payload: Dict[str, Any], diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py index 2ac937e6b6..023f7ddc30 100644 --- a/zerver/webhooks/github/tests.py +++ b/zerver/webhooks/github/tests.py @@ -3,6 +3,7 @@ from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase from zerver.lib.webhooks.git import COMMITS_LIMIT + class GithubWebhookTest(WebhookTestCase): STREAM_NAME = 'github' URL_TEMPLATE = "/api/v1/external/github?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py index 142ed71fdd..f161809f7a 100644 --- a/zerver/webhooks/github/view.py +++ b/zerver/webhooks/github/view.py @@ -1,23 +1,22 @@ import re from functools import partial -from typing import Any, Dict, Optional from inspect import signature +from typing import Any, Dict, Optional 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, \ - validate_extract_webhook_http_header, UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message, get_http_headers_from_filename, \ + validate_extract_webhook_http_header from zerver.lib.webhooks.git import CONTENT_MESSAGE_TEMPLATE, \ TOPIC_WITH_BRANCH_TEMPLATE, TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \ get_commits_comment_action_message, get_issue_event_message, \ get_pull_request_event_message, get_push_commits_event_message, \ get_push_tag_event_message, get_setup_webhook_message 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") diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py index b50637c8b6..fdf4c56cf3 100644 --- a/zerver/webhooks/gitlab/tests.py +++ b/zerver/webhooks/gitlab/tests.py @@ -4,6 +4,7 @@ from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase from zerver.lib.webhooks.git import COMMITS_LIMIT + class GitlabHookTests(WebhookTestCase): STREAM_NAME = 'gitlab' URL_TEMPLATE = "/api/v1/external/gitlab?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py index 8dd99cdd94..0f3d7307fa 100644 --- a/zerver/webhooks/gitlab/view.py +++ b/zerver/webhooks/gitlab/view.py @@ -1,22 +1,23 @@ -from functools import partial -from typing import Any, Dict, Optional -from inspect import signature import re +from functools import partial +from inspect import signature +from typing import Any, Dict, Optional 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, \ - validate_extract_webhook_http_header, UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message, validate_extract_webhook_http_header from zerver.lib.webhooks.git import EMPTY_SHA, \ - TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, \ - get_commits_comment_action_message, get_issue_event_message, \ - get_pull_request_event_message, get_push_commits_event_message, \ - get_push_tag_event_message, get_remove_branch_event_message + TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE, get_commits_comment_action_message, \ + get_issue_event_message, get_pull_request_event_message, \ + get_push_commits_event_message, get_push_tag_event_message, \ + get_remove_branch_event_message from zerver.models import UserProfile + def fixture_to_headers(fixture_name: str) -> Dict[str, Any]: if fixture_name.startswith("build"): return {} # Since there are 2 possible event types. diff --git a/zerver/webhooks/gocd/tests.py b/zerver/webhooks/gocd/tests.py index e837e043cd..1f79a7c0a5 100644 --- a/zerver/webhooks/gocd/tests.py +++ b/zerver/webhooks/gocd/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class GocdHookTests(WebhookTestCase): STREAM_NAME = 'gocd' URL_TEMPLATE = "/api/v1/external/gocd?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/gocd/view.py b/zerver/webhooks/gocd/view.py index 4a4ab9e946..935b24cd14 100644 --- a/zerver/webhooks/gocd/view.py +++ b/zerver/webhooks/gocd/view.py @@ -1,8 +1,6 @@ # Webhooks for external integrations. - import json import os - from typing import Any, Dict from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/gogs/tests.py b/zerver/webhooks/gogs/tests.py index 443e3c61e1..7887ab839a 100644 --- a/zerver/webhooks/gogs/tests.py +++ b/zerver/webhooks/gogs/tests.py @@ -4,6 +4,7 @@ from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase from zerver.lib.webhooks.git import COMMITS_LIMIT + class GogsHookTests(WebhookTestCase): STREAM_NAME = 'commits' URL_TEMPLATE = "/api/v1/external/gogs?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/gogs/view.py b/zerver/webhooks/gogs/view.py index b1abdeab78..edee495a1f 100644 --- a/zerver/webhooks/gogs/view.py +++ b/zerver/webhooks/gogs/view.py @@ -7,13 +7,13 @@ 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, \ - validate_extract_webhook_http_header, UnexpectedWebhookEventType, \ - get_http_headers_from_filename +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message, get_http_headers_from_filename, \ + validate_extract_webhook_http_header from zerver.lib.webhooks.git import TOPIC_WITH_BRANCH_TEMPLATE, \ 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_issue_event_message, get_pull_request_event_message, \ + get_push_commits_event_message from zerver.models import UserProfile fixture_to_headers = get_http_headers_from_filename("HTTP_X_GOGS_EVENT") diff --git a/zerver/webhooks/gosquared/tests.py b/zerver/webhooks/gosquared/tests.py index 726ec05652..b290a399e6 100644 --- a/zerver/webhooks/gosquared/tests.py +++ b/zerver/webhooks/gosquared/tests.py @@ -1,9 +1,8 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase - from zerver.webhooks.gosquared.view import CHAT_MESSAGE_TEMPLATE + class GoSquaredHookTests(WebhookTestCase): STREAM_NAME = 'gosquared' URL_TEMPLATE = "/api/v1/external/gosquared?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/gosquared/view.py b/zerver/webhooks/gosquared/view.py index b0ce9fc055..44909dc6f8 100644 --- a/zerver/webhooks/gosquared/view.py +++ b/zerver/webhooks/gosquared/view.py @@ -5,8 +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, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile TRAFFIC_SPIKE_TEMPLATE = '[{website_name}]({website_url}) has {user_num} visitors online.' diff --git a/zerver/webhooks/greenhouse/tests.py b/zerver/webhooks/greenhouse/tests.py index eff2d7ea02..f648c8e3c5 100644 --- a/zerver/webhooks/greenhouse/tests.py +++ b/zerver/webhooks/greenhouse/tests.py @@ -1,9 +1,9 @@ # -*- coding: utf-8 -*- - from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase + class GreenhouseHookTests(WebhookTestCase): STREAM_NAME = 'greenhouse' URL_TEMPLATE = "/api/v1/external/greenhouse?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/groove/tests.py b/zerver/webhooks/groove/tests.py index e8b286e62d..76e8cd6787 100644 --- a/zerver/webhooks/groove/tests.py +++ b/zerver/webhooks/groove/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class GrooveHookTests(WebhookTestCase): STREAM_NAME = 'groove' URL_TEMPLATE = '/api/v1/external/groove?stream={stream}&api_key={api_key}' diff --git a/zerver/webhooks/groove/view.py b/zerver/webhooks/groove/view.py index aa79f85e71..cee879168e 100644 --- a/zerver/webhooks/groove/view.py +++ b/zerver/webhooks/groove/view.py @@ -1,15 +1,15 @@ # Webhooks for external integrations. 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 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, \ - validate_extract_webhook_http_header, UnexpectedWebhookEventType, \ - get_http_headers_from_filename +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 TICKET_STARTED_TEMPLATE = """ diff --git a/zerver/webhooks/harbor/tests.py b/zerver/webhooks/harbor/tests.py index 43fe31b0ac..b8175774ff 100644 --- a/zerver/webhooks/harbor/tests.py +++ b/zerver/webhooks/harbor/tests.py @@ -3,6 +3,7 @@ from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase + class HarborHookTests(WebhookTestCase): STREAM_NAME = "harbor" URL_TEMPLATE = u"/api/v1/external/harbor?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/harbor/view.py b/zerver/webhooks/harbor/view.py index 60ac4b9e6a..4dfaa73e71 100644 --- a/zerver/webhooks/harbor/view.py +++ b/zerver/webhooks/harbor/view.py @@ -7,8 +7,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, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import Realm, UserProfile IGNORED_EVENTS = [ diff --git a/zerver/webhooks/hellosign/tests.py b/zerver/webhooks/hellosign/tests.py index d0b6e96324..c0c96b78e6 100644 --- a/zerver/webhooks/hellosign/tests.py +++ b/zerver/webhooks/hellosign/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class HelloSignHookTests(WebhookTestCase): STREAM_NAME = 'hellosign' URL_TEMPLATE = "/api/v1/external/hellosign?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/hellosign/view.py b/zerver/webhooks/hellosign/view.py index 0d0b898973..7a89208e35 100644 --- a/zerver/webhooks/hellosign/view.py +++ b/zerver/webhooks/hellosign/view.py @@ -8,7 +8,6 @@ from zerver.lib.response import json_success from zerver.lib.webhooks.common import check_send_webhook_message from zerver.models import UserProfile - IS_AWAITING_SIGNATURE = "is awaiting the signature of {awaiting_recipients}" WAS_JUST_SIGNED_BY = "was just signed by {signed_recipients}" BODY = "The `{contract_title}` document {actions}." diff --git a/zerver/webhooks/helloworld/tests.py b/zerver/webhooks/helloworld/tests.py index a5242bf1ab..b65538da00 100644 --- a/zerver/webhooks/helloworld/tests.py +++ b/zerver/webhooks/helloworld/tests.py @@ -4,6 +4,7 @@ from django.conf import settings from zerver.lib.test_classes import WebhookTestCase from zerver.models import get_system_bot + class HelloWorldHookTests(WebhookTestCase): STREAM_NAME = 'test' URL_TEMPLATE = "/api/v1/external/helloworld?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/helloworld/view.py b/zerver/webhooks/helloworld/view.py index 5fc6cff0ba..2a8df7a145 100644 --- a/zerver/webhooks/helloworld/view.py +++ b/zerver/webhooks/helloworld/view.py @@ -4,11 +4,12 @@ from typing import Any, Dict, Iterable from django.http import HttpRequest, HttpResponse 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.response import json_success +from zerver.lib.webhooks.common import check_send_webhook_message from zerver.models import UserProfile + @api_key_only_webhook_view('HelloWorld') @has_request_variables def api_helloworld_webhook( diff --git a/zerver/webhooks/heroku/tests.py b/zerver/webhooks/heroku/tests.py index 462701d2f6..f0fd3c7a32 100644 --- a/zerver/webhooks/heroku/tests.py +++ b/zerver/webhooks/heroku/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class HerokuHookTests(WebhookTestCase): STREAM_NAME = 'heroku' URL_TEMPLATE = u"/api/v1/external/heroku?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/heroku/view.py b/zerver/webhooks/heroku/view.py index 32138ed5df..d0984ffe18 100644 --- a/zerver/webhooks/heroku/view.py +++ b/zerver/webhooks/heroku/view.py @@ -1,5 +1,4 @@ # Webhooks for external integrations. - from django.http import HttpRequest, HttpResponse from zerver.decorator import api_key_only_webhook_view diff --git a/zerver/webhooks/homeassistant/tests.py b/zerver/webhooks/homeassistant/tests.py index 9e51690f86..d070b9a55e 100644 --- a/zerver/webhooks/homeassistant/tests.py +++ b/zerver/webhooks/homeassistant/tests.py @@ -1,5 +1,6 @@ from zerver.lib.test_classes import WebhookTestCase + class HomeAssistantHookTests(WebhookTestCase): STREAM_NAME = 'homeassistant' URL_TEMPLATE = "/api/v1/external/homeassistant?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/homeassistant/view.py b/zerver/webhooks/homeassistant/view.py index ca354ba54d..99574fe38d 100644 --- a/zerver/webhooks/homeassistant/view.py +++ b/zerver/webhooks/homeassistant/view.py @@ -8,6 +8,7 @@ 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('HomeAssistant') @has_request_variables def api_homeassistant_webhook(request: HttpRequest, user_profile: UserProfile, diff --git a/zerver/webhooks/ifttt/tests.py b/zerver/webhooks/ifttt/tests.py index f13615c6ee..d1ad701d05 100644 --- a/zerver/webhooks/ifttt/tests.py +++ b/zerver/webhooks/ifttt/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class IFTTTHookTests(WebhookTestCase): STREAM_NAME = 'ifttt' URL_TEMPLATE = "/api/v1/external/ifttt?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/ifttt/view.py b/zerver/webhooks/ifttt/view.py index af6749a3cd..7dc9791cb3 100644 --- a/zerver/webhooks/ifttt/view.py +++ b/zerver/webhooks/ifttt/view.py @@ -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.models import UserProfile + @api_key_only_webhook_view('IFTTT') @has_request_variables def api_iftt_app_webhook(request: HttpRequest, user_profile: UserProfile, diff --git a/zerver/webhooks/insping/tests.py b/zerver/webhooks/insping/tests.py index 0a1d420cab..ea2cd20a14 100644 --- a/zerver/webhooks/insping/tests.py +++ b/zerver/webhooks/insping/tests.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase diff --git a/zerver/webhooks/insping/view.py b/zerver/webhooks/insping/view.py index 2306cfee44..5c96b0dd4f 100644 --- a/zerver/webhooks/insping/view.py +++ b/zerver/webhooks/insping/view.py @@ -1,14 +1,13 @@ -from zerver.lib.response import json_success -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 +import time +from typing import Any, Dict 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 = """ State changed to **{state}**: diff --git a/zerver/webhooks/intercom/tests.py b/zerver/webhooks/intercom/tests.py index dacf2d420c..7a5397a614 100644 --- a/zerver/webhooks/intercom/tests.py +++ b/zerver/webhooks/intercom/tests.py @@ -2,6 +2,7 @@ from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase + class IntercomWebHookTests(WebhookTestCase): STREAM_NAME = 'test' URL_TEMPLATE = "/api/v1/external/intercom?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/intercom/view.py b/zerver/webhooks/intercom/view.py index e1e8e5369b..51df9b804f 100644 --- a/zerver/webhooks/intercom/view.py +++ b/zerver/webhooks/intercom/view.py @@ -1,17 +1,16 @@ from functools import partial 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 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, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile - COMPANY_CREATED = """ New company **{name}** created: * **User count**: {user_count} diff --git a/zerver/webhooks/jira/tests.py b/zerver/webhooks/jira/tests.py index 5249404654..5585d39504 100644 --- a/zerver/webhooks/jira/tests.py +++ b/zerver/webhooks/jira/tests.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- - from urllib.parse import quote, unquote from zerver.lib.test_classes import WebhookTestCase from zerver.lib.users import get_api_key + class JiraHookTests(WebhookTestCase): STREAM_NAME = 'jira' URL_TEMPLATE = u"/api/v1/external/jira?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/jira/view.py b/zerver/webhooks/jira/view.py index a534c02954..a7d7a1c90f 100644 --- a/zerver/webhooks/jira/view.py +++ b/zerver/webhooks/jira/view.py @@ -1,7 +1,7 @@ # Webhooks for external integrations. import re 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.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.lib.request import REQ, has_request_variables from zerver.lib.response import json_success -from zerver.lib.webhooks.common import check_send_webhook_message, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import Realm, UserProfile, get_user_by_delivery_email IGNORED_EVENTS = [ diff --git a/zerver/webhooks/librato/tests.py b/zerver/webhooks/librato/tests.py index 5f19cd6343..9ca4dc5aaf 100644 --- a/zerver/webhooks/librato/tests.py +++ b/zerver/webhooks/librato/tests.py @@ -3,6 +3,7 @@ import urllib from zerver.lib.test_classes import WebhookTestCase + class LibratoHookTests(WebhookTestCase): STREAM_NAME = 'librato' URL_TEMPLATE = u"/api/v1/external/librato?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/mention/tests.py b/zerver/webhooks/mention/tests.py index 4b39bde6b1..b90dbb3364 100644 --- a/zerver/webhooks/mention/tests.py +++ b/zerver/webhooks/mention/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class MentionHookTests(WebhookTestCase): STREAM_NAME = 'test' URL_TEMPLATE = "/api/v1/external/mention?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/mention/view.py b/zerver/webhooks/mention/view.py index a5ca101a96..80f036fb4d 100644 --- a/zerver/webhooks/mention/view.py +++ b/zerver/webhooks/mention/view.py @@ -9,6 +9,7 @@ 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('Mention') @has_request_variables def api_mention_webhook( diff --git a/zerver/webhooks/netlify/tests.py b/zerver/webhooks/netlify/tests.py index 56b2d98cd6..95d4217891 100644 --- a/zerver/webhooks/netlify/tests.py +++ b/zerver/webhooks/netlify/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class NetlifyHookTests(WebhookTestCase): STREAM_NAME = 'netlify' URL_TEMPLATE = u"/api/v1/external/netlify?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/netlify/view.py b/zerver/webhooks/netlify/view.py index 0d9e912002..607c528d5a 100644 --- a/zerver/webhooks/netlify/view.py +++ b/zerver/webhooks/netlify/view.py @@ -3,11 +3,11 @@ from typing import Any, Dict, Iterable from django.http import HttpRequest, HttpResponse 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.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 EVENTS = ['deploy_failed', 'deploy_locked', 'deploy_unlocked', 'deploy_building', 'deploy_created'] diff --git a/zerver/webhooks/newrelic/tests.py b/zerver/webhooks/newrelic/tests.py index cf20c2ee25..6e7595b11d 100644 --- a/zerver/webhooks/newrelic/tests.py +++ b/zerver/webhooks/newrelic/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class NewRelicHookTests(WebhookTestCase): STREAM_NAME = 'newrelic' URL_TEMPLATE = u"/api/v1/external/newrelic?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/newrelic/view.py b/zerver/webhooks/newrelic/view.py index 709f57f259..df3f611d86 100644 --- a/zerver/webhooks/newrelic/view.py +++ b/zerver/webhooks/newrelic/view.py @@ -6,9 +6,9 @@ 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, \ - UnexpectedWebhookEventType from zerver.lib.validator import check_dict +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile ALERT_TEMPLATE = "{long_description} ([view alert]({alert_url}))." diff --git a/zerver/webhooks/opbeat/tests.py b/zerver/webhooks/opbeat/tests.py index 20cf8715a4..2e899aa112 100644 --- a/zerver/webhooks/opbeat/tests.py +++ b/zerver/webhooks/opbeat/tests.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase from zerver.webhooks.opbeat.view import get_value diff --git a/zerver/webhooks/opbeat/view.py b/zerver/webhooks/opbeat/view.py index d9b7daafb2..9c922ec688 100644 --- a/zerver/webhooks/opbeat/view.py +++ b/zerver/webhooks/opbeat/view.py @@ -1,5 +1,5 @@ # Webhooks for external integrations. -from typing import Dict, Any, List +from typing import Any, Dict, List from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/opsgenie/tests.py b/zerver/webhooks/opsgenie/tests.py index 66f9cb78f2..a2da91856a 100644 --- a/zerver/webhooks/opsgenie/tests.py +++ b/zerver/webhooks/opsgenie/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class OpsGenieHookTests(WebhookTestCase): STREAM_NAME = 'opsgenie' URL_TEMPLATE = "/api/v1/external/opsgenie?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/opsgenie/view.py b/zerver/webhooks/opsgenie/view.py index 1baca36b35..f39ec8133c 100644 --- a/zerver/webhooks/opsgenie/view.py +++ b/zerver/webhooks/opsgenie/view.py @@ -8,6 +8,7 @@ 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('OpsGenie') @has_request_variables def api_opsgenie_webhook(request: HttpRequest, user_profile: UserProfile, diff --git a/zerver/webhooks/pagerduty/tests.py b/zerver/webhooks/pagerduty/tests.py index 5d11153d32..c59517e53d 100644 --- a/zerver/webhooks/pagerduty/tests.py +++ b/zerver/webhooks/pagerduty/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class PagerDutyHookTests(WebhookTestCase): STREAM_NAME = 'pagerduty' URL_TEMPLATE = u"/api/v1/external/pagerduty?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/pagerduty/view.py b/zerver/webhooks/pagerduty/view.py index 729dbb1f65..5b56603f92 100644 --- a/zerver/webhooks/pagerduty/view.py +++ b/zerver/webhooks/pagerduty/view.py @@ -1,5 +1,4 @@ # Webhooks for external integrations. - from typing import Any, Dict, Iterable 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.lib.request import REQ, has_request_variables from zerver.lib.response import json_success -from zerver.lib.webhooks.common import check_send_webhook_message, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile PAGER_DUTY_EVENT_NAMES = { diff --git a/zerver/webhooks/papertrail/tests.py b/zerver/webhooks/papertrail/tests.py index e3b6e1f3c8..8b383970fb 100644 --- a/zerver/webhooks/papertrail/tests.py +++ b/zerver/webhooks/papertrail/tests.py @@ -2,6 +2,7 @@ from urllib.parse import urlencode from zerver.lib.test_classes import WebhookTestCase + class PapertrailHookTests(WebhookTestCase): STREAM_NAME = 'papertrail' URL_TEMPLATE = "/api/v1/external/papertrail?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/pingdom/tests.py b/zerver/webhooks/pingdom/tests.py index 2cd1c643bd..8c70dff690 100644 --- a/zerver/webhooks/pingdom/tests.py +++ b/zerver/webhooks/pingdom/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class PingdomHookTests(WebhookTestCase): STREAM_NAME = 'pingdom' URL_TEMPLATE = u"/api/v1/external/pingdom?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/pingdom/view.py b/zerver/webhooks/pingdom/view.py index 33eecfeb80..6d747a4817 100644 --- a/zerver/webhooks/pingdom/view.py +++ b/zerver/webhooks/pingdom/view.py @@ -6,8 +6,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, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile PINGDOM_TOPIC_TEMPLATE = '{name} status.' diff --git a/zerver/webhooks/pivotal/tests.py b/zerver/webhooks/pivotal/tests.py index 7c0acb8c37..79f1cb5327 100644 --- a/zerver/webhooks/pivotal/tests.py +++ b/zerver/webhooks/pivotal/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class PivotalV3HookTests(WebhookTestCase): STREAM_NAME = 'pivotal' URL_TEMPLATE = u"/api/v1/external/pivotal?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/pivotal/view.py b/zerver/webhooks/pivotal/view.py index 0538f67f71..31965e3e32 100644 --- a/zerver/webhooks/pivotal/view.py +++ b/zerver/webhooks/pivotal/view.py @@ -1,5 +1,4 @@ """Webhooks for external integrations.""" - import re 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.lib.request import has_request_variables from zerver.lib.response import json_error, json_success -from zerver.lib.webhooks.common import check_send_webhook_message, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile + def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> Tuple[str, str]: payload = xml_fromstring(request.body) diff --git a/zerver/webhooks/raygun/tests.py b/zerver/webhooks/raygun/tests.py index 4cf53604e3..154a8e519c 100644 --- a/zerver/webhooks/raygun/tests.py +++ b/zerver/webhooks/raygun/tests.py @@ -1,5 +1,4 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase diff --git a/zerver/webhooks/raygun/view.py b/zerver/webhooks/raygun/view.py index 68aebadd1b..6aadff02e5 100644 --- a/zerver/webhooks/raygun/view.py +++ b/zerver/webhooks/raygun/view.py @@ -1,3 +1,4 @@ +import time from typing import Any, Dict 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.lib.request import REQ, has_request_variables from zerver.lib.response import json_success -from zerver.lib.webhooks.common import check_send_webhook_message, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile -import time - @api_key_only_webhook_view('Raygun') @has_request_variables diff --git a/zerver/webhooks/reviewboard/view.py b/zerver/webhooks/reviewboard/view.py index 95ee0cef4a..4d881053d9 100644 --- a/zerver/webhooks/reviewboard/view.py +++ b/zerver/webhooks/reviewboard/view.py @@ -3,11 +3,11 @@ from typing import Any, Dict, Iterable from django.http import HttpRequest, HttpResponse 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.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 REVIEW_REQUEST_PUBLISHED = """ diff --git a/zerver/webhooks/semaphore/tests.py b/zerver/webhooks/semaphore/tests.py index d692d1fd57..b576af580b 100644 --- a/zerver/webhooks/semaphore/tests.py +++ b/zerver/webhooks/semaphore/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class SemaphoreHookTests(WebhookTestCase): STREAM_NAME = 'semaphore' URL_TEMPLATE = "/api/v1/external/semaphore?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/semaphore/view.py b/zerver/webhooks/semaphore/view.py index 21ebf1b03f..16e1fc05a0 100644 --- a/zerver/webhooks/semaphore/view.py +++ b/zerver/webhooks/semaphore/view.py @@ -1,5 +1,4 @@ # Webhooks for external integrations. - from typing import Any, Dict from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/sentry/tests.py b/zerver/webhooks/sentry/tests.py index 3d6db7c37d..d4cdc2da75 100644 --- a/zerver/webhooks/sentry/tests.py +++ b/zerver/webhooks/sentry/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class SentryHookTests(WebhookTestCase): STREAM_NAME = 'sentry' URL_TEMPLATE = "/api/v1/external/sentry?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/slack/tests.py b/zerver/webhooks/slack/tests.py index 91f70fe450..ef948159c5 100644 --- a/zerver/webhooks/slack/tests.py +++ b/zerver/webhooks/slack/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class SlackWebhookTests(WebhookTestCase): STREAM_NAME = 'slack' URL_TEMPLATE = "/api/v1/external/slack?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/solano/tests.py b/zerver/webhooks/solano/tests.py index 4babad0f31..906847c77b 100644 --- a/zerver/webhooks/solano/tests.py +++ b/zerver/webhooks/solano/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class SolanoHookTests(WebhookTestCase): STREAM_NAME = 'solano labs' URL_TEMPLATE = u"/api/v1/external/solano?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/solano/view.py b/zerver/webhooks/solano/view.py index 9d57f5e43e..6d039702aa 100644 --- a/zerver/webhooks/solano/view.py +++ b/zerver/webhooks/solano/view.py @@ -1,5 +1,4 @@ # Webhooks for external integrations. - from typing import Any, Dict from django.http import HttpRequest, HttpResponse diff --git a/zerver/webhooks/splunk/tests.py b/zerver/webhooks/splunk/tests.py index 246bb1a36f..b28bbc5d1f 100644 --- a/zerver/webhooks/splunk/tests.py +++ b/zerver/webhooks/splunk/tests.py @@ -1,7 +1,7 @@ # -*- coding: utf-8 -*- - from zerver.lib.test_classes import WebhookTestCase + class SplunkHookTests(WebhookTestCase): STREAM_NAME = 'splunk' diff --git a/zerver/webhooks/statuspage/tests.py b/zerver/webhooks/statuspage/tests.py index f39c5f7a34..5e93e3a1a9 100644 --- a/zerver/webhooks/statuspage/tests.py +++ b/zerver/webhooks/statuspage/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class StatuspageHookTests(WebhookTestCase): STREAM_NAME = 'statuspage-test' URL_TEMPLATE = u"/api/v1/external/statuspage?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/statuspage/view.py b/zerver/webhooks/statuspage/view.py index 9b03b538fa..30f0a005a1 100644 --- a/zerver/webhooks/statuspage/view.py +++ b/zerver/webhooks/statuspage/view.py @@ -1,10 +1,13 @@ # 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.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 django.http import HttpRequest, HttpResponse -from typing import Dict, Any INCIDENT_TEMPLATE = """ **{name}**: diff --git a/zerver/webhooks/stripe/tests.py b/zerver/webhooks/stripe/tests.py index c756c1abf6..9e5b80ea6e 100644 --- a/zerver/webhooks/stripe/tests.py +++ b/zerver/webhooks/stripe/tests.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- - import mock from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase + class StripeHookTests(WebhookTestCase): STREAM_NAME = 'test' URL_TEMPLATE = "/api/v1/external/stripe?&api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/stripe/view.py b/zerver/webhooks/stripe/view.py index 9d8091072d..43192005dc 100644 --- a/zerver/webhooks/stripe/view.py +++ b/zerver/webhooks/stripe/view.py @@ -8,10 +8,11 @@ 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.timestamp import timestamp_to_datetime -from zerver.lib.webhooks.common import check_send_webhook_message, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile + class SuppressedEvent(Exception): pass diff --git a/zerver/webhooks/taiga/tests.py b/zerver/webhooks/taiga/tests.py index 6e114d60d4..ae397289ee 100644 --- a/zerver/webhooks/taiga/tests.py +++ b/zerver/webhooks/taiga/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class TaigaHookTests(WebhookTestCase): STREAM_NAME = 'taiga' TOPIC = "subject" diff --git a/zerver/webhooks/taiga/view.py b/zerver/webhooks/taiga/view.py index 3ee6fd9628..0136f8c630 100644 --- a/zerver/webhooks/taiga/view.py +++ b/zerver/webhooks/taiga/view.py @@ -6,9 +6,8 @@ Tips for notification output: value should always be in bold; otherwise the subject of US/task should be in bold. """ - -from typing import Any, Dict, List, Mapping, Optional, Tuple import string +from typing import Any, Dict, List, Mapping, Optional, Tuple from django.http import HttpRequest, HttpResponse @@ -18,6 +17,7 @@ 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('Taiga') @has_request_variables def api_taiga_webhook(request: HttpRequest, user_profile: UserProfile, diff --git a/zerver/webhooks/teamcity/tests.py b/zerver/webhooks/teamcity/tests.py index d870ac50b0..343ce98f4f 100644 --- a/zerver/webhooks/teamcity/tests.py +++ b/zerver/webhooks/teamcity/tests.py @@ -1,10 +1,12 @@ # -*- coding: utf-8 -*- import ujson -from zerver.lib.test_classes import WebhookTestCase from zerver.lib.send_email import FromAddress -from zerver.models import Recipient, get_user_by_delivery_email, get_realm -from zerver.webhooks.teamcity.view import MISCONFIGURED_PAYLOAD_TYPE_ERROR_MESSAGE +from zerver.lib.test_classes import WebhookTestCase +from zerver.models import Recipient, get_realm, get_user_by_delivery_email +from zerver.webhooks.teamcity.view import \ + MISCONFIGURED_PAYLOAD_TYPE_ERROR_MESSAGE + class TeamcityHookTests(WebhookTestCase): STREAM_NAME = 'teamcity' diff --git a/zerver/webhooks/teamcity/view.py b/zerver/webhooks/teamcity/view.py index b3c8653f30..b322741aa0 100644 --- a/zerver/webhooks/teamcity/view.py +++ b/zerver/webhooks/teamcity/view.py @@ -1,5 +1,4 @@ # Webhooks for teamcity integration - import logging from typing import Any, Dict, List, Optional @@ -9,9 +8,9 @@ from django.http import HttpRequest, HttpResponse from zerver.decorator import api_key_only_webhook_view from zerver.lib.actions import check_send_private_message, \ send_rate_limited_pm_notification_to_bot_owner -from zerver.lib.send_email import FromAddress from zerver.lib.request import REQ, has_request_variables from zerver.lib.response import json_success +from zerver.lib.send_email import FromAddress from zerver.lib.webhooks.common import check_send_webhook_message from zerver.models import Realm, UserProfile diff --git a/zerver/webhooks/transifex/tests.py b/zerver/webhooks/transifex/tests.py index 461f18751e..a439c5d107 100644 --- a/zerver/webhooks/transifex/tests.py +++ b/zerver/webhooks/transifex/tests.py @@ -3,6 +3,7 @@ from typing import Any, Dict from zerver.lib.test_classes import WebhookTestCase + class TransifexHookTests(WebhookTestCase): STREAM_NAME = 'transifex' URL_TEMPLATE = u"/api/v1/external/transifex?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/transifex/view.py b/zerver/webhooks/transifex/view.py index 4862649937..8ade7cb88f 100644 --- a/zerver/webhooks/transifex/view.py +++ b/zerver/webhooks/transifex/view.py @@ -7,10 +7,11 @@ 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.validator import check_int -from zerver.lib.webhooks.common import check_send_webhook_message, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile + @api_key_only_webhook_view('Transifex', notify_bot_owner_on_invalid_json=False) @has_request_variables def api_transifex_webhook( diff --git a/zerver/webhooks/travis/tests.py b/zerver/webhooks/travis/tests.py index b16e2c8903..fb13a34233 100644 --- a/zerver/webhooks/travis/tests.py +++ b/zerver/webhooks/travis/tests.py @@ -3,6 +3,7 @@ import urllib from zerver.lib.test_classes import WebhookTestCase + class TravisHookTests(WebhookTestCase): STREAM_NAME = 'travis' URL_TEMPLATE = u"/api/v1/external/travis?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/travis/view.py b/zerver/webhooks/travis/view.py index 9ea67aeca1..75c9a7fcb3 100644 --- a/zerver/webhooks/travis/view.py +++ b/zerver/webhooks/travis/view.py @@ -1,5 +1,4 @@ # Webhooks for external integrations. - from typing import Dict 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.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.validator import check_bool, check_dict, check_string +from zerver.lib.webhooks.common import check_send_webhook_message from zerver.models import UserProfile GOOD_STATUSES = ['Passed', 'Fixed'] diff --git a/zerver/webhooks/trello/tests.py b/zerver/webhooks/trello/tests.py index f43b4d4de9..5622aac137 100644 --- a/zerver/webhooks/trello/tests.py +++ b/zerver/webhooks/trello/tests.py @@ -3,6 +3,7 @@ from mock import MagicMock, patch from zerver.lib.test_classes import WebhookTestCase + class TrelloHookTests(WebhookTestCase): STREAM_NAME = 'trello' URL_TEMPLATE = u"/api/v1/external/trello?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/trello/view/__init__.py b/zerver/webhooks/trello/view/__init__.py index 71e1bdb8ce..69d201e3ae 100644 --- a/zerver/webhooks/trello/view/__init__.py +++ b/zerver/webhooks/trello/view/__init__.py @@ -1,17 +1,21 @@ # Webhooks for external integrations. +from typing import Any, Mapping, Optional, Tuple + import ujson -from typing import Mapping, Any, Tuple, Optional from django.http import HttpRequest, HttpResponse -from zerver.decorator import api_key_only_webhook_view, return_success_on_head_request -from zerver.lib.response import json_success + +from zerver.decorator import api_key_only_webhook_view, \ + return_success_on_head_request from zerver.lib.request import REQ, has_request_variables -from zerver.lib.webhooks.common import check_send_webhook_message, \ - UnexpectedWebhookEventType +from zerver.lib.response import json_success +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile -from .card_actions import SUPPORTED_CARD_ACTIONS, \ - IGNORED_CARD_ACTIONS, process_card_action from .board_actions import SUPPORTED_BOARD_ACTIONS, process_board_action +from .card_actions import IGNORED_CARD_ACTIONS, SUPPORTED_CARD_ACTIONS, \ + process_card_action + @api_key_only_webhook_view('Trello') @return_success_on_head_request diff --git a/zerver/webhooks/updown/tests.py b/zerver/webhooks/updown/tests.py index 7aee6f59ce..868105ebfe 100644 --- a/zerver/webhooks/updown/tests.py +++ b/zerver/webhooks/updown/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class UpdownHookTests(WebhookTestCase): STREAM_NAME = 'updown' URL_TEMPLATE = u"/api/v1/external/updown?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/updown/view.py b/zerver/webhooks/updown/view.py index c5acc457dd..9081214a11 100644 --- a/zerver/webhooks/updown/view.py +++ b/zerver/webhooks/updown/view.py @@ -7,8 +7,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, \ - UnexpectedWebhookEventType +from zerver.lib.webhooks.common import UnexpectedWebhookEventType, \ + check_send_webhook_message from zerver.models import UserProfile TOPIC_TEMPLATE = "{service_url}" diff --git a/zerver/webhooks/wordpress/tests.py b/zerver/webhooks/wordpress/tests.py index f9f71bd238..c49e0c2b1b 100644 --- a/zerver/webhooks/wordpress/tests.py +++ b/zerver/webhooks/wordpress/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class WordPressHookTests(WebhookTestCase): STREAM_NAME = 'wordpress' URL_TEMPLATE = "/api/v1/external/wordpress?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/yo/tests.py b/zerver/webhooks/yo/tests.py index 969c913b48..8b632ff45f 100644 --- a/zerver/webhooks/yo/tests.py +++ b/zerver/webhooks/yo/tests.py @@ -3,6 +3,7 @@ from typing import Any, Dict from zerver.lib.test_classes import WebhookTestCase + class YoHookTests(WebhookTestCase): STREAM_NAME = 'yo' URL_TEMPLATE = u"/api/v1/external/yo?api_key={api_key}" diff --git a/zerver/webhooks/yo/view.py b/zerver/webhooks/yo/view.py index 2cf430d40b..a5b8ebead7 100644 --- a/zerver/webhooks/yo/view.py +++ b/zerver/webhooks/yo/view.py @@ -9,6 +9,7 @@ from zerver.lib.request import REQ, has_request_variables from zerver.lib.response import json_success from zerver.models import UserProfile, get_user + @api_key_only_webhook_view('Yo', notify_bot_owner_on_invalid_json=False) @has_request_variables def api_yo_app_webhook(request: HttpRequest, user_profile: UserProfile, diff --git a/zerver/webhooks/zabbix/tests.py b/zerver/webhooks/zabbix/tests.py index 4600c54ae7..124244e140 100644 --- a/zerver/webhooks/zabbix/tests.py +++ b/zerver/webhooks/zabbix/tests.py @@ -1,10 +1,10 @@ # -*- coding: utf-8 -*- -from zerver.lib.test_classes import WebhookTestCase - -from zerver.models import Recipient from zerver.lib.send_email import FromAddress +from zerver.lib.test_classes import WebhookTestCase +from zerver.models import Recipient from zerver.webhooks.zabbix.view import MISCONFIGURED_PAYLOAD_ERROR_MESSAGE + class ZabbixHookTests(WebhookTestCase): STREAM_NAME = 'zabbix' URL_TEMPLATE = u"/api/v1/external/zabbix?api_key={api_key}&stream={stream}" diff --git a/zerver/webhooks/zabbix/view.py b/zerver/webhooks/zabbix/view.py index 52c2c6f79d..cecc95371b 100644 --- a/zerver/webhooks/zabbix/view.py +++ b/zerver/webhooks/zabbix/view.py @@ -1,13 +1,14 @@ from typing import Any, Dict -from django.utils.translation import ugettext as _ from django.http import HttpRequest, HttpResponse +from django.utils.translation import ugettext as _ +from zerver.decorator import REQ, api_key_only_webhook_view, \ + has_request_variables from zerver.lib.actions import send_rate_limited_pm_notification_to_bot_owner -from zerver.lib.webhooks.common import check_send_webhook_message -from zerver.lib.response import json_success, json_error +from zerver.lib.response import json_error, json_success from zerver.lib.send_email import FromAddress -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 MISCONFIGURED_PAYLOAD_ERROR_MESSAGE = """ diff --git a/zerver/webhooks/zapier/tests.py b/zerver/webhooks/zapier/tests.py index 44a368a250..2ede6fde9e 100644 --- a/zerver/webhooks/zapier/tests.py +++ b/zerver/webhooks/zapier/tests.py @@ -1,6 +1,7 @@ # -*- coding: utf-8 -*- from zerver.lib.test_classes import WebhookTestCase + class ZapierHookTests(WebhookTestCase): STREAM_NAME = 'zapier' URL_TEMPLATE = "/api/v1/external/zapier?stream={stream}&api_key={api_key}" diff --git a/zerver/webhooks/zapier/view.py b/zerver/webhooks/zapier/view.py index d199b336b5..0c5102d81d 100644 --- a/zerver/webhooks/zapier/view.py +++ b/zerver/webhooks/zapier/view.py @@ -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.models import UserProfile + @api_key_only_webhook_view('Zapier', notify_bot_owner_on_invalid_json=False) @has_request_variables def api_zapier_webhook(request: HttpRequest, user_profile: UserProfile, diff --git a/zerver/webhooks/zendesk/tests.py b/zerver/webhooks/zendesk/tests.py index c81f31ba62..43c69917cf 100644 --- a/zerver/webhooks/zendesk/tests.py +++ b/zerver/webhooks/zendesk/tests.py @@ -3,6 +3,7 @@ from typing import Any, Dict, Optional from zerver.lib.test_classes import WebhookTestCase + class ZenDeskHookTests(WebhookTestCase): STREAM_NAME = 'zendesk' URL_TEMPLATE = u"/api/v1/external/zendesk?stream={stream}" diff --git a/zerver/webhooks/zendesk/view.py b/zerver/webhooks/zendesk/view.py index 3026a948f4..0d9de550b9 100644 --- a/zerver/webhooks/zendesk/view.py +++ b/zerver/webhooks/zendesk/view.py @@ -1,5 +1,4 @@ # Webhooks for external integrations. - from django.http import HttpRequest, HttpResponse 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.models import UserProfile + def truncate(string: str, length: int) -> str: if len(string) > length: string = string[:length-3] + '...'