From 7de45951e24d64cd99038bd8cab56c4cea3d6dd6 Mon Sep 17 00:00:00 2001 From: Tomasz Kolek Date: Wed, 23 Nov 2016 20:15:23 +0100 Subject: [PATCH] Make webhooks as separate modules with view and tests. Create python packege for every webhook with view.py and tests.py --- tools/test-backend | 1 + zerver/lib/integrations.py | 10 ++-- zerver/{tests => }/webhooks/__init__.py | 0 .../airbrake}/__init__.py | 0 .../airbrake/tests.py} | 0 .../airbrake.py => webhooks/airbrake/view.py} | 0 zerver/webhooks/appfollow/__init__.py | 0 .../appfollow/tests.py} | 2 +- .../appfollow/view.py} | 0 zerver/webhooks/beanstalk/__init__.py | 0 .../beanstalk/tests.py} | 0 .../beanstalk/view.py} | 2 +- zerver/webhooks/bitbucket/__init__.py | 0 zerver/webhooks/bitbucket/tests.py | 50 +++++++++++++++++++ .../bitbucket/view.py} | 0 zerver/webhooks/bitbucket2/__init__.py | 0 .../bitbucket2/tests.py} | 48 ------------------ .../bitbucket2/view.py} | 0 zerver/webhooks/circleci/__init__.py | 0 .../circleci/tests.py} | 0 .../circleci.py => webhooks/circleci/view.py} | 0 zerver/webhooks/codeship/__init__.py | 0 .../codeship/tests.py} | 0 .../codeship.py => webhooks/codeship/view.py} | 0 zerver/webhooks/crashlytics/__init__.py | 0 .../crashlytics/tests.py} | 0 .../crashlytics/view.py} | 0 zerver/webhooks/delighted/__init__.py | 0 .../delighted/tests.py} | 0 .../delighted/view.py} | 0 zerver/webhooks/deskdotcom/__init__.py | 0 .../deskdotcom/tests.py} | 0 .../deskdotcom/view.py} | 0 zerver/webhooks/freshdesk/__init__.py | 0 .../freshdesk/tests.py} | 0 .../freshdesk/view.py} | 0 zerver/webhooks/github/__init__.py | 0 .../github/tests.py} | 0 .../github.py => webhooks/github/view.py} | 0 .../{views => }/webhooks/github_dispatcher.py | 4 +- zerver/webhooks/github_webhook/__init__.py | 0 .../github_webhook/tests.py} | 0 .../github_webhook/view.py} | 0 zerver/webhooks/gitlab/__init__.py | 0 .../gitlab/tests.py} | 0 .../gitlab.py => webhooks/gitlab/view.py} | 0 zerver/webhooks/gosquared/__init__.py | 0 .../gosquared/tests.py} | 0 .../gosquared/view.py} | 0 zerver/webhooks/hellosign/__init__.py | 0 .../hellosign/tests.py} | 0 .../hellosign/view.py} | 0 zerver/webhooks/helloworld/__init__.py | 0 .../helloworld/tests.py} | 0 .../helloworld/view.py} | 0 zerver/webhooks/heroku/__init__.py | 0 .../heroku/tests.py} | 0 .../heroku.py => webhooks/heroku/view.py} | 0 zerver/webhooks/ifttt/__init__.py | 0 .../test_IFTTT.py => webhooks/ifttt/tests.py} | 0 .../ifttt.py => webhooks/ifttt/view.py} | 0 zerver/webhooks/jira/__init__.py | 0 .../test_jira.py => webhooks/jira/tests.py} | 0 .../jira.py => webhooks/jira/view.py} | 0 zerver/webhooks/librato/__init__.py | 0 .../librato/tests.py} | 0 .../librato.py => webhooks/librato/view.py} | 0 zerver/webhooks/mention/__init__.py | 0 .../mention/tests.py} | 0 .../mention.py => webhooks/mention/view.py} | 0 zerver/webhooks/newrelic/__init__.py | 0 .../newrelic/tests.py} | 0 .../newrelic.py => webhooks/newrelic/view.py} | 0 zerver/webhooks/pagerduty/__init__.py | 0 .../pagerduty/tests.py} | 0 .../pagerduty/view.py} | 0 zerver/webhooks/papertrail/__init__.py | 0 .../papertrail/tests.py} | 0 .../papertrail/view.py} | 0 zerver/webhooks/pingdom/__init__.py | 0 .../pingdom/tests.py} | 0 .../pingdom.py => webhooks/pingdom/view.py} | 0 zerver/webhooks/pivotal/__init__.py | 0 .../pivotal/tests.py} | 0 .../pivotal.py => webhooks/pivotal/view.py} | 0 zerver/webhooks/semaphore/__init__.py | 0 .../semaphore/tests.py} | 0 .../semaphore/view.py} | 0 zerver/webhooks/sentry/__init__.py | 0 .../sentry/tests.py} | 0 .../sentry.py => webhooks/sentry/view.py} | 0 zerver/webhooks/solano/__init__.py | 0 .../solano/tests.py} | 0 .../solano.py => webhooks/solano/view.py} | 0 zerver/webhooks/stash/__init__.py | 0 .../test_stash.py => webhooks/stash/tests.py} | 0 .../stash.py => webhooks/stash/view.py} | 0 zerver/webhooks/stripe/__init__.py | 0 .../stripe/tests.py} | 0 .../stripe.py => webhooks/stripe/view.py} | 0 zerver/webhooks/taiga/__init__.py | 0 .../test_taiga.py => webhooks/taiga/tests.py} | 0 .../taiga.py => webhooks/taiga/view.py} | 0 zerver/webhooks/teamcity/__init__.py | 0 .../teamcity/tests.py} | 0 .../teamcity.py => webhooks/teamcity/view.py} | 0 zerver/webhooks/transifex/__init__.py | 0 .../transifex/tests.py} | 0 .../transifex/view.py} | 0 zerver/webhooks/travis/__init__.py | 0 .../travis/tests.py} | 0 .../travis.py => webhooks/travis/view.py} | 0 zerver/webhooks/trello/__init__.py | 38 ++++++++++++++ .../trello/tests.py} | 0 .../trello/view}/__init__.py | 0 .../trello/view}/board_actions.py | 0 .../trello/view}/card_actions.py | 0 .../trello/view}/exceptions.py | 0 .../trello/view}/templates.py | 0 zerver/webhooks/updown/__init__.py | 0 .../updown/tests.py} | 0 .../updown.py => webhooks/updown/view.py} | 0 zerver/webhooks/yo/__init__.py | 0 .../test_yo.py => webhooks/yo/tests.py} | 0 .../webhooks/yo.py => webhooks/yo/view.py} | 0 zerver/webhooks/zapier/__init__.py | 0 .../zapier/tests.py} | 0 .../zapier.py => webhooks/zapier/view.py} | 0 zerver/webhooks/zendesk/__init__.py | 0 .../zendesk/tests.py} | 0 .../zendesk.py => webhooks/zendesk/view.py} | 0 zproject/urls.py | 2 +- 132 files changed, 99 insertions(+), 58 deletions(-) rename zerver/{tests => }/webhooks/__init__.py (100%) rename zerver/{views/webhooks => webhooks/airbrake}/__init__.py (100%) rename zerver/{tests/webhooks/test_airbrake.py => webhooks/airbrake/tests.py} (100%) rename zerver/{views/webhooks/airbrake.py => webhooks/airbrake/view.py} (100%) create mode 100644 zerver/webhooks/appfollow/__init__.py rename zerver/{tests/webhooks/test_appfollow.py => webhooks/appfollow/tests.py} (97%) rename zerver/{views/webhooks/appfollow.py => webhooks/appfollow/view.py} (100%) create mode 100644 zerver/webhooks/beanstalk/__init__.py rename zerver/{tests/webhooks/test_beanstalk.py => webhooks/beanstalk/tests.py} (100%) rename zerver/{views/webhooks/beanstalk.py => webhooks/beanstalk/view.py} (98%) create mode 100644 zerver/webhooks/bitbucket/__init__.py create mode 100644 zerver/webhooks/bitbucket/tests.py rename zerver/{views/webhooks/bitbucket.py => webhooks/bitbucket/view.py} (100%) create mode 100644 zerver/webhooks/bitbucket2/__init__.py rename zerver/{tests/webhooks/test_bitbucket.py => webhooks/bitbucket2/tests.py} (82%) rename zerver/{views/webhooks/bitbucket2.py => webhooks/bitbucket2/view.py} (100%) create mode 100644 zerver/webhooks/circleci/__init__.py rename zerver/{tests/webhooks/test_circleci.py => webhooks/circleci/tests.py} (100%) rename zerver/{views/webhooks/circleci.py => webhooks/circleci/view.py} (100%) create mode 100644 zerver/webhooks/codeship/__init__.py rename zerver/{tests/webhooks/test_codeship.py => webhooks/codeship/tests.py} (100%) rename zerver/{views/webhooks/codeship.py => webhooks/codeship/view.py} (100%) create mode 100644 zerver/webhooks/crashlytics/__init__.py rename zerver/{tests/webhooks/test_crashlytics.py => webhooks/crashlytics/tests.py} (100%) rename zerver/{views/webhooks/crashlytics.py => webhooks/crashlytics/view.py} (100%) create mode 100644 zerver/webhooks/delighted/__init__.py rename zerver/{tests/webhooks/test_delighted.py => webhooks/delighted/tests.py} (100%) rename zerver/{views/webhooks/delighted.py => webhooks/delighted/view.py} (100%) create mode 100644 zerver/webhooks/deskdotcom/__init__.py rename zerver/{tests/webhooks/test_deskdotcom.py => webhooks/deskdotcom/tests.py} (100%) rename zerver/{views/webhooks/deskdotcom.py => webhooks/deskdotcom/view.py} (100%) create mode 100644 zerver/webhooks/freshdesk/__init__.py rename zerver/{tests/webhooks/test_freshdesk.py => webhooks/freshdesk/tests.py} (100%) rename zerver/{views/webhooks/freshdesk.py => webhooks/freshdesk/view.py} (100%) create mode 100644 zerver/webhooks/github/__init__.py rename zerver/{tests/webhooks/test_github.py => webhooks/github/tests.py} (100%) rename zerver/{views/webhooks/github.py => webhooks/github/view.py} (100%) rename zerver/{views => }/webhooks/github_dispatcher.py (83%) create mode 100644 zerver/webhooks/github_webhook/__init__.py rename zerver/{tests/webhooks/test_github_webhook.py => webhooks/github_webhook/tests.py} (100%) rename zerver/{views/webhooks/github_webhook.py => webhooks/github_webhook/view.py} (100%) create mode 100644 zerver/webhooks/gitlab/__init__.py rename zerver/{tests/webhooks/test_gitlab.py => webhooks/gitlab/tests.py} (100%) rename zerver/{views/webhooks/gitlab.py => webhooks/gitlab/view.py} (100%) create mode 100644 zerver/webhooks/gosquared/__init__.py rename zerver/{tests/webhooks/test_gosquared.py => webhooks/gosquared/tests.py} (100%) rename zerver/{views/webhooks/gosquared.py => webhooks/gosquared/view.py} (100%) create mode 100644 zerver/webhooks/hellosign/__init__.py rename zerver/{tests/webhooks/test_hellosign.py => webhooks/hellosign/tests.py} (100%) rename zerver/{views/webhooks/hellosign.py => webhooks/hellosign/view.py} (100%) create mode 100644 zerver/webhooks/helloworld/__init__.py rename zerver/{tests/webhooks/test_hello_world.py => webhooks/helloworld/tests.py} (100%) rename zerver/{views/webhooks/helloworld.py => webhooks/helloworld/view.py} (100%) create mode 100644 zerver/webhooks/heroku/__init__.py rename zerver/{tests/webhooks/test_heroku.py => webhooks/heroku/tests.py} (100%) rename zerver/{views/webhooks/heroku.py => webhooks/heroku/view.py} (100%) create mode 100644 zerver/webhooks/ifttt/__init__.py rename zerver/{tests/webhooks/test_IFTTT.py => webhooks/ifttt/tests.py} (100%) rename zerver/{views/webhooks/ifttt.py => webhooks/ifttt/view.py} (100%) create mode 100644 zerver/webhooks/jira/__init__.py rename zerver/{tests/webhooks/test_jira.py => webhooks/jira/tests.py} (100%) rename zerver/{views/webhooks/jira.py => webhooks/jira/view.py} (100%) create mode 100644 zerver/webhooks/librato/__init__.py rename zerver/{tests/webhooks/test_librato.py => webhooks/librato/tests.py} (100%) rename zerver/{views/webhooks/librato.py => webhooks/librato/view.py} (100%) create mode 100644 zerver/webhooks/mention/__init__.py rename zerver/{tests/webhooks/test_mention.py => webhooks/mention/tests.py} (100%) rename zerver/{views/webhooks/mention.py => webhooks/mention/view.py} (100%) create mode 100644 zerver/webhooks/newrelic/__init__.py rename zerver/{tests/webhooks/test_new_relic.py => webhooks/newrelic/tests.py} (100%) rename zerver/{views/webhooks/newrelic.py => webhooks/newrelic/view.py} (100%) create mode 100644 zerver/webhooks/pagerduty/__init__.py rename zerver/{tests/webhooks/test_pagerduty.py => webhooks/pagerduty/tests.py} (100%) rename zerver/{views/webhooks/pagerduty.py => webhooks/pagerduty/view.py} (100%) create mode 100644 zerver/webhooks/papertrail/__init__.py rename zerver/{tests/webhooks/test_papertrail.py => webhooks/papertrail/tests.py} (100%) rename zerver/{views/webhooks/papertrail.py => webhooks/papertrail/view.py} (100%) create mode 100644 zerver/webhooks/pingdom/__init__.py rename zerver/{tests/webhooks/test_pingdom.py => webhooks/pingdom/tests.py} (100%) rename zerver/{views/webhooks/pingdom.py => webhooks/pingdom/view.py} (100%) create mode 100644 zerver/webhooks/pivotal/__init__.py rename zerver/{tests/webhooks/test_pivotal.py => webhooks/pivotal/tests.py} (100%) rename zerver/{views/webhooks/pivotal.py => webhooks/pivotal/view.py} (100%) create mode 100644 zerver/webhooks/semaphore/__init__.py rename zerver/{tests/webhooks/test_semaphore.py => webhooks/semaphore/tests.py} (100%) rename zerver/{views/webhooks/semaphore.py => webhooks/semaphore/view.py} (100%) create mode 100644 zerver/webhooks/sentry/__init__.py rename zerver/{tests/webhooks/test_sentry.py => webhooks/sentry/tests.py} (100%) rename zerver/{views/webhooks/sentry.py => webhooks/sentry/view.py} (100%) create mode 100644 zerver/webhooks/solano/__init__.py rename zerver/{tests/webhooks/test_solano.py => webhooks/solano/tests.py} (100%) rename zerver/{views/webhooks/solano.py => webhooks/solano/view.py} (100%) create mode 100644 zerver/webhooks/stash/__init__.py rename zerver/{tests/webhooks/test_stash.py => webhooks/stash/tests.py} (100%) rename zerver/{views/webhooks/stash.py => webhooks/stash/view.py} (100%) create mode 100644 zerver/webhooks/stripe/__init__.py rename zerver/{tests/webhooks/test_stripe.py => webhooks/stripe/tests.py} (100%) rename zerver/{views/webhooks/stripe.py => webhooks/stripe/view.py} (100%) create mode 100644 zerver/webhooks/taiga/__init__.py rename zerver/{tests/webhooks/test_taiga.py => webhooks/taiga/tests.py} (100%) rename zerver/{views/webhooks/taiga.py => webhooks/taiga/view.py} (100%) create mode 100644 zerver/webhooks/teamcity/__init__.py rename zerver/{tests/webhooks/test_teamcity.py => webhooks/teamcity/tests.py} (100%) rename zerver/{views/webhooks/teamcity.py => webhooks/teamcity/view.py} (100%) create mode 100644 zerver/webhooks/transifex/__init__.py rename zerver/{tests/webhooks/test_transifex.py => webhooks/transifex/tests.py} (100%) rename zerver/{views/webhooks/transifex.py => webhooks/transifex/view.py} (100%) create mode 100644 zerver/webhooks/travis/__init__.py rename zerver/{tests/webhooks/test_travis.py => webhooks/travis/tests.py} (100%) rename zerver/{views/webhooks/travis.py => webhooks/travis/view.py} (100%) create mode 100644 zerver/webhooks/trello/__init__.py rename zerver/{tests/webhooks/test_trello.py => webhooks/trello/tests.py} (100%) rename zerver/{views/webhooks/trello => webhooks/trello/view}/__init__.py (100%) rename zerver/{views/webhooks/trello => webhooks/trello/view}/board_actions.py (100%) rename zerver/{views/webhooks/trello => webhooks/trello/view}/card_actions.py (100%) rename zerver/{views/webhooks/trello => webhooks/trello/view}/exceptions.py (100%) rename zerver/{views/webhooks/trello => webhooks/trello/view}/templates.py (100%) create mode 100644 zerver/webhooks/updown/__init__.py rename zerver/{tests/webhooks/test_updown.py => webhooks/updown/tests.py} (100%) rename zerver/{views/webhooks/updown.py => webhooks/updown/view.py} (100%) create mode 100644 zerver/webhooks/yo/__init__.py rename zerver/{tests/webhooks/test_yo.py => webhooks/yo/tests.py} (100%) rename zerver/{views/webhooks/yo.py => webhooks/yo/view.py} (100%) create mode 100644 zerver/webhooks/zapier/__init__.py rename zerver/{tests/webhooks/test_zapier.py => webhooks/zapier/tests.py} (100%) rename zerver/{views/webhooks/zapier.py => webhooks/zapier/view.py} (100%) create mode 100644 zerver/webhooks/zendesk/__init__.py rename zerver/{tests/webhooks/test_zendesk.py => webhooks/zendesk/tests.py} (100%) rename zerver/{views/webhooks/zendesk.py => webhooks/zendesk/view.py} (100%) diff --git a/tools/test-backend b/tools/test-backend index cf99f07c5f..00416cb55b 100755 --- a/tools/test-backend +++ b/tools/test-backend @@ -128,6 +128,7 @@ if __name__ == "__main__": if len(args) == 0: suites = ["zerver.tests", + "zerver.webhooks", "analytics.tests"] else: suites = args diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py index 4c895902ea..06a7600a85 100644 --- a/zerver/lib/integrations.py +++ b/zerver/lib/integrations.py @@ -48,7 +48,7 @@ class EmailIntegration(Integration): return settings.EMAIL_GATEWAY_BOT != "" class WebhookIntegration(Integration): - DEFAULT_FUNCTION_PATH = 'zerver.views.webhooks.{name}.api_{name}_webhook' + DEFAULT_FUNCTION_PATH = 'zerver.webhooks.{name}.view.api_{name}_webhook' DEFAULT_URL = 'api/v1/external/{name}' DEFAULT_CLIENT_NAME = 'Zulip{name}Webhook' @@ -114,7 +114,7 @@ WEBHOOK_INTEGRATIONS = [ WebhookIntegration('freshdesk'), GithubIntegration( 'github', - function='zerver.views.webhooks.github.api_github_landing', + function='zerver.webhooks.github.view.api_github_landing', display_name='GitHub', secondary_line_text='(deprecated)' ), @@ -123,14 +123,14 @@ WEBHOOK_INTEGRATIONS = [ display_name='GitHub', logo='static/images/integrations/logos/github.png', secondary_line_text='(webhook)', - function='zerver.views.webhooks.github_webhook.api_github_webhook' + function='zerver.webhooks.github_webhook.view.api_github_webhook' ), WebhookIntegration('gitlab', display_name='GitLab'), WebhookIntegration('gosquared', display_name='GoSquared'), WebhookIntegration('hellosign', display_name='HelloSign'), WebhookIntegration('helloworld', display_name='Hello World'), WebhookIntegration('heroku', display_name='Heroku'), - WebhookIntegration('ifttt', function='zerver.views.webhooks.ifttt.api_iftt_app_webhook', display_name='IFTTT'), + WebhookIntegration('ifttt', function='zerver.webhooks.ifttt.view.api_iftt_app_webhook', display_name='IFTTT'), WebhookIntegration('jira', secondary_line_text='(hosted or v5.2+)', display_name='JIRA'), WebhookIntegration('librato'), WebhookIntegration('mention', display_name='Mention'), @@ -152,7 +152,7 @@ WEBHOOK_INTEGRATIONS = [ WebhookIntegration('updown'), WebhookIntegration( 'yo', - function='zerver.views.webhooks.yo.api_yo_app_webhook', + function='zerver.webhooks.yo.view.api_yo_app_webhook', logo='static/images/integrations/logos/yo-app.png', display_name='Yo App' ), diff --git a/zerver/tests/webhooks/__init__.py b/zerver/webhooks/__init__.py similarity index 100% rename from zerver/tests/webhooks/__init__.py rename to zerver/webhooks/__init__.py diff --git a/zerver/views/webhooks/__init__.py b/zerver/webhooks/airbrake/__init__.py similarity index 100% rename from zerver/views/webhooks/__init__.py rename to zerver/webhooks/airbrake/__init__.py diff --git a/zerver/tests/webhooks/test_airbrake.py b/zerver/webhooks/airbrake/tests.py similarity index 100% rename from zerver/tests/webhooks/test_airbrake.py rename to zerver/webhooks/airbrake/tests.py diff --git a/zerver/views/webhooks/airbrake.py b/zerver/webhooks/airbrake/view.py similarity index 100% rename from zerver/views/webhooks/airbrake.py rename to zerver/webhooks/airbrake/view.py diff --git a/zerver/webhooks/appfollow/__init__.py b/zerver/webhooks/appfollow/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_appfollow.py b/zerver/webhooks/appfollow/tests.py similarity index 97% rename from zerver/tests/webhooks/test_appfollow.py rename to zerver/webhooks/appfollow/tests.py index 36b5dedaaa..851b6b3cc5 100644 --- a/zerver/tests/webhooks/test_appfollow.py +++ b/zerver/webhooks/appfollow/tests.py @@ -3,7 +3,7 @@ from typing import Text from zerver.lib.test_classes import WebhookTestCase from django.test import TestCase -from zerver.views.webhooks.appfollow import convert_markdown +from zerver.webhooks.appfollow.view import convert_markdown class AppFollowHookTests(WebhookTestCase): STREAM_NAME = 'appfollow' diff --git a/zerver/views/webhooks/appfollow.py b/zerver/webhooks/appfollow/view.py similarity index 100% rename from zerver/views/webhooks/appfollow.py rename to zerver/webhooks/appfollow/view.py diff --git a/zerver/webhooks/beanstalk/__init__.py b/zerver/webhooks/beanstalk/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_beanstalk.py b/zerver/webhooks/beanstalk/tests.py similarity index 100% rename from zerver/tests/webhooks/test_beanstalk.py rename to zerver/webhooks/beanstalk/tests.py diff --git a/zerver/views/webhooks/beanstalk.py b/zerver/webhooks/beanstalk/view.py similarity index 98% rename from zerver/views/webhooks/beanstalk.py rename to zerver/webhooks/beanstalk/view.py index bb7f88cad4..feec93bd9e 100644 --- a/zerver/views/webhooks/beanstalk.py +++ b/zerver/webhooks/beanstalk/view.py @@ -11,7 +11,7 @@ from zerver.decorator import REQ, has_request_variables, authenticated_rest_api_ import base64 from functools import wraps -from .github import build_message_from_gitlog +from zerver.webhooks.github.view import build_message_from_gitlog from typing import Any, Callable, Dict, TypeVar from zerver.lib.str_utils import force_str, force_bytes diff --git a/zerver/webhooks/bitbucket/__init__.py b/zerver/webhooks/bitbucket/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/webhooks/bitbucket/tests.py b/zerver/webhooks/bitbucket/tests.py new file mode 100644 index 0000000000..8d75e04c6c --- /dev/null +++ b/zerver/webhooks/bitbucket/tests.py @@ -0,0 +1,50 @@ +# -*- coding: utf-8 -*- +from six import text_type +from typing import Union +from zerver.lib.test_classes import WebhookTestCase + +class BitbucketHookTests(WebhookTestCase): + STREAM_NAME = 'bitbucket' + URL_TEMPLATE = "/api/v1/external/bitbucket?payload={payload}&stream={stream}" + FIXTURE_DIR_NAME = 'bitbucket' + EXPECTED_SUBJECT = u"Repository name" + EXPECTED_SUBJECT_BRANCH_EVENTS = u"Repository name / master" + + def test_bitbucket_on_push_event(self): + # type: () -> None + fixture_name = 'push' + self.url = self.build_url(fixture_name) + commit_info = u'* [25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12): c' + expected_message = u"kolaszek pushed to branch master\n\n{}".format(commit_info) + self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL)) + + def test_bitbucket_on_push_commits_above_limit_event(self): + # type: () -> None + fixture_name = 'push_commits_above_limit' + self.url = self.build_url(fixture_name) + commit_info = u'* [25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12): c\n' + expected_message = u"kolaszek pushed to branch master\n\n{}[and 40 more commit(s)]".format(commit_info * 10) + self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL)) + + def test_bitbucket_on_force_push_event(self): + # type: () -> None + fixture_name = 'force_push' + self.url = self.build_url(fixture_name) + expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name)" + self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT, expected_message, **self.api_auth(self.TEST_USER_EMAIL)) + + def get_body(self, fixture_name): + # type: (text_type) -> Union[text_type, Dict[str, text_type]] + return {} + + def get_payload(self, fixture_name): + # type: (text_type) -> Union[text_type, Dict[str, text_type]] + return self.fixture_data(self.FIXTURE_DIR_NAME, fixture_name) + + def build_webhook_url(self): + # type: () -> text_type + return '' + + def build_url(self, fixture_name): + # type: (text_type) -> text_type + return self.URL_TEMPLATE.format(payload=self.get_payload(fixture_name), stream=self.STREAM_NAME) diff --git a/zerver/views/webhooks/bitbucket.py b/zerver/webhooks/bitbucket/view.py similarity index 100% rename from zerver/views/webhooks/bitbucket.py rename to zerver/webhooks/bitbucket/view.py diff --git a/zerver/webhooks/bitbucket2/__init__.py b/zerver/webhooks/bitbucket2/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_bitbucket.py b/zerver/webhooks/bitbucket2/tests.py similarity index 82% rename from zerver/tests/webhooks/test_bitbucket.py rename to zerver/webhooks/bitbucket2/tests.py index 2f9775c0a6..8911858259 100644 --- a/zerver/tests/webhooks/test_bitbucket.py +++ b/zerver/webhooks/bitbucket2/tests.py @@ -1,6 +1,4 @@ # -*- coding: utf-8 -*- -from typing import Union, Text -from zerver.lib.webhooks.git import COMMITS_LIMIT from zerver.lib.test_classes import WebhookTestCase class Bitbucket2HookTests(WebhookTestCase): @@ -180,49 +178,3 @@ class Bitbucket2HookTests(WebhookTestCase): msg = self.get_last_message() self.do_test_message(msg, 'kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)') self.do_test_subject(msg, self.EXPECTED_SUBJECT) - -class BitbucketHookTests(WebhookTestCase): - STREAM_NAME = 'bitbucket' - URL_TEMPLATE = "/api/v1/external/bitbucket?payload={payload}&stream={stream}" - FIXTURE_DIR_NAME = 'bitbucket' - EXPECTED_SUBJECT = u"Repository name" - EXPECTED_SUBJECT_BRANCH_EVENTS = u"Repository name / master" - - def test_bitbucket_on_push_event(self): - # type: () -> None - fixture_name = 'push' - self.url = self.build_url(fixture_name) - commit_info = u'* [25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12): c' - expected_message = u"kolaszek pushed to branch master\n\n{}".format(commit_info) - self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL)) - - def test_bitbucket_on_push_commits_above_limit_event(self): - # type: () -> None - fixture_name = 'push_commits_above_limit' - self.url = self.build_url(fixture_name) - commit_info = u'* [25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12): c\n' - expected_message = u"kolaszek pushed to branch master\n\n{}[and 40 more commit(s)]".format(commit_info * 10) - self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL)) - - def test_bitbucket_on_force_push_event(self): - # type: () -> None - fixture_name = 'force_push' - self.url = self.build_url(fixture_name) - expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name)" - self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT, expected_message, **self.api_auth(self.TEST_USER_EMAIL)) - - def get_body(self, fixture_name): - # type: (Text) -> Union[Text, Dict[str, Text]] - return {} - - def get_payload(self, fixture_name): - # type: (Text) -> Union[Text, Dict[str, Text]] - return self.fixture_data(self.FIXTURE_DIR_NAME, fixture_name) - - def build_webhook_url(self): - # type: () -> Text - return '' - - def build_url(self, fixture_name): - # type: (Text) -> Text - return self.URL_TEMPLATE.format(payload=self.get_payload(fixture_name), stream=self.STREAM_NAME) diff --git a/zerver/views/webhooks/bitbucket2.py b/zerver/webhooks/bitbucket2/view.py similarity index 100% rename from zerver/views/webhooks/bitbucket2.py rename to zerver/webhooks/bitbucket2/view.py diff --git a/zerver/webhooks/circleci/__init__.py b/zerver/webhooks/circleci/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_circleci.py b/zerver/webhooks/circleci/tests.py similarity index 100% rename from zerver/tests/webhooks/test_circleci.py rename to zerver/webhooks/circleci/tests.py diff --git a/zerver/views/webhooks/circleci.py b/zerver/webhooks/circleci/view.py similarity index 100% rename from zerver/views/webhooks/circleci.py rename to zerver/webhooks/circleci/view.py diff --git a/zerver/webhooks/codeship/__init__.py b/zerver/webhooks/codeship/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_codeship.py b/zerver/webhooks/codeship/tests.py similarity index 100% rename from zerver/tests/webhooks/test_codeship.py rename to zerver/webhooks/codeship/tests.py diff --git a/zerver/views/webhooks/codeship.py b/zerver/webhooks/codeship/view.py similarity index 100% rename from zerver/views/webhooks/codeship.py rename to zerver/webhooks/codeship/view.py diff --git a/zerver/webhooks/crashlytics/__init__.py b/zerver/webhooks/crashlytics/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_crashlytics.py b/zerver/webhooks/crashlytics/tests.py similarity index 100% rename from zerver/tests/webhooks/test_crashlytics.py rename to zerver/webhooks/crashlytics/tests.py diff --git a/zerver/views/webhooks/crashlytics.py b/zerver/webhooks/crashlytics/view.py similarity index 100% rename from zerver/views/webhooks/crashlytics.py rename to zerver/webhooks/crashlytics/view.py diff --git a/zerver/webhooks/delighted/__init__.py b/zerver/webhooks/delighted/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_delighted.py b/zerver/webhooks/delighted/tests.py similarity index 100% rename from zerver/tests/webhooks/test_delighted.py rename to zerver/webhooks/delighted/tests.py diff --git a/zerver/views/webhooks/delighted.py b/zerver/webhooks/delighted/view.py similarity index 100% rename from zerver/views/webhooks/delighted.py rename to zerver/webhooks/delighted/view.py diff --git a/zerver/webhooks/deskdotcom/__init__.py b/zerver/webhooks/deskdotcom/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_deskdotcom.py b/zerver/webhooks/deskdotcom/tests.py similarity index 100% rename from zerver/tests/webhooks/test_deskdotcom.py rename to zerver/webhooks/deskdotcom/tests.py diff --git a/zerver/views/webhooks/deskdotcom.py b/zerver/webhooks/deskdotcom/view.py similarity index 100% rename from zerver/views/webhooks/deskdotcom.py rename to zerver/webhooks/deskdotcom/view.py diff --git a/zerver/webhooks/freshdesk/__init__.py b/zerver/webhooks/freshdesk/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_freshdesk.py b/zerver/webhooks/freshdesk/tests.py similarity index 100% rename from zerver/tests/webhooks/test_freshdesk.py rename to zerver/webhooks/freshdesk/tests.py diff --git a/zerver/views/webhooks/freshdesk.py b/zerver/webhooks/freshdesk/view.py similarity index 100% rename from zerver/views/webhooks/freshdesk.py rename to zerver/webhooks/freshdesk/view.py diff --git a/zerver/webhooks/github/__init__.py b/zerver/webhooks/github/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_github.py b/zerver/webhooks/github/tests.py similarity index 100% rename from zerver/tests/webhooks/test_github.py rename to zerver/webhooks/github/tests.py diff --git a/zerver/views/webhooks/github.py b/zerver/webhooks/github/view.py similarity index 100% rename from zerver/views/webhooks/github.py rename to zerver/webhooks/github/view.py diff --git a/zerver/views/webhooks/github_dispatcher.py b/zerver/webhooks/github_dispatcher.py similarity index 83% rename from zerver/views/webhooks/github_dispatcher.py rename to zerver/webhooks/github_dispatcher.py index 420bf10c1e..0a2e587610 100644 --- a/zerver/views/webhooks/github_dispatcher.py +++ b/zerver/webhooks/github_dispatcher.py @@ -1,8 +1,8 @@ from __future__ import absolute_import from django.http import HttpRequest, HttpResponse from django.views.decorators.csrf import csrf_exempt -from .github_webhook import api_github_webhook -from .github import api_github_landing +from .github_webhook.view import api_github_webhook +from .github.view import api_github_landing # Since this dispatcher is an API-style endpoint, it needs to be # explicitly marked as CSRF-exempt diff --git a/zerver/webhooks/github_webhook/__init__.py b/zerver/webhooks/github_webhook/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_github_webhook.py b/zerver/webhooks/github_webhook/tests.py similarity index 100% rename from zerver/tests/webhooks/test_github_webhook.py rename to zerver/webhooks/github_webhook/tests.py diff --git a/zerver/views/webhooks/github_webhook.py b/zerver/webhooks/github_webhook/view.py similarity index 100% rename from zerver/views/webhooks/github_webhook.py rename to zerver/webhooks/github_webhook/view.py diff --git a/zerver/webhooks/gitlab/__init__.py b/zerver/webhooks/gitlab/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_gitlab.py b/zerver/webhooks/gitlab/tests.py similarity index 100% rename from zerver/tests/webhooks/test_gitlab.py rename to zerver/webhooks/gitlab/tests.py diff --git a/zerver/views/webhooks/gitlab.py b/zerver/webhooks/gitlab/view.py similarity index 100% rename from zerver/views/webhooks/gitlab.py rename to zerver/webhooks/gitlab/view.py diff --git a/zerver/webhooks/gosquared/__init__.py b/zerver/webhooks/gosquared/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_gosquared.py b/zerver/webhooks/gosquared/tests.py similarity index 100% rename from zerver/tests/webhooks/test_gosquared.py rename to zerver/webhooks/gosquared/tests.py diff --git a/zerver/views/webhooks/gosquared.py b/zerver/webhooks/gosquared/view.py similarity index 100% rename from zerver/views/webhooks/gosquared.py rename to zerver/webhooks/gosquared/view.py diff --git a/zerver/webhooks/hellosign/__init__.py b/zerver/webhooks/hellosign/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_hellosign.py b/zerver/webhooks/hellosign/tests.py similarity index 100% rename from zerver/tests/webhooks/test_hellosign.py rename to zerver/webhooks/hellosign/tests.py diff --git a/zerver/views/webhooks/hellosign.py b/zerver/webhooks/hellosign/view.py similarity index 100% rename from zerver/views/webhooks/hellosign.py rename to zerver/webhooks/hellosign/view.py diff --git a/zerver/webhooks/helloworld/__init__.py b/zerver/webhooks/helloworld/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_hello_world.py b/zerver/webhooks/helloworld/tests.py similarity index 100% rename from zerver/tests/webhooks/test_hello_world.py rename to zerver/webhooks/helloworld/tests.py diff --git a/zerver/views/webhooks/helloworld.py b/zerver/webhooks/helloworld/view.py similarity index 100% rename from zerver/views/webhooks/helloworld.py rename to zerver/webhooks/helloworld/view.py diff --git a/zerver/webhooks/heroku/__init__.py b/zerver/webhooks/heroku/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_heroku.py b/zerver/webhooks/heroku/tests.py similarity index 100% rename from zerver/tests/webhooks/test_heroku.py rename to zerver/webhooks/heroku/tests.py diff --git a/zerver/views/webhooks/heroku.py b/zerver/webhooks/heroku/view.py similarity index 100% rename from zerver/views/webhooks/heroku.py rename to zerver/webhooks/heroku/view.py diff --git a/zerver/webhooks/ifttt/__init__.py b/zerver/webhooks/ifttt/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_IFTTT.py b/zerver/webhooks/ifttt/tests.py similarity index 100% rename from zerver/tests/webhooks/test_IFTTT.py rename to zerver/webhooks/ifttt/tests.py diff --git a/zerver/views/webhooks/ifttt.py b/zerver/webhooks/ifttt/view.py similarity index 100% rename from zerver/views/webhooks/ifttt.py rename to zerver/webhooks/ifttt/view.py diff --git a/zerver/webhooks/jira/__init__.py b/zerver/webhooks/jira/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_jira.py b/zerver/webhooks/jira/tests.py similarity index 100% rename from zerver/tests/webhooks/test_jira.py rename to zerver/webhooks/jira/tests.py diff --git a/zerver/views/webhooks/jira.py b/zerver/webhooks/jira/view.py similarity index 100% rename from zerver/views/webhooks/jira.py rename to zerver/webhooks/jira/view.py diff --git a/zerver/webhooks/librato/__init__.py b/zerver/webhooks/librato/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_librato.py b/zerver/webhooks/librato/tests.py similarity index 100% rename from zerver/tests/webhooks/test_librato.py rename to zerver/webhooks/librato/tests.py diff --git a/zerver/views/webhooks/librato.py b/zerver/webhooks/librato/view.py similarity index 100% rename from zerver/views/webhooks/librato.py rename to zerver/webhooks/librato/view.py diff --git a/zerver/webhooks/mention/__init__.py b/zerver/webhooks/mention/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_mention.py b/zerver/webhooks/mention/tests.py similarity index 100% rename from zerver/tests/webhooks/test_mention.py rename to zerver/webhooks/mention/tests.py diff --git a/zerver/views/webhooks/mention.py b/zerver/webhooks/mention/view.py similarity index 100% rename from zerver/views/webhooks/mention.py rename to zerver/webhooks/mention/view.py diff --git a/zerver/webhooks/newrelic/__init__.py b/zerver/webhooks/newrelic/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_new_relic.py b/zerver/webhooks/newrelic/tests.py similarity index 100% rename from zerver/tests/webhooks/test_new_relic.py rename to zerver/webhooks/newrelic/tests.py diff --git a/zerver/views/webhooks/newrelic.py b/zerver/webhooks/newrelic/view.py similarity index 100% rename from zerver/views/webhooks/newrelic.py rename to zerver/webhooks/newrelic/view.py diff --git a/zerver/webhooks/pagerduty/__init__.py b/zerver/webhooks/pagerduty/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_pagerduty.py b/zerver/webhooks/pagerduty/tests.py similarity index 100% rename from zerver/tests/webhooks/test_pagerduty.py rename to zerver/webhooks/pagerduty/tests.py diff --git a/zerver/views/webhooks/pagerduty.py b/zerver/webhooks/pagerduty/view.py similarity index 100% rename from zerver/views/webhooks/pagerduty.py rename to zerver/webhooks/pagerduty/view.py diff --git a/zerver/webhooks/papertrail/__init__.py b/zerver/webhooks/papertrail/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_papertrail.py b/zerver/webhooks/papertrail/tests.py similarity index 100% rename from zerver/tests/webhooks/test_papertrail.py rename to zerver/webhooks/papertrail/tests.py diff --git a/zerver/views/webhooks/papertrail.py b/zerver/webhooks/papertrail/view.py similarity index 100% rename from zerver/views/webhooks/papertrail.py rename to zerver/webhooks/papertrail/view.py diff --git a/zerver/webhooks/pingdom/__init__.py b/zerver/webhooks/pingdom/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_pingdom.py b/zerver/webhooks/pingdom/tests.py similarity index 100% rename from zerver/tests/webhooks/test_pingdom.py rename to zerver/webhooks/pingdom/tests.py diff --git a/zerver/views/webhooks/pingdom.py b/zerver/webhooks/pingdom/view.py similarity index 100% rename from zerver/views/webhooks/pingdom.py rename to zerver/webhooks/pingdom/view.py diff --git a/zerver/webhooks/pivotal/__init__.py b/zerver/webhooks/pivotal/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_pivotal.py b/zerver/webhooks/pivotal/tests.py similarity index 100% rename from zerver/tests/webhooks/test_pivotal.py rename to zerver/webhooks/pivotal/tests.py diff --git a/zerver/views/webhooks/pivotal.py b/zerver/webhooks/pivotal/view.py similarity index 100% rename from zerver/views/webhooks/pivotal.py rename to zerver/webhooks/pivotal/view.py diff --git a/zerver/webhooks/semaphore/__init__.py b/zerver/webhooks/semaphore/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_semaphore.py b/zerver/webhooks/semaphore/tests.py similarity index 100% rename from zerver/tests/webhooks/test_semaphore.py rename to zerver/webhooks/semaphore/tests.py diff --git a/zerver/views/webhooks/semaphore.py b/zerver/webhooks/semaphore/view.py similarity index 100% rename from zerver/views/webhooks/semaphore.py rename to zerver/webhooks/semaphore/view.py diff --git a/zerver/webhooks/sentry/__init__.py b/zerver/webhooks/sentry/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_sentry.py b/zerver/webhooks/sentry/tests.py similarity index 100% rename from zerver/tests/webhooks/test_sentry.py rename to zerver/webhooks/sentry/tests.py diff --git a/zerver/views/webhooks/sentry.py b/zerver/webhooks/sentry/view.py similarity index 100% rename from zerver/views/webhooks/sentry.py rename to zerver/webhooks/sentry/view.py diff --git a/zerver/webhooks/solano/__init__.py b/zerver/webhooks/solano/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_solano.py b/zerver/webhooks/solano/tests.py similarity index 100% rename from zerver/tests/webhooks/test_solano.py rename to zerver/webhooks/solano/tests.py diff --git a/zerver/views/webhooks/solano.py b/zerver/webhooks/solano/view.py similarity index 100% rename from zerver/views/webhooks/solano.py rename to zerver/webhooks/solano/view.py diff --git a/zerver/webhooks/stash/__init__.py b/zerver/webhooks/stash/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_stash.py b/zerver/webhooks/stash/tests.py similarity index 100% rename from zerver/tests/webhooks/test_stash.py rename to zerver/webhooks/stash/tests.py diff --git a/zerver/views/webhooks/stash.py b/zerver/webhooks/stash/view.py similarity index 100% rename from zerver/views/webhooks/stash.py rename to zerver/webhooks/stash/view.py diff --git a/zerver/webhooks/stripe/__init__.py b/zerver/webhooks/stripe/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_stripe.py b/zerver/webhooks/stripe/tests.py similarity index 100% rename from zerver/tests/webhooks/test_stripe.py rename to zerver/webhooks/stripe/tests.py diff --git a/zerver/views/webhooks/stripe.py b/zerver/webhooks/stripe/view.py similarity index 100% rename from zerver/views/webhooks/stripe.py rename to zerver/webhooks/stripe/view.py diff --git a/zerver/webhooks/taiga/__init__.py b/zerver/webhooks/taiga/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_taiga.py b/zerver/webhooks/taiga/tests.py similarity index 100% rename from zerver/tests/webhooks/test_taiga.py rename to zerver/webhooks/taiga/tests.py diff --git a/zerver/views/webhooks/taiga.py b/zerver/webhooks/taiga/view.py similarity index 100% rename from zerver/views/webhooks/taiga.py rename to zerver/webhooks/taiga/view.py diff --git a/zerver/webhooks/teamcity/__init__.py b/zerver/webhooks/teamcity/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_teamcity.py b/zerver/webhooks/teamcity/tests.py similarity index 100% rename from zerver/tests/webhooks/test_teamcity.py rename to zerver/webhooks/teamcity/tests.py diff --git a/zerver/views/webhooks/teamcity.py b/zerver/webhooks/teamcity/view.py similarity index 100% rename from zerver/views/webhooks/teamcity.py rename to zerver/webhooks/teamcity/view.py diff --git a/zerver/webhooks/transifex/__init__.py b/zerver/webhooks/transifex/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_transifex.py b/zerver/webhooks/transifex/tests.py similarity index 100% rename from zerver/tests/webhooks/test_transifex.py rename to zerver/webhooks/transifex/tests.py diff --git a/zerver/views/webhooks/transifex.py b/zerver/webhooks/transifex/view.py similarity index 100% rename from zerver/views/webhooks/transifex.py rename to zerver/webhooks/transifex/view.py diff --git a/zerver/webhooks/travis/__init__.py b/zerver/webhooks/travis/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_travis.py b/zerver/webhooks/travis/tests.py similarity index 100% rename from zerver/tests/webhooks/test_travis.py rename to zerver/webhooks/travis/tests.py diff --git a/zerver/views/webhooks/travis.py b/zerver/webhooks/travis/view.py similarity index 100% rename from zerver/views/webhooks/travis.py rename to zerver/webhooks/travis/view.py diff --git a/zerver/webhooks/trello/__init__.py b/zerver/webhooks/trello/__init__.py new file mode 100644 index 0000000000..7017645a31 --- /dev/null +++ b/zerver/webhooks/trello/__init__.py @@ -0,0 +1,38 @@ +# Webhooks for external integrations. +from __future__ import absolute_import +import ujson +from typing import Mapping, Any, Tuple, Text +from django.utils.translation import ugettext as _ +from django.http import HttpRequest, HttpResponse +from zerver.lib.actions import check_send_message +from zerver.decorator import return_success_on_head_request +from zerver.lib.response import json_success, json_error +from zerver.models import UserProfile, Client +from zerver.decorator import REQ, has_request_variables, api_key_only_webhook_view + +from .view.card_actions import SUPPORTED_CARD_ACTIONS, process_card_action +from .view.board_actions import SUPPORTED_BOARD_ACTIONS, process_board_action +from .view.exceptions import UnsupportedAction + +@api_key_only_webhook_view('Trello') +@return_success_on_head_request +@has_request_variables +def api_trello_webhook(request, user_profile, client, payload=REQ(argument_type='body'), stream=REQ(default='trello')): + # type: (HttpRequest, UserProfile, Client, Mapping[str, Any], Text) -> HttpResponse + payload = ujson.loads(request.body) + action_type = payload.get('action').get('type') + try: + subject, body = get_subject_and_body(payload, action_type) + except UnsupportedAction: + return json_error(_('Unsupported action_type: {action_type}'.format(action_type=action_type))) + + check_send_message(user_profile, client, 'stream', [stream], subject, body) + return json_success() + +def get_subject_and_body(payload, action_type): + # type: (Mapping[str, Any], Text) -> Tuple[Text, Text] + if action_type in SUPPORTED_CARD_ACTIONS: + return process_card_action(payload, action_type) + if action_type in SUPPORTED_BOARD_ACTIONS: + return process_board_action(payload, action_type) + raise UnsupportedAction('{} if not supported'.format(action_type)) diff --git a/zerver/tests/webhooks/test_trello.py b/zerver/webhooks/trello/tests.py similarity index 100% rename from zerver/tests/webhooks/test_trello.py rename to zerver/webhooks/trello/tests.py diff --git a/zerver/views/webhooks/trello/__init__.py b/zerver/webhooks/trello/view/__init__.py similarity index 100% rename from zerver/views/webhooks/trello/__init__.py rename to zerver/webhooks/trello/view/__init__.py diff --git a/zerver/views/webhooks/trello/board_actions.py b/zerver/webhooks/trello/view/board_actions.py similarity index 100% rename from zerver/views/webhooks/trello/board_actions.py rename to zerver/webhooks/trello/view/board_actions.py diff --git a/zerver/views/webhooks/trello/card_actions.py b/zerver/webhooks/trello/view/card_actions.py similarity index 100% rename from zerver/views/webhooks/trello/card_actions.py rename to zerver/webhooks/trello/view/card_actions.py diff --git a/zerver/views/webhooks/trello/exceptions.py b/zerver/webhooks/trello/view/exceptions.py similarity index 100% rename from zerver/views/webhooks/trello/exceptions.py rename to zerver/webhooks/trello/view/exceptions.py diff --git a/zerver/views/webhooks/trello/templates.py b/zerver/webhooks/trello/view/templates.py similarity index 100% rename from zerver/views/webhooks/trello/templates.py rename to zerver/webhooks/trello/view/templates.py diff --git a/zerver/webhooks/updown/__init__.py b/zerver/webhooks/updown/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_updown.py b/zerver/webhooks/updown/tests.py similarity index 100% rename from zerver/tests/webhooks/test_updown.py rename to zerver/webhooks/updown/tests.py diff --git a/zerver/views/webhooks/updown.py b/zerver/webhooks/updown/view.py similarity index 100% rename from zerver/views/webhooks/updown.py rename to zerver/webhooks/updown/view.py diff --git a/zerver/webhooks/yo/__init__.py b/zerver/webhooks/yo/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_yo.py b/zerver/webhooks/yo/tests.py similarity index 100% rename from zerver/tests/webhooks/test_yo.py rename to zerver/webhooks/yo/tests.py diff --git a/zerver/views/webhooks/yo.py b/zerver/webhooks/yo/view.py similarity index 100% rename from zerver/views/webhooks/yo.py rename to zerver/webhooks/yo/view.py diff --git a/zerver/webhooks/zapier/__init__.py b/zerver/webhooks/zapier/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_zapier.py b/zerver/webhooks/zapier/tests.py similarity index 100% rename from zerver/tests/webhooks/test_zapier.py rename to zerver/webhooks/zapier/tests.py diff --git a/zerver/views/webhooks/zapier.py b/zerver/webhooks/zapier/view.py similarity index 100% rename from zerver/views/webhooks/zapier.py rename to zerver/webhooks/zapier/view.py diff --git a/zerver/webhooks/zendesk/__init__.py b/zerver/webhooks/zendesk/__init__.py new file mode 100644 index 0000000000..e69de29bb2 diff --git a/zerver/tests/webhooks/test_zendesk.py b/zerver/webhooks/zendesk/tests.py similarity index 100% rename from zerver/tests/webhooks/test_zendesk.py rename to zerver/webhooks/zendesk/tests.py diff --git a/zerver/views/webhooks/zendesk.py b/zerver/webhooks/zendesk/view.py similarity index 100% rename from zerver/views/webhooks/zendesk.py rename to zerver/webhooks/zendesk/view.py diff --git a/zproject/urls.py b/zproject/urls.py index 4a5385560c..8ff9154076 100644 --- a/zproject/urls.py +++ b/zproject/urls.py @@ -9,7 +9,7 @@ from zproject import dev_urls from zproject.legacy_urls import legacy_urls from zerver.views.integrations import IntegrationView, APIView, HelpView from zerver.lib.integrations import WEBHOOK_INTEGRATIONS -from zerver.views.webhooks import github_dispatcher +from zerver.webhooks import github_dispatcher from django.contrib.auth.views import (login, password_reset,