mirror of
https://github.com/zulip/zulip.git
synced 2025-11-05 06:23:38 +00:00
webhooks: Stop overriding build_webhook_url for URL query parameters.
This commit is contained in:
@@ -18,14 +18,6 @@ class GithubWebhookTest(WebhookTestCase):
|
||||
EXPECTED_SUBJECT_BRANCH_EVENTS = u"public-repo / changes"
|
||||
EXPECTED_SUBJECT_WIKI_EVENTS = u"public-repo / Wiki Pages"
|
||||
|
||||
def build_webhook_url(self, branches=None):
|
||||
# type: (Optional[Text]) -> Text
|
||||
api_key = self.get_api_key(self.TEST_USER_EMAIL)
|
||||
url = self.URL_TEMPLATE.format(stream=self.STREAM_NAME, api_key=api_key)
|
||||
if branches:
|
||||
url = "{}&branches={}".format(url, branches)
|
||||
return url
|
||||
|
||||
def test_ping_event(self):
|
||||
# type: () -> None
|
||||
expected_message = u"GitHub webhook has been successfully configured by TomaszKolek"
|
||||
@@ -56,6 +48,22 @@ class GithubWebhookTest(WebhookTestCase):
|
||||
|
||||
self.send_and_test_stream_message('push_multiple_committers_with_others', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='push')
|
||||
|
||||
def test_push_multiple_comitters_filtered_by_branches(self):
|
||||
# type: () -> None
|
||||
self.url = self.build_webhook_url('master,changes')
|
||||
commits_info = u'* Update README.md ([0d1a26e](https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c))\n'
|
||||
expected_message = u"""baxterthehacker [pushed](https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f) 6 commits to branch changes. Commits by Tomasz(3), Ben(2) and baxterthehacker(1)\n\n{}* Update README.md ([0d1a26e](https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c))""".format(commits_info * 5)
|
||||
|
||||
self.send_and_test_stream_message('push_multiple_committers', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='push')
|
||||
|
||||
def test_push_multiple_comitters_with_others_filtered_by_branches(self):
|
||||
# type: () -> None
|
||||
self.url = self.build_webhook_url('master,changes')
|
||||
commits_info = u'* Update README.md ([0d1a26e](https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c))\n'
|
||||
expected_message = u"""baxterthehacker [pushed](https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f) 10 commits to branch changes. Commits by Tomasz(4), Ben(3), James(2) and others(1)\n\n{}* Update README.md ([0d1a26e](https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c))""".format(commits_info * 9)
|
||||
|
||||
self.send_and_test_stream_message('push_multiple_committers_with_others', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, HTTP_X_GITHUB_EVENT='push')
|
||||
|
||||
def test_push_50_commits(self):
|
||||
# type: () -> None
|
||||
commit_info = "* Update README.md ([0d1a26e](https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c))\n"
|
||||
@@ -66,7 +74,7 @@ class GithubWebhookTest(WebhookTestCase):
|
||||
|
||||
def test_push_50_commits_filtered_by_branches(self):
|
||||
# type: () -> None
|
||||
self.url = self.build_webhook_url('master,changes')
|
||||
self.url = self.build_webhook_url(branches='master,changes')
|
||||
commit_info = "* Update README.md ([0d1a26e](https://github.com/baxterthehacker/public-repo/commit/0d1a26e67d8f5eaf1f6ba5c57fc3c7d91ac0fd1c))\n"
|
||||
expected_message = u"baxterthehacker [pushed](https://github.com/baxterthehacker/public-repo/compare/9049f1265b7d...0d1a26e67d8f) 50 commits to branch changes. Commits by baxterthehacker(50)\n\n{}[and 30 more commit(s)]".format(
|
||||
commit_info * COMMITS_LIMIT
|
||||
@@ -251,7 +259,7 @@ class GithubWebhookTest(WebhookTestCase):
|
||||
@patch('zerver.webhooks.github_webhook.view.check_send_message')
|
||||
def test_push_1_commit_filtered_by_branches_ignore(self, check_send_message_mock):
|
||||
# type: (MagicMock) -> None
|
||||
self.url = self.build_webhook_url('master,development')
|
||||
self.url = self.build_webhook_url(branches='master,development')
|
||||
payload = self.get_body('push_1_commit')
|
||||
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='push', content_type="application/json")
|
||||
self.assertFalse(check_send_message_mock.called)
|
||||
@@ -260,8 +268,26 @@ class GithubWebhookTest(WebhookTestCase):
|
||||
@patch('zerver.webhooks.github_webhook.view.check_send_message')
|
||||
def test_push_50_commits_filtered_by_branches_ignore(self, check_send_message_mock):
|
||||
# type: (MagicMock) -> None
|
||||
self.url = self.build_webhook_url('master,development')
|
||||
self.url = self.build_webhook_url(branches='master,development')
|
||||
payload = self.get_body('push_50_commits')
|
||||
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='push', content_type="application/json")
|
||||
self.assertFalse(check_send_message_mock.called)
|
||||
self.assert_json_success(result)
|
||||
|
||||
@patch('zerver.webhooks.github_webhook.view.check_send_message')
|
||||
def test_push_multiple_comitters_filtered_by_branches_ignore(self, check_send_message_mock):
|
||||
# type: (MagicMock) -> None
|
||||
self.url = self.build_webhook_url(branches='master,development')
|
||||
payload = self.get_body('push_multiple_committers')
|
||||
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='push', content_type="application/json")
|
||||
self.assertFalse(check_send_message_mock.called)
|
||||
self.assert_json_success(result)
|
||||
|
||||
@patch('zerver.webhooks.github_webhook.view.check_send_message')
|
||||
def test_push_multiple_comitters_with_others_filtered_by_branches_ignore(self, check_send_message_mock):
|
||||
# type: (MagicMock) -> None
|
||||
self.url = self.build_webhook_url(branches='master,development')
|
||||
payload = self.get_body('push_multiple_committers_with_others')
|
||||
result = self.client_post(self.url, payload, HTTP_X_GITHUB_EVENT='push', content_type="application/json")
|
||||
self.assertFalse(check_send_message_mock.called)
|
||||
self.assert_json_success(result)
|
||||
|
||||
Reference in New Issue
Block a user