diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.py index 3245fe70fb..b562f6ce47 100644 --- a/zerver/lib/test_classes.py +++ b/zerver/lib/test_classes.py @@ -536,11 +536,18 @@ class WebhookTestCase(ZulipTestCase): return msg - def build_webhook_url(self, **kwargs): - # type: (**Any) -> 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 kwargs and url.find('?') == -1: + def build_webhook_url(self, *args, **kwargs): + # type: (*Any, **Any) -> Text + url = self.URL_TEMPLATE + if url.find("api_key") >= 0: + api_key = self.get_api_key(self.TEST_USER_EMAIL) + url = self.URL_TEMPLATE.format(api_key=api_key, + stream=self.STREAM_NAME) + else: + url = self.URL_TEMPLATE.format(stream=self.STREAM_NAME) + + has_arguments = kwargs or args + if has_arguments and url.find('?') == -1: url = "{}?".format(url) else: url = "{}&".format(url) @@ -548,7 +555,10 @@ class WebhookTestCase(ZulipTestCase): for key, value in kwargs.items(): url = "{}{}={}&".format(url, key, value) - return url[:-1] if kwargs else url + for arg in args: + url = "{}{}&".format(url, arg) + + return url[:-1] if has_arguments else url def get_body(self, fixture_name): # type: (Text) -> Union[Text, Dict[str, Text]] diff --git a/zerver/webhooks/bitbucket/tests.py b/zerver/webhooks/bitbucket/tests.py index ad9e808d02..9cda5cd23a 100644 --- a/zerver/webhooks/bitbucket/tests.py +++ b/zerver/webhooks/bitbucket/tests.py @@ -5,7 +5,7 @@ from zerver.lib.test_classes import WebhookTestCase class BitbucketHookTests(WebhookTestCase): STREAM_NAME = 'bitbucket' - URL_TEMPLATE = "/api/v1/external/bitbucket?payload={payload}&stream={stream}" + URL_TEMPLATE = "/api/v1/external/bitbucket?stream={stream}" FIXTURE_DIR_NAME = 'bitbucket' EXPECTED_SUBJECT = u"Repository name" EXPECTED_SUBJECT_BRANCH_EVENTS = u"Repository name / master" @@ -13,7 +13,7 @@ class BitbucketHookTests(WebhookTestCase): def test_bitbucket_on_push_event(self): # type: () -> None fixture_name = 'push' - self.url = self.build_url(fixture_name) + self.url = self.build_webhook_url(payload=self.get_body(fixture_name)) commit_info = u'* c ([25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12))' expected_message = u"kolaszek pushed 1 commit to branch master. Commits by kolaszek(1)\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)) @@ -21,7 +21,7 @@ class BitbucketHookTests(WebhookTestCase): 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) + self.url = self.build_webhook_url(payload=self.get_body(fixture_name)) commit_info = u'* c ([25f93d2](https://bitbucket.org/kolaszek/repository-name/commits/25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12))\n' expected_message = u"kolaszek pushed 50 commits to branch master. Commits by kolaszek(50)\n\n{}[and 30 more commit(s)]".format(commit_info * 20) self.send_and_test_stream_message(fixture_name, self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message, **self.api_auth(self.TEST_USER_EMAIL)) @@ -29,22 +29,10 @@ class BitbucketHookTests(WebhookTestCase): def test_bitbucket_on_force_push_event(self): # type: () -> None fixture_name = 'force_push' - self.url = self.build_url(fixture_name) + self.url = self.build_webhook_url(payload=self.get_body(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/webhooks/freshdesk/tests.py b/zerver/webhooks/freshdesk/tests.py index 2f9fdab55e..7a3c572ad0 100644 --- a/zerver/webhooks/freshdesk/tests.py +++ b/zerver/webhooks/freshdesk/tests.py @@ -85,10 +85,6 @@ Priority: **High** => **Low**""" content_type="application/x-www-form-urlencoded", **self.api_auth(self.TEST_USER_EMAIL)) - def build_webhook_url(self): - # type: () -> Text - return self.URL_TEMPLATE.format(stream=self.STREAM_NAME) - def get_body(self, fixture_name): # type: (Text) -> Text return self.fixture_data("freshdesk", fixture_name, file_type="json") diff --git a/zerver/webhooks/github_webhook/tests.py b/zerver/webhooks/github_webhook/tests.py index 8c853f2c92..deb5f3f34c 100644 --- a/zerver/webhooks/github_webhook/tests.py +++ b/zerver/webhooks/github_webhook/tests.py @@ -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) diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py index 70678725e3..907e743579 100644 --- a/zerver/webhooks/gitlab/tests.py +++ b/zerver/webhooks/gitlab/tests.py @@ -7,17 +7,9 @@ from zerver.lib.test_classes import WebhookTestCase class GitlabHookTests(WebhookTestCase): STREAM_NAME = 'gitlab' - URL_TEMPLATE = "/api/v1/external/gitlab?&api_key={api_key}" + URL_TEMPLATE = "/api/v1/external/gitlab?&api_key={api_key}&stream={stream}" FIXTURE_DIR_NAME = 'gitlab' - 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(api_key=api_key) - if branches is not None: - url = "{}&branches={}".format(url, branches) - return url - def test_push_event_message(self): # type: () -> None expected_subject = u"my-awesome-project / tomek" @@ -26,7 +18,7 @@ class GitlabHookTests(WebhookTestCase): def test_push_event_message_filtered_by_branches(self): # type: () -> None - self.url = self.build_webhook_url('master,tomek') + self.url = self.build_webhook_url(branches='master,tomek') expected_subject = u"my-awesome-project / tomek" expected_message = u"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek. Commits by Tomasz Kolek(2)\n\n* b ([66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))" self.send_and_test_stream_message('push', expected_subject, expected_message, HTTP_X_GITLAB_EVENT="Push Hook") @@ -56,7 +48,7 @@ class GitlabHookTests(WebhookTestCase): def test_push_commits_more_than_limit_message_filtered_by_branches(self): # type: () -> None - self.url = self.build_webhook_url('master,tomek') + self.url = self.build_webhook_url(branches='master,tomek') expected_subject = u"my-awesome-project / tomek" commits_info = u'* b ([66abd2d](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n' expected_message = u"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek. Commits by Tomasz Kolek(50)\n\n{}[and {} more commit(s)]".format( @@ -373,7 +365,7 @@ class GitlabHookTests(WebhookTestCase): def test_push_event_message_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') result = self.client_post(self.url, payload, HTTP_X_GITLAB_EVENT='Push Hook', content_type="application/json") self.assertFalse(check_send_message_mock.called) @@ -383,7 +375,7 @@ class GitlabHookTests(WebhookTestCase): def test_push_commits_more_than_limit_message_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_commits_more_than_limit') result = self.client_post(self.url, payload, HTTP_X_GITLAB_EVENT='Push Hook', content_type="application/json") self.assertFalse(check_send_message_mock.called) diff --git a/zerver/webhooks/librato/tests.py b/zerver/webhooks/librato/tests.py index 57af71092d..0991fce2cf 100644 --- a/zerver/webhooks/librato/tests.py +++ b/zerver/webhooks/librato/tests.py @@ -5,7 +5,7 @@ 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=librato" + URL_TEMPLATE = u"/api/v1/external/librato?api_key={api_key}&stream={stream}" FIXTURE_DIR_NAME = 'librato' IS_ATTACHMENT = False @@ -15,14 +15,6 @@ class LibratoHookTests(WebhookTestCase): return self.fixture_data("librato", fixture_name, file_type='json') return urllib.parse.urlencode({'payload': self.fixture_data("librato", fixture_name, file_type='json')}) - def build_webhook_url(self, topic=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 topic: - url = u"{}&topic={}".format(url, topic) - return url - def test_alert_message_with_default_topic(self): # type: () -> None expected_subject = 'Alert alert.name' @@ -32,7 +24,7 @@ class LibratoHookTests(WebhookTestCase): def test_alert_message_with_custom_topic(self): # type: () -> None custom_topic = 'custom_name' - self.url = self.build_webhook_url(custom_topic) + self.url = self.build_webhook_url(topic=custom_topic) expected_message = "Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.google.pl)\n>Metric `librato.cpu.percent.idle`, sum was below 44 by 300s, recorded at 2016-03-31 09:11:42 UTC\n>Metric `librato.swap.swap.cached`, average was absent by 300s, recorded at 2016-03-31 09:11:42 UTC\n>Metric `librato.swap.swap.cached`, derivative was above 9 by 300s, recorded at 2016-03-31 09:11:42 UTC" self.send_and_test_stream_message('alert', custom_topic, expected_message, content_type="application/x-www-form-urlencoded") diff --git a/zerver/webhooks/splunk/tests.py b/zerver/webhooks/splunk/tests.py index 998ffed724..112bc777e6 100644 --- a/zerver/webhooks/splunk/tests.py +++ b/zerver/webhooks/splunk/tests.py @@ -5,24 +5,12 @@ from zerver.lib.test_classes import WebhookTestCase class SplunkHookTests(WebhookTestCase): STREAM_NAME = 'splunk' - TOPIC = u"Default Topic" - URL_TEMPLATE = "/api/v1/external/splunk?api_key={api_key}&stream={stream}&topic={topic}" + URL_TEMPLATE = "/api/v1/external/splunk?api_key={api_key}&stream={stream}" FIXTURE_DIR_NAME = 'splunk' - # override the base class behavior so we can include TOPIC - def build_webhook_url(self): - # type: () -> Text - api_key = self.get_api_key(self.TEST_USER_EMAIL) - return self.URL_TEMPLATE.format(stream=self.STREAM_NAME, - api_key=api_key, - topic=self.TOPIC) - def test_splunk_search_one_result(self): # type: () -> None - - # construct the URL used for this test - self.TOPIC = u"New Search Alert" - self.url = self.build_webhook_url() + self.url = self.build_webhook_url(topic=u"New Search Alert") # define the expected message contents expected_subject = u"New Search Alert" @@ -38,9 +26,6 @@ class SplunkHookTests(WebhookTestCase): # type: () -> None # don't provide a topic so the search name is used instead - self.URL_TEMPLATE = "/api/v1/external/splunk?api_key={api_key}&stream={stream}" - self.url = self.build_webhook_url() - expected_subject = u"This search's name isn't that long" expected_message = u"Splunk alert from saved search\n[This search's name isn't that long](http://example.com:8000/app/search/search?q=%7Cloadjob%20rt_scheduler__admin__search__sudo_at_1483557185_2.2%20%7C%20head%201%20%7C%20tail%201&earliest=0&latest=now)\nhost: myserver\nsource: /var/log/auth.log\n\nraw: Jan 4 11:14:32 myserver sudo: pam_unix(sudo:session): session closed for user root" @@ -53,9 +38,6 @@ class SplunkHookTests(WebhookTestCase): # type: () -> None # don't provide a topic so the search name is used instead - self.URL_TEMPLATE = "/api/v1/external/splunk?api_key={api_key}&stream={stream}" - self.url = self.build_webhook_url() - expected_subject = u"this-search's-got-47-words-37-sentences-58-words-we-wanna..." expected_message = u"Splunk alert from saved search\n[this-search's-got-47-words-37-sentences-58-words-we-wanna-know-details-of-the-search-time-of-the-search-and-any-other-kind-of-thing-you-gotta-say-pertaining-to-and-about-the-search-I-want-to-know-authenticated-user's-name-and-any-other-kind-of-thing-you-gotta-say](http://example.com:8000/app/search/search?q=%7Cloadjob%20rt_scheduler__admin__search__sudo_at_1483557185_2.2%20%7C%20head%201%20%7C%20tail%201&earliest=0&latest=now)\nhost: myserver\nsource: /var/log/auth.log\n\nraw: Jan 4 11:14:32 myserver sudo: pam_unix(sudo:session): session closed for user root" @@ -67,8 +49,7 @@ class SplunkHookTests(WebhookTestCase): def test_splunk_missing_results_link(self): # type: () -> None - self.TOPIC = u"New Search Alert" - self.url = self.build_webhook_url() + self.url = self.build_webhook_url(topic=u"New Search Alert") expected_subject = u"New Search Alert" expected_message = u"Splunk alert from saved search\n[sudo](Missing results_link)\nhost: myserver\nsource: /var/log/auth.log\n\nraw: Jan 4 11:14:32 myserver sudo: pam_unix(sudo:session): session closed for user root" @@ -81,8 +62,7 @@ class SplunkHookTests(WebhookTestCase): def test_splunk_missing_search_name(self): # type: () -> None - self.TOPIC = u"New Search Alert" - self.url = self.build_webhook_url() + self.url = self.build_webhook_url(topic=u"New Search Alert") expected_subject = u"New Search Alert" expected_message = u"Splunk alert from saved search\n[Missing search_name](http://example.com:8000/app/search/search?q=%7Cloadjob%20rt_scheduler__admin__search__sudo_at_1483557185_2.2%20%7C%20head%201%20%7C%20tail%201&earliest=0&latest=now)\nhost: myserver\nsource: /var/log/auth.log\n\nraw: Jan 4 11:14:32 myserver sudo: pam_unix(sudo:session): session closed for user root" @@ -95,8 +75,7 @@ class SplunkHookTests(WebhookTestCase): def test_splunk_missing_host(self): # type: () -> None - self.TOPIC = u"New Search Alert" - self.url = self.build_webhook_url() + self.url = self.build_webhook_url(topic=u"New Search Alert") expected_subject = u"New Search Alert" expected_message = u"Splunk alert from saved search\n[sudo](http://example.com:8000/app/search/search?q=%7Cloadjob%20rt_scheduler__admin__search__sudo_at_1483557185_2.2%20%7C%20head%201%20%7C%20tail%201&earliest=0&latest=now)\nhost: Missing host\nsource: /var/log/auth.log\n\nraw: Jan 4 11:14:32 myserver sudo: pam_unix(sudo:session): session closed for user root" @@ -109,8 +88,7 @@ class SplunkHookTests(WebhookTestCase): def test_splunk_missing_source(self): # type: () -> None - self.TOPIC = u"New Search Alert" - self.url = self.build_webhook_url() + self.url = self.build_webhook_url(topic=u"New Search Alert") expected_subject = u"New Search Alert" expected_message = u"Splunk alert from saved search\n[sudo](http://example.com:8000/app/search/search?q=%7Cloadjob%20rt_scheduler__admin__search__sudo_at_1483557185_2.2%20%7C%20head%201%20%7C%20tail%201&earliest=0&latest=now)\nhost: myserver\nsource: Missing source\n\nraw: Jan 4 11:14:32 myserver sudo: pam_unix(sudo:session): session closed for user root" @@ -123,8 +101,7 @@ class SplunkHookTests(WebhookTestCase): def test_splunk_missing_raw(self): # type: () -> None - self.TOPIC = u"New Search Alert" - self.url = self.build_webhook_url() + self.url = self.build_webhook_url(topic=u"New Search Alert") expected_subject = u"New Search Alert" expected_message = u"Splunk alert from saved search\n[sudo](http://example.com:8000/app/search/search?q=%7Cloadjob%20rt_scheduler__admin__search__sudo_at_1483557185_2.2%20%7C%20head%201%20%7C%20tail%201&earliest=0&latest=now)\nhost: myserver\nsource: /var/log/auth.log\n\nraw: Missing _raw" diff --git a/zerver/webhooks/taiga/tests.py b/zerver/webhooks/taiga/tests.py index 6110023fae..9dc4a6ff1a 100644 --- a/zerver/webhooks/taiga/tests.py +++ b/zerver/webhooks/taiga/tests.py @@ -5,13 +5,12 @@ from zerver.lib.test_classes import WebhookTestCase class TaigaHookTests(WebhookTestCase): STREAM_NAME = 'taiga' TOPIC = "subject" - URL_TEMPLATE = u"/api/v1/external/taiga?stream={stream}&api_key={api_key}&topic={topic}" + URL_TEMPLATE = u"/api/v1/external/taiga?stream={stream}&api_key={api_key}" FIXTURE_DIR_NAME = 'taiga' - def build_webhook_url(self): - # type: () -> Text - api_key = self.get_api_key(self.TEST_USER_EMAIL) - return self.URL_TEMPLATE.format(stream=self.STREAM_NAME, api_key=api_key, topic=self.TOPIC) + def setUp(self): + # type: () -> None + self.url = self.build_webhook_url(topic=self.TOPIC) def test_taiga_userstory_deleted(self): # type: () -> None diff --git a/zerver/webhooks/transifex/tests.py b/zerver/webhooks/transifex/tests.py index 16f12191a3..f5ae9560f0 100644 --- a/zerver/webhooks/transifex/tests.py +++ b/zerver/webhooks/transifex/tests.py @@ -4,8 +4,7 @@ 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}&{data_template}" - URL_DATA_TEMPLATE = "project={project}&language={language}&resource={resource}&{method}" + URL_TEMPLATE = u"/api/v1/external/transifex?stream={stream}&api_key={api_key}" URL_REVIEWED_METHOD_TEMPLATE = "reviewed=100" URL_TRANSLATED_METHOD_TEMPLATE = "translated=100" FIXTURE_DIR_NAME = 'transifex' @@ -20,7 +19,12 @@ class TransifexHookTests(WebhookTestCase): self.REVIEWED = True expected_subject = "{} in {}".format(self.PROJECT, self.LANGUAGE) expected_message = "Resource {} fully reviewed.".format(self.RESOURCE) - self.url = self.build_webhook_url() + self.url = self.build_webhook_url( + self.URL_REVIEWED_METHOD_TEMPLATE, + project=self.PROJECT, + language=self.LANGUAGE, + resource=self.RESOURCE, + ) self.send_and_test_stream_message(None, expected_subject, expected_message) def test_transifex_translated_message(self): @@ -28,20 +32,14 @@ class TransifexHookTests(WebhookTestCase): self.REVIEWED = False expected_subject = "{} in {}".format(self.PROJECT, self.LANGUAGE) expected_message = "Resource {} fully translated.".format(self.RESOURCE) - self.url = self.build_webhook_url() - self.send_and_test_stream_message(None, expected_subject, expected_message) - self.REVIEWED = True - - def build_webhook_url(self): - # type: () -> Text - url_data = self.URL_DATA_TEMPLATE.format( + self.url = self.build_webhook_url( + self.URL_TRANSLATED_METHOD_TEMPLATE, project=self.PROJECT, language=self.LANGUAGE, resource=self.RESOURCE, - method=self.URL_REVIEWED_METHOD_TEMPLATE if self.REVIEWED else self.URL_TRANSLATED_METHOD_TEMPLATE ) - api_key = self.get_api_key(self.TEST_USER_EMAIL) - return self.URL_TEMPLATE.format(api_key=api_key, stream=self.STREAM_NAME, data_template=url_data) + self.send_and_test_stream_message(None, expected_subject, expected_message) + self.REVIEWED = True def get_body(self, fixture_name): # type: (Text) -> Dict[str, Any] diff --git a/zerver/webhooks/yo/tests.py b/zerver/webhooks/yo/tests.py index 217a76bb2f..df731f0fec 100644 --- a/zerver/webhooks/yo/tests.py +++ b/zerver/webhooks/yo/tests.py @@ -4,7 +4,7 @@ from zerver.lib.test_classes import WebhookTestCase class YoHookTests(WebhookTestCase): STREAM_NAME = 'yo' - URL_TEMPLATE = u"/api/v1/external/yo?email={email}&api_key={api_key}&username={username}&user_ip={ip}" + URL_TEMPLATE = u"/api/v1/external/yo?api_key={api_key}" FIXTURE_DIR_NAME = 'yo' def test_yo_message(self): @@ -12,6 +12,11 @@ class YoHookTests(WebhookTestCase): """ Yo App sends notification whenever user receives a new Yo from another user. """ + self.url = self.build_webhook_url( + email="cordelia@zulip.com", + username="IAGO", + user_ip="127.0.0.1" + ) expected_message = u"Yo from IAGO" self.send_and_test_private_message('', expected_message=expected_message, content_type="application/x-www-form-urlencoded") @@ -19,11 +24,3 @@ class YoHookTests(WebhookTestCase): def get_body(self, fixture_name): # type: (Text) -> Dict[str, Any] return {} - - def build_webhook_url(self): - # type: () -> Text - api_key = self.get_api_key(self.TEST_USER_EMAIL) - email = "cordelia@zulip.com" - username = "IAGO" - ip = "127.0.0.1" - return self.URL_TEMPLATE.format(email=email, api_key=api_key, username=username, ip=ip)