diff --git a/zerver/webhooks/airbrake/tests.py b/zerver/webhooks/airbrake/tests.py index a01db9e731..bb98c567e6 100644 --- a/zerver/webhooks/airbrake/tests.py +++ b/zerver/webhooks/airbrake/tests.py @@ -7,6 +7,6 @@ class AirbrakeHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "airbrake" def test_airbrake_error_message(self) -> None: - expected_topic = "ZulipIntegrationTest" + expected_topic_name = "ZulipIntegrationTest" expected_message = '[ZeroDivisionError](https://zulip.airbrake.io/projects/125209/groups/1705190192091077626): "Error message from logger" occurred.' - self.check_webhook("error_message", expected_topic, expected_message) + self.check_webhook("error_message", expected_topic_name, expected_message) diff --git a/zerver/webhooks/airbrake/view.py b/zerver/webhooks/airbrake/view.py index 8ac4384e01..2c5a74f350 100644 --- a/zerver/webhooks/airbrake/view.py +++ b/zerver/webhooks/airbrake/view.py @@ -20,9 +20,9 @@ def api_airbrake_webhook( *, payload: JsonBodyPayload[WildValue], ) -> HttpResponse: - topic = get_topic(payload) + topic_name = get_topic(payload) body = get_body(payload) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/alertmanager/tests.py b/zerver/webhooks/alertmanager/tests.py index e0bb206545..a3c522834b 100644 --- a/zerver/webhooks/alertmanager/tests.py +++ b/zerver/webhooks/alertmanager/tests.py @@ -7,7 +7,7 @@ class AlertmanagerHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "alertmanager" def test_error_issue_message(self) -> None: - expected_topic = "andromeda" + expected_topic_name = "andromeda" expected_message = """ :alert: **FIRING** * CPU core temperature is 34.75C ([graph](http://cobalt:9090/graph?g0.expr=avg+by%28host%29+%28sensors_temp_input%7Bfeature%3D~%22core_%5B0-9%5D%2B%22%7D%29+%3E+15&g0.tab=0)) @@ -16,20 +16,20 @@ class AlertmanagerHookTests(WebhookTestCase): self.check_webhook( "alert", - expected_topic, + expected_topic_name, expected_message, "application/json", ) def test_single_error_issue_message(self) -> None: - expected_topic = "andromeda" + expected_topic_name = "andromeda" expected_message = """ :squared_ok: **Resolved** CPU core temperature is 34.75C ([graph](http://cobalt:9090/graph?g0.expr=avg+by%28host%29+%28sensors_temp_input%7Bfeature%3D~%22core_%5B0-9%5D%2B%22%7D%29+%3E+15&g0.tab=0)) """.strip() self.check_webhook( "single_alert", - expected_topic, + expected_topic_name, expected_message, "application/json", ) diff --git a/zerver/webhooks/alertmanager/view.py b/zerver/webhooks/alertmanager/view.py index 1583a34ca4..9ba6dbff23 100644 --- a/zerver/webhooks/alertmanager/view.py +++ b/zerver/webhooks/alertmanager/view.py @@ -40,7 +40,7 @@ def api_alertmanager_webhook( topics[name] = {"firing": [], "resolved": []} topics[name][alert["status"].tame(check_string)].append(body) - for topic, statuses in topics.items(): + for topic_name, statuses in topics.items(): for status, messages in statuses.items(): if len(messages) == 0: continue @@ -58,6 +58,6 @@ def api_alertmanager_webhook( message_list = "\n".join(f"* {m}" for m in messages) body = f"{icon} **{title}**\n{message_list}" - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/ansibletower/tests.py b/zerver/webhooks/ansibletower/tests.py index c29beaf607..5a8abcac5f 100644 --- a/zerver/webhooks/ansibletower/tests.py +++ b/zerver/webhooks/ansibletower/tests.py @@ -10,31 +10,31 @@ class AnsibletowerHookTests(WebhookTestCase): """ Tests if ansibletower project update successful notification is handled correctly """ - expected_topic = "AWX - Project Update" + expected_topic_name = "AWX - Project Update" expected_message = ( "Project Update: [#2677 AWX - Project Update]" "(http://awx.example.co.uk/#/jobs/project/2677) was successful." ) - self.check_webhook("project_update_successful", expected_topic, expected_message) + self.check_webhook("project_update_successful", expected_topic_name, expected_message) def test_ansibletower_project_update_failed_message(self) -> None: """ Tests if ansibletower project update failed notification is handled correctly """ - expected_topic = "AWX - Project Update" + expected_topic_name = "AWX - Project Update" expected_message = ( "Project Update: [#2678 AWX - Project Update]" "(http://awx.example.co.uk/#/jobs/project/2678) failed." ) - self.check_webhook("project_update_failed", expected_topic, expected_message) + self.check_webhook("project_update_failed", expected_topic_name, expected_message) def test_ansibletower_job_successful_multiple_hosts_message(self) -> None: """ Tests if ansibletower job successful multiple hosts notification is handled correctly """ - expected_topic = "System - Deploy - Zabbix Agent" + expected_topic_name = "System - Deploy - Zabbix Agent" expected_message = """ Job: [#2674 System - Deploy - Zabbix Agent](http://awx.example.co.uk/#/jobs/playbook/2674) was successful: * chat.example.co.uk: Success @@ -44,50 +44,52 @@ Job: [#2674 System - Deploy - Zabbix Agent](http://awx.example.co.uk/#/jobs/play * mail.example.co.uk: Success """.strip() - self.check_webhook("job_successful_multiple_hosts", expected_topic, expected_message) + self.check_webhook("job_successful_multiple_hosts", expected_topic_name, expected_message) def test_ansibletower_job_successful_message(self) -> None: """ Tests if ansibletower job successful notification is handled correctly """ - expected_topic = "System - Deploy - Zabbix Agent" + expected_topic_name = "System - Deploy - Zabbix Agent" expected_message = """ Job: [#2674 System - Deploy - Zabbix Agent](http://awx.example.co.uk/#/jobs/playbook/2674) was successful: * chat.example.co.uk: Success """.strip() - self.check_webhook("job_successful", expected_topic, expected_message) + self.check_webhook("job_successful", expected_topic_name, expected_message) def test_ansibletower_nine_job_successful_message(self) -> None: """ Test to see if awx/ansibletower 9.x.x job successful notifications are handled just as successfully as prior to 9.x.x. """ - expected_topic = "Demo Job Template" + expected_topic_name = "Demo Job Template" expected_message = """ Job: [#1 Demo Job Template](https://towerhost/#/jobs/playbook/1) was successful: * localhost: Success """.strip() - self.check_webhook("job_complete_successful_awx_9.1.1", expected_topic, expected_message) + self.check_webhook( + "job_complete_successful_awx_9.1.1", expected_topic_name, expected_message + ) def test_ansibletower_job_failed_message(self) -> None: """ Tests if ansibletower job failed notification is handled correctly """ - expected_topic = "System - Updates - Ubuntu" + expected_topic_name = "System - Updates - Ubuntu" expected_message = """ Job: [#2722 System - Updates - Ubuntu](http://awx.example.co.uk/#/jobs/playbook/2722) failed: * chat.example.co.uk: Failed """.strip() - self.check_webhook("job_failed", expected_topic, expected_message) + self.check_webhook("job_failed", expected_topic_name, expected_message) def test_ansibletower_job_failed_multiple_hosts_message(self) -> None: """ Tests if ansibletower job failed notification is handled correctly """ - expected_topic = "System - Updates - Ubuntu" + expected_topic_name = "System - Updates - Ubuntu" expected_message = """ Job: [#2722 System - Updates - Ubuntu](http://awx.example.co.uk/#/jobs/playbook/2722) failed: * chat.example.co.uk: Failed @@ -97,76 +99,76 @@ Job: [#2722 System - Updates - Ubuntu](http://awx.example.co.uk/#/jobs/playbook/ * mail.example.co.uk: Failed """.strip() - self.check_webhook("job_failed_multiple_hosts", expected_topic, expected_message) + self.check_webhook("job_failed_multiple_hosts", expected_topic_name, expected_message) def test_ansibletower_inventory_update_successful_message(self) -> None: """ Tests if ansibletower inventory update successful notification is handled correctly """ - expected_topic = "AWX - Inventory Update" + expected_topic_name = "AWX - Inventory Update" expected_message = ( "Inventory Update: [#2724 AWX - Inventory Update]" "(http://awx.example.co.uk/#/jobs/inventory/2724) was successful." ) - self.check_webhook("inventory_update_successful", expected_topic, expected_message) + self.check_webhook("inventory_update_successful", expected_topic_name, expected_message) def test_ansibletower_inventory_update_failed_message(self) -> None: """ Tests if ansibletower inventory update failed notification is handled correctly """ - expected_topic = "AWX - Inventory Update" + expected_topic_name = "AWX - Inventory Update" expected_message = ( "Inventory Update: [#2724 AWX - Inventory Update]" "(http://awx.example.co.uk/#/jobs/inventory/2724) failed." ) - self.check_webhook("inventory_update_failed", expected_topic, expected_message) + self.check_webhook("inventory_update_failed", expected_topic_name, expected_message) def test_ansibletower_adhoc_command_successful_message(self) -> None: """ Tests if ansibletower adhoc command successful notification is handled correctly """ - expected_topic = "shell: uname -r" + expected_topic_name = "shell: uname -r" expected_message = ( "AdHoc Command: [#2726 shell: uname -r]" "(http://awx.example.co.uk/#/jobs/command/2726) was successful." ) - self.check_webhook("adhoc_command_successful", expected_topic, expected_message) + self.check_webhook("adhoc_command_successful", expected_topic_name, expected_message) def test_ansibletower_adhoc_command_failed_message(self) -> None: """ Tests if ansibletower adhoc command failed notification is handled correctly """ - expected_topic = "shell: uname -r" + expected_topic_name = "shell: uname -r" expected_message = ( "AdHoc Command: [#2726 shell: uname -r]" "(http://awx.example.co.uk/#/jobs/command/2726) failed." ) - self.check_webhook("adhoc_command_failed", expected_topic, expected_message) + self.check_webhook("adhoc_command_failed", expected_topic_name, expected_message) def test_ansibletower_system_job_successful_message(self) -> None: """ Tests if ansibletower system job successful notification is handled correctly """ - expected_topic = "Cleanup Job Details" + expected_topic_name = "Cleanup Job Details" expected_message = ( "System Job: [#2721 Cleanup Job Details]" "(http://awx.example.co.uk/#/jobs/system/2721) was successful." ) - self.check_webhook("system_job_successful", expected_topic, expected_message) + self.check_webhook("system_job_successful", expected_topic_name, expected_message) def test_ansibletower_system_job_failed_message(self) -> None: """ Tests if ansibletower system job failed notification is handled correctly """ - expected_topic = "Cleanup Job Details" + expected_topic_name = "Cleanup Job Details" expected_message = ( "System Job: [#2721 Cleanup Job Details]" "(http://awx.example.co.uk/#/jobs/system/2721) failed." ) - self.check_webhook("system_job_failed", expected_topic, expected_message) + self.check_webhook("system_job_failed", expected_topic_name, expected_message) diff --git a/zerver/webhooks/ansibletower/view.py b/zerver/webhooks/ansibletower/view.py index 5b0df8fb9a..f4709f536b 100644 --- a/zerver/webhooks/ansibletower/view.py +++ b/zerver/webhooks/ansibletower/view.py @@ -30,9 +30,9 @@ def api_ansibletower_webhook( payload: JsonBodyPayload[WildValue], ) -> HttpResponse: body = get_body(payload) - topic = payload["name"].tame(check_string) + topic_name = payload["name"].tame(check_string) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/appfollow/tests.py b/zerver/webhooks/appfollow/tests.py index 6d0485088e..b5fa98a307 100644 --- a/zerver/webhooks/appfollow/tests.py +++ b/zerver/webhooks/appfollow/tests.py @@ -8,18 +8,18 @@ class AppFollowHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "appfollow" def test_sample(self) -> None: - expected_topic = "Webhook integration was successful." + expected_topic_name = "Webhook integration was successful." expected_message = """Webhook integration was successful. Test User / Acme (Google Play)""" self.check_webhook( "sample", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_reviews(self) -> None: - expected_topic = "Acme - Group chat" + expected_topic_name = "Acme - Group chat" expected_message = """Acme - Group chat App Store, Acme Technologies, Inc. ★★★★★ United States @@ -29,7 +29,7 @@ Acme enables me to manage the flow of information quite well. I only wish I coul [Permalink](http://appfollow.io/permalink) · [Add tag](http://watch.appfollow.io/add_tag)""" self.check_webhook( "review", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -40,7 +40,7 @@ Acme enables me to manage the flow of information quite well. I only wish I coul original_url_template = self.URL_TEMPLATE self.URL_TEMPLATE = original_url_template + "&topic=foo" self.url = self.build_webhook_url() - expected_topic = "foo" + expected_topic_name = "foo" expected_message = """Acme - Group chat App Store, Acme Technologies, Inc. ★★★★★ United States @@ -50,7 +50,7 @@ Acme enables me to manage the flow of information quite well. I only wish I coul [Permalink](http://appfollow.io/permalink) · [Add tag](http://watch.appfollow.io/add_tag)""" self.check_webhook( "review", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/appfollow/view.py b/zerver/webhooks/appfollow/view.py index af262f99e7..2198eb84d5 100644 --- a/zerver/webhooks/appfollow/view.py +++ b/zerver/webhooks/appfollow/view.py @@ -23,9 +23,9 @@ def api_appfollow_webhook( app_name_search = re.search(r"\A(.+)", message) assert app_name_search is not None app_name = app_name_search.group(0) - topic = app_name + topic_name = app_name - check_send_webhook_message(request, user_profile, topic, body=convert_markdown(message)) + check_send_webhook_message(request, user_profile, topic_name, body=convert_markdown(message)) return json_success(request) diff --git a/zerver/webhooks/appveyor/tests.py b/zerver/webhooks/appveyor/tests.py index 0d8b4d184e..481e2e634c 100644 --- a/zerver/webhooks/appveyor/tests.py +++ b/zerver/webhooks/appveyor/tests.py @@ -10,7 +10,7 @@ class AppveyorHookTests(WebhookTestCase): """ Tests if appveyor build success notification is handled correctly """ - expected_topic = "Hubot-DSC-Resource" + expected_topic_name = "Hubot-DSC-Resource" expected_message = """ [Build Hubot-DSC-Resource 2.0.59 completed](https://ci.appveyor.com/project/joebloggs/hubot-dsc-resource/build/2.0.59): * **Commit**: [c06e208b47: Increment version number.](https://github.com/joebloggs/Hubot-DSC-Resource/commit/c06e208b47) by Joe Bloggs @@ -18,13 +18,13 @@ class AppveyorHookTests(WebhookTestCase): * **Finished**: 9/9/2018 7:06 PM """.strip() - self.check_webhook("appveyor_build_success", expected_topic, expected_message) + self.check_webhook("appveyor_build_success", expected_topic_name, expected_message) def test_appveyor_build_failure_message(self) -> None: """ Tests if appveyor build failure notification is handled correctly """ - expected_topic = "Hubot-DSC-Resource" + expected_topic_name = "Hubot-DSC-Resource" expected_message = """ [Build Hubot-DSC-Resource 2.0.59 failed](https://ci.appveyor.com/project/joebloggs/hubot-dsc-resource/build/2.0.59): * **Commit**: [c06e208b47: Increment version number.](https://github.com/joebloggs/Hubot-DSC-Resource/commit/c06e208b47) by Joe Bloggs @@ -32,4 +32,4 @@ class AppveyorHookTests(WebhookTestCase): * **Finished**: 9/9/2018 7:06 PM """.strip() - self.check_webhook("appveyor_build_failure", expected_topic, expected_message) + self.check_webhook("appveyor_build_failure", expected_topic_name, expected_message) diff --git a/zerver/webhooks/appveyor/view.py b/zerver/webhooks/appveyor/view.py index bc7140dd46..dc9fcc20b3 100644 --- a/zerver/webhooks/appveyor/view.py +++ b/zerver/webhooks/appveyor/view.py @@ -25,9 +25,9 @@ def api_appveyor_webhook( payload: JsonBodyPayload[WildValue], ) -> HttpResponse: body = get_body_for_http_request(payload) - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/azuredevops/tests.py b/zerver/webhooks/azuredevops/tests.py index 87dd7f79b6..174a994f42 100644 --- a/zerver/webhooks/azuredevops/tests.py +++ b/zerver/webhooks/azuredevops/tests.py @@ -10,15 +10,15 @@ class AzuredevopsHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "azuredevops" def test_push_event_message(self) -> None: - expected_topic = "test-zulip / main" + expected_topic_name = "test-zulip / main" expected_message = "Yuro Itaki [pushed](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/branchCompare?baseVersion=GC51515957669f93c543df09f8f3e7f47c3613c879&targetVersion=GCb0ce2f2009c3c87dbefadf61d7eb2c0697a6f369&_a=files) 1 commit to branch main.\n\n* Modify readme ([b0ce2f2009c](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/commit/b0ce2f2009c3c87dbefadf61d7eb2c0697a6f369))" - self.check_webhook("code_push", expected_topic, expected_message) + self.check_webhook("code_push", expected_topic_name, expected_message) def test_push_event_message_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="main,dev") - expected_topic = "test-zulip / main" + expected_topic_name = "test-zulip / main" expected_message = "Yuro Itaki [pushed](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/branchCompare?baseVersion=GC51515957669f93c543df09f8f3e7f47c3613c879&targetVersion=GCb0ce2f2009c3c87dbefadf61d7eb2c0697a6f369&_a=files) 1 commit to branch main.\n\n* Modify readme ([b0ce2f2009c](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/commit/b0ce2f2009c3c87dbefadf61d7eb2c0697a6f369))" - self.check_webhook("code_push", expected_topic, expected_message) + self.check_webhook("code_push", expected_topic_name, expected_message) @patch("zerver.lib.webhooks.common.check_send_webhook_message") def test_push_event_message_filtered_by_branches_ignore( @@ -31,52 +31,54 @@ class AzuredevopsHookTests(WebhookTestCase): self.assert_json_success(result) def test_push_local_branch_without_commits(self) -> None: - expected_topic = "test-zulip / dev" + expected_topic_name = "test-zulip / dev" expected_message = "Yuro Itaki [pushed](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/branchCompare?baseVersion=GC0000000000000000000000000000000000000000&targetVersion=GC0929a3404b39f6e39076a640779b2c1c961e19b5&_a=files) the branch dev." self.check_webhook( - "code_push__local_branch_without_commits", expected_topic, expected_message + "code_push__local_branch_without_commits", expected_topic_name, expected_message ) def test_push_multiple_committers(self) -> None: - expected_topic = "test-zulip / main" + expected_topic_name = "test-zulip / main" expected_message = "Yuro Itaki [pushed](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/branchCompare?baseVersion=GCcc21b940719cc372b364d932eb39e528b0ec2a91&targetVersion=GC0929a3404b39f6e39076a640779b2c1c961e19b5&_a=files) 2 commits to branch main. Commits by Itachi Sensei (1) and Yuro Itaki (1).\n\n* Add reply ([0929a3404b3](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/commit/0929a3404b39f6e39076a640779b2c1c961e19b5))\n* Add how are you ([819ce8de51b](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/commit/819ce8de51bedfc250c202edcaee0ce8dc70bf3b))" - self.check_webhook("code_push__multiple_committers", expected_topic, expected_message) + self.check_webhook("code_push__multiple_committers", expected_topic_name, expected_message) def test_push_multiple_committers_with_others(self) -> None: - expected_topic = "test-zulip / main" + expected_topic_name = "test-zulip / main" commits_info = "* Add how are you ([819ce8de51b](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/commit/819ce8de51bedfc250c202edcaee0ce8dc70bf3b))\n" expected_message = f"Yuro Itaki [pushed](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/branchCompare?baseVersion=GCcc21b940719cc372b364d932eb39e528b0ec2a91&targetVersion=GC0929a3404b39f6e39076a640779b2c1c961e19b5&_a=files) 6 commits to branch main. Commits by Itachi Sensei (2), Yuro Itaki (2), Jonas Nielsen (1) and others (1).\n\n* Add reply ([0929a3404b3](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/commit/0929a3404b39f6e39076a640779b2c1c961e19b5))\n{commits_info * 4}* Add reply ([0929a3404b3](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/commit/0929a3404b39f6e39076a640779b2c1c961e19b5))" self.check_webhook( - "code_push__multiple_committers_with_others", expected_topic, expected_message + "code_push__multiple_committers_with_others", expected_topic_name, expected_message ) def test_push_commits_more_than_limit(self) -> None: - expected_topic = "test-zulip / main" + expected_topic_name = "test-zulip / main" commits_info = "* Modify readme ([b0ce2f2009c](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/commit/b0ce2f2009c3c87dbefadf61d7eb2c0697a6f369))\n" expected_message = f"Yuro Itaki [pushed](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/branchCompare?baseVersion=GC51515957669f93c543df09f8f3e7f47c3613c879&targetVersion=GCb0ce2f2009c3c87dbefadf61d7eb2c0697a6f369&_a=files) 50 commits to branch main.\n\n{commits_info * COMMITS_LIMIT}[and {50 - COMMITS_LIMIT} more commit(s)]" - self.check_webhook("code_push__commits_more_than_limit", expected_topic, expected_message) + self.check_webhook( + "code_push__commits_more_than_limit", expected_topic_name, expected_message + ) def test_push_remove_branch(self) -> None: - expected_topic = "test-zulip / dev" + expected_topic_name = "test-zulip / dev" expected_message = "Yuro Itaki [pushed](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/branchCompare?baseVersion=GC0929a3404b39f6e39076a640779b2c1c961e19b5&targetVersion=GC0000000000000000000000000000000000000000&_a=files) the branch dev." - self.check_webhook("code_push__remove_branch", expected_topic, expected_message) + self.check_webhook("code_push__remove_branch", expected_topic_name, expected_message) def test_pull_request_opened(self) -> None: - expected_topic = "test-zulip / PR #1 Add PR request" + expected_topic_name = "test-zulip / PR #1 Add PR request" expected_message = "Yuro Itaki created [PR #1 Add PR request](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/1) from `dev` to `main`:\n\n~~~ quote\nAdd PR request\n~~~" - self.check_webhook("code_pull_request__opened", expected_topic, expected_message) + self.check_webhook("code_pull_request__opened", expected_topic_name, expected_message) def test_pull_request_opened_without_description(self) -> None: - expected_topic = "test-zulip / PR #2 Raised 2nd PR!" + expected_topic_name = "test-zulip / PR #2 Raised 2nd PR!" expected_message = "Yuro Itaki created [PR #2 Raised 2nd PR!](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/2) from `stg` to `main`." self.check_webhook( - "code_pull_request__opened_without_description", expected_topic, expected_message + "code_pull_request__opened_without_description", expected_topic_name, expected_message ) def test_pull_request_merged(self) -> None: - expected_topic = "test-zulip / PR #1 Add PR request" + expected_topic_name = "test-zulip / PR #1 Add PR request" expected_message = "Yuro Itaki merged [PR #1 Add PR request](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/1) from `dev` to `main`." - self.check_webhook("code_pull_request__merged", expected_topic, expected_message) + self.check_webhook("code_pull_request__merged", expected_topic_name, expected_message) @patch("zerver.lib.webhooks.common.check_send_webhook_message") def test_pull_request_merge_attempted_ignore( @@ -89,6 +91,6 @@ class AzuredevopsHookTests(WebhookTestCase): self.assert_json_success(result) def test_pull_request_updated(self) -> None: - expected_topic = "test-zulip / PR #2 Raised 2nd PR!" + expected_topic_name = "test-zulip / PR #2 Raised 2nd PR!" expected_message = "Yuro Itaki updated [PR #2 Raised 2nd PR!](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/2)\n\n~~~ quote\nYuro Itaki updated the source branch of [pull request 2](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/pullrequest/2) (Raised 2nd PR!) in [test-zulip](https://dev.azure.com/ttchong/test-zulip/_git/test-zulip/)\r\nRaised 2nd PR!\r\n\n~~~" - self.check_webhook("code_pull_request__updated", expected_topic, expected_message) + self.check_webhook("code_pull_request__updated", expected_topic_name, expected_message) diff --git a/zerver/webhooks/azuredevops/view.py b/zerver/webhooks/azuredevops/view.py index ea1bde5a37..eddc1ef34f 100644 --- a/zerver/webhooks/azuredevops/view.py +++ b/zerver/webhooks/azuredevops/view.py @@ -181,10 +181,10 @@ def api_azuredevops_webhook( if event is None: return json_success(request) - topic = get_topic_based_on_event(payload, event) + topic_name = get_topic_based_on_event(payload, event) body_function = EVENT_FUNCTION_MAPPER[event] body = body_function(payload) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/basecamp/tests.py b/zerver/webhooks/basecamp/tests.py index 685bffed06..b537210e51 100644 --- a/zerver/webhooks/basecamp/tests.py +++ b/zerver/webhooks/basecamp/tests.py @@ -1,6 +1,6 @@ from zerver.lib.test_classes import WebhookTestCase -TOPIC = "Zulip HQ" +TOPIC_NAME = "Zulip HQ" class BasecampHookTests(WebhookTestCase): @@ -137,4 +137,4 @@ class BasecampHookTests(WebhookTestCase): self._send_and_test_message("comment_created", expected_message) def _send_and_test_message(self, fixture_name: str, expected_message: str) -> None: - self.check_webhook(fixture_name, TOPIC, expected_message) + self.check_webhook(fixture_name, TOPIC_NAME, expected_message) diff --git a/zerver/webhooks/basecamp/view.py b/zerver/webhooks/basecamp/view.py index 8005905c2a..8499cb3253 100644 --- a/zerver/webhooks/basecamp/view.py +++ b/zerver/webhooks/basecamp/view.py @@ -50,7 +50,7 @@ def api_basecamp_webhook( if event not in SUPPORT_EVENTS: raise UnsupportedWebhookEventTypeError(event) - topic = get_project_name(payload) + topic_name = get_project_name(payload) if event.startswith("document_"): body = get_document_body(event, payload) event = "document" @@ -75,7 +75,7 @@ def api_basecamp_webhook( else: raise UnsupportedWebhookEventTypeError(event) - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/beanstalk/tests.py b/zerver/webhooks/beanstalk/tests.py index 3667a7aa78..638844180b 100644 --- a/zerver/webhooks/beanstalk/tests.py +++ b/zerver/webhooks/beanstalk/tests.py @@ -12,26 +12,34 @@ class BeanstalkHookTests(WebhookTestCase): URL_TEMPLATE = "/api/v1/external/beanstalk?stream={stream}" def test_git_single(self) -> None: - expected_topic = "work-test / master" + expected_topic_name = "work-test / master" expected_message = """Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) 1 commit to branch master. * add some stuff ([e50508df24c](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/e50508df))""" self.api_stream_message( - self.test_user, "git_singlecommit", expected_topic, expected_message, content_type=None + self.test_user, + "git_singlecommit", + expected_topic_name, + expected_message, + content_type=None, ) def test_git_single_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="master,development") - expected_topic = "work-test / master" + expected_topic_name = "work-test / master" expected_message = """Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) 1 commit to branch master. * add some stuff ([e50508df24c](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/e50508df))""" self.api_stream_message( - self.test_user, "git_singlecommit", expected_topic, expected_message, content_type=None + self.test_user, + "git_singlecommit", + expected_topic_name, + expected_message, + content_type=None, ) def test_git_multiple_committers(self) -> None: - expected_topic = "work-test / master" + expected_topic_name = "work-test / master" expected_message = """Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) 3 commits to branch master. Commits by Leo Franchi (2) and Tomasz Kolek (1). * Added new file ([edf529c7a64](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/edf529c7)) @@ -40,14 +48,14 @@ class BeanstalkHookTests(WebhookTestCase): self.api_stream_message( self.test_user, "git_multiple_committers", - expected_topic, + expected_topic_name, expected_message, content_type=None, ) def test_git_multiple_committers_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="master,development") - expected_topic = "work-test / master" + expected_topic_name = "work-test / master" expected_message = """Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) 3 commits to branch master. Commits by Leo Franchi (2) and Tomasz Kolek (1). * Added new file ([edf529c7a64](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/edf529c7)) @@ -56,44 +64,44 @@ class BeanstalkHookTests(WebhookTestCase): self.api_stream_message( self.test_user, "git_multiple_committers", - expected_topic, + expected_topic_name, expected_message, content_type=None, ) def test_git_multiple(self) -> None: - expected_topic = "work-test / master" + expected_topic_name = "work-test / master" expected_message = """Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) 3 commits to branch master. * Added new file ([edf529c7a64](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/edf529c7)) * Filled in new file with some stuff ([c2a191b9e79](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/c2a191b9)) * More work to fix some bugs ([20098158e20](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/20098158))""" self.api_stream_message( - self.test_user, "git_multiple", expected_topic, expected_message, content_type=None + self.test_user, "git_multiple", expected_topic_name, expected_message, content_type=None ) def test_git_multiple_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="master,development") - expected_topic = "work-test / master" + expected_topic_name = "work-test / master" expected_message = """Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) 3 commits to branch master. * Added new file ([edf529c7a64](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/edf529c7)) * Filled in new file with some stuff ([c2a191b9e79](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/c2a191b9)) * More work to fix some bugs ([20098158e20](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/20098158))""" self.api_stream_message( - self.test_user, "git_multiple", expected_topic, expected_message, content_type=None + self.test_user, "git_multiple", expected_topic_name, expected_message, content_type=None ) def test_git_more_than_limit(self) -> None: commits_info = "* add some stuff ([e50508df24c](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/e50508df))\n" - expected_topic = "work-test / master" + expected_topic_name = "work-test / master" expected_message = f"""Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) 50 commits to branch master. {(commits_info * COMMITS_LIMIT)}[and {50 - COMMITS_LIMIT} more commit(s)]""" self.api_stream_message( self.test_user, "git_morethanlimitcommits", - expected_topic, + expected_topic_name, expected_message, content_type=None, ) @@ -101,14 +109,14 @@ class BeanstalkHookTests(WebhookTestCase): def test_git_more_than_limit_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="master,development") commits_info = "* add some stuff ([e50508df24c](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/e50508df))\n" - expected_topic = "work-test / master" + expected_topic_name = "work-test / master" expected_message = f"""Leo Franchi [pushed](http://lfranchi-svn.beanstalkapp.com/work-test) 50 commits to branch master. {(commits_info * COMMITS_LIMIT)}[and {50 - COMMITS_LIMIT} more commit(s)]""" self.api_stream_message( self.test_user, "git_morethanlimitcommits", - expected_topic, + expected_topic_name, expected_message, content_type=None, ) @@ -154,21 +162,29 @@ class BeanstalkHookTests(WebhookTestCase): self.assert_json_success(result) def test_svn_addremove(self) -> None: - expected_topic = "svn r3" + expected_topic_name = "svn r3" expected_message = """Leo Franchi pushed [revision 3](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/3): > Removed a file and added another one!""" self.api_stream_message( - self.test_user, "svn_addremove", expected_topic, expected_message, content_type=None + self.test_user, + "svn_addremove", + expected_topic_name, + expected_message, + content_type=None, ) def test_svn_changefile(self) -> None: - expected_topic = "svn r2" + expected_topic_name = "svn r2" expected_message = """Leo Franchi pushed [revision 2](http://lfranchi-svn.beanstalkapp.com/work-test/changesets/2): > Added some code""" self.api_stream_message( - self.test_user, "svn_changefile", expected_topic, expected_message, content_type=None + self.test_user, + "svn_changefile", + expected_topic_name, + expected_message, + content_type=None, ) @override diff --git a/zerver/webhooks/beanstalk/view.py b/zerver/webhooks/beanstalk/view.py index 804641c87b..d6d2fe3371 100644 --- a/zerver/webhooks/beanstalk/view.py +++ b/zerver/webhooks/beanstalk/view.py @@ -28,12 +28,12 @@ def build_message_from_gitlog( deleted: bool = False, ) -> Tuple[str, str]: short_ref = re.sub(r"^refs/heads/", "", ref) - topic = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref) + topic_name = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=name, branch=short_ref) commits_data = _transform_commits_list_to_common_format(commits) content = get_push_commits_event_message(pusher, url, short_ref, commits_data, deleted=deleted) - return topic, content + return topic_name, content def _transform_commits_list_to_common_format(commits: WildValue) -> List[Dict[str, str]]: @@ -70,7 +70,7 @@ def api_beanstalk_webhook( if branches is not None and branches.find(payload["branch"].tame(check_string)) == -1: return json_success(request) - topic, content = build_message_from_gitlog( + topic_name, content = build_message_from_gitlog( user_profile, payload["repository"]["name"].tame(check_string), payload["ref"].tame(check_string), @@ -86,8 +86,8 @@ def api_beanstalk_webhook( revision = payload["revision"].tame(check_int) (short_commit_msg, _, _) = payload["message"].tame(check_string).partition("\n") - topic = f"svn r{revision}" + topic_name = f"svn r{revision}" content = f"{author} pushed [revision {revision}]({url}):\n\n> {short_commit_msg}" - check_send_webhook_message(request, user_profile, topic, content) + check_send_webhook_message(request, user_profile, topic_name, content) return json_success(request) diff --git a/zerver/webhooks/beeminder/tests.py b/zerver/webhooks/beeminder/tests.py index b9775ce63a..4d6e452724 100644 --- a/zerver/webhooks/beeminder/tests.py +++ b/zerver/webhooks/beeminder/tests.py @@ -11,7 +11,7 @@ class BeeminderHookTests(WebhookTestCase): @patch("zerver.webhooks.beeminder.view.time.time") def test_beeminder_derail(self, time: MagicMock) -> None: time.return_value = 1517739100 # 5.6 hours from fixture value - expected_topic = "beekeeper" + expected_topic_name = "beekeeper" expected_message = """ You are going to derail from goal **gainweight** in **5.6 hours**. You need **+2 in 7 days (60)** to avoid derailing. * Pledge: **0$** :relieved: @@ -19,7 +19,7 @@ You are going to derail from goal **gainweight** in **5.6 hours**. You need **+2 self.check_webhook( "derail", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -27,12 +27,12 @@ You are going to derail from goal **gainweight** in **5.6 hours**. You need **+2 @patch("zerver.webhooks.beeminder.view.time.time") def test_beeminder_derail_worried(self, time: MagicMock) -> None: time.return_value = 1517739100 # 5.6 hours from fixture value - expected_topic = "beekeeper" + expected_topic_name = "beekeeper" expected_message = """ You are going to derail from goal **gainweight** in **5.6 hours**. You need **+2 in 7 days (60)** to avoid derailing. * Pledge: **5$** :worried: """.strip() self.check_webhook( - "derail_worried", expected_topic, expected_message, content_type="application/json" + "derail_worried", expected_topic_name, expected_message, content_type="application/json" ) diff --git a/zerver/webhooks/beeminder/view.py b/zerver/webhooks/beeminder/view.py index cc15769727..f6fa84e4c1 100644 --- a/zerver/webhooks/beeminder/view.py +++ b/zerver/webhooks/beeminder/view.py @@ -41,7 +41,7 @@ def api_beeminder_webhook( else: expression = ":relieved:" - topic = "beekeeper" + topic_name = "beekeeper" body = MESSAGE_TEMPLATE.format( goal_name=goal_name, time=time_remain, @@ -49,5 +49,5 @@ def api_beeminder_webhook( pledge=pledge, expression=expression, ) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/bitbucket/view.py b/zerver/webhooks/bitbucket/view.py index d92e9dec0f..38e64b6226 100644 --- a/zerver/webhooks/bitbucket/view.py +++ b/zerver/webhooks/bitbucket/view.py @@ -41,7 +41,7 @@ def api_bitbucket_webhook( if len(commits) == 0: # Bitbucket doesn't give us enough information to really give # a useful message :/ - topic = repository["name"].tame(check_string) + topic_name = repository["name"].tame(check_string) content = "{} [force pushed]({}).".format( payload.get("user", "Someone").tame(check_string), payload["canon_url"].tame(check_string) + repository["absolute_url"].tame(check_string), @@ -53,9 +53,11 @@ def api_bitbucket_webhook( committer = payload.get("user", "Someone").tame(check_string) content = get_push_commits_event_message(committer, None, branch, commits) - topic = TOPIC_WITH_BRANCH_TEMPLATE.format( + topic_name = TOPIC_WITH_BRANCH_TEMPLATE.format( repo=repository["name"].tame(check_string), branch=branch ) - check_send_webhook_message(request, user_profile, topic, content, unquote_url_parameters=True) + check_send_webhook_message( + request, user_profile, topic_name, content, unquote_url_parameters=True + ) return json_success(request) diff --git a/zerver/webhooks/bitbucket2/tests.py b/zerver/webhooks/bitbucket2/tests.py index 3d5c76a5ab..577fdc221b 100644 --- a/zerver/webhooks/bitbucket2/tests.py +++ b/zerver/webhooks/bitbucket2/tests.py @@ -100,9 +100,9 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_issue_created_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "Tomasz created [issue #1 Bug](https://bitbucket.org/kolaszek/repository-name/issues/2/bug) (assigned to Tomasz):\n\n~~~ quote\nSuch a bug\n~~~" - self.check_webhook("issue_created", expected_topic, expected_message) + self.check_webhook("issue_created", expected_topic_name, expected_message) def test_bitbucket2_on_issue_updated_event(self) -> None: expected_message = "Tomasz updated [issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)." @@ -114,9 +114,9 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_issue_commented_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "Tomasz [commented](https://bitbucket.org/kolaszek/repository-name/issues/2#comment-28973596) on [issue #1 Bug](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)." - self.check_webhook("issue_commented", expected_topic, expected_message) + self.check_webhook("issue_commented", expected_topic_name, expected_message) def test_bitbucket2_on_pull_request_created_event(self) -> None: expected_message = "Tomasz created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription\n~~~" @@ -138,11 +138,11 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_created_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "Tomasz created [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) from `new-branch` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription\n~~~" self.check_webhook( "pull_request_created_or_updated", - expected_topic, + expected_topic_name, expected_message, HTTP_X_EVENT_KEY="pullrequest:created", ) @@ -167,11 +167,11 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_approved_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "Tomasz approved [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1)." self.check_webhook( "pull_request_approved_or_unapproved", - expected_topic, + expected_topic_name, expected_message, HTTP_X_EVENT_KEY="pullrequest:approved", ) @@ -214,11 +214,11 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_comment_created_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "Tomasz [commented](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n~~~ quote\nComment1\n~~~" self.check_webhook( "pull_request_comment_action", - expected_topic, + expected_topic_name, expected_message, HTTP_X_EVENT_KEY="pullrequest:comment_created", ) @@ -234,11 +234,11 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_pull_request_comment_updated_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "Tomasz updated a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/3):\n\n~~~ quote\nComment1\n~~~" self.check_webhook( "pull_request_comment_action", - expected_topic, + expected_topic_name, expected_message, HTTP_X_EVENT_KEY="pullrequest:comment_updated", ) @@ -254,9 +254,9 @@ class Bitbucket2HookTests(WebhookTestCase): def test_bitbucket2_on_repo_updated_event(self) -> None: expected_message = "eeshangarg changed the website of the **new-name** repo to **http://zulipchat.com**.\neeshangarg changed the name of the **new-name** repo from **test-repo** to **new-name**.\neeshangarg changed the language of the **new-name** repo to **python**.\neeshangarg changed the full name of the **new-name** repo from **webhooktest/test-repo** to **webhooktest/new-name**.\neeshangarg changed the description of the **new-name** repo to **Random description.**" - expected_topic = "new-name" + expected_topic_name = "new-name" self.check_webhook( - "repo_updated", expected_topic, expected_message, HTTP_X_EVENT_KEY="repo:updated" + "repo_updated", expected_topic_name, expected_message, HTTP_X_EVENT_KEY="repo:updated" ) def test_bitbucket2_on_push_one_tag_event(self) -> None: diff --git a/zerver/webhooks/bitbucket2/view.py b/zerver/webhooks/bitbucket2/view.py index 3e2c3ef7c9..a246561580 100644 --- a/zerver/webhooks/bitbucket2/view.py +++ b/zerver/webhooks/bitbucket2/view.py @@ -95,15 +95,15 @@ def api_bitbucket2_webhook( if branch and branches and branches.find(branch) == -1: return json_success(request) - topics = get_push_topics(payload) + topic_names = get_push_topics(payload) bodies = get_push_bodies(request, payload) - for b, t in zip(bodies, topics): + for b, t in zip(bodies, topic_names): check_send_webhook_message( request, user_profile, t, b, type, unquote_url_parameters=True ) else: - topic = get_topic_based_on_type(payload, type) + topic_name = get_topic_based_on_type(payload, type) body_function = get_body_based_on_type(type) body = body_function( request, @@ -112,7 +112,7 @@ def api_bitbucket2_webhook( ) check_send_webhook_message( - request, user_profile, topic, body, type, unquote_url_parameters=True + request, user_profile, topic_name, body, type, unquote_url_parameters=True ) return json_success(request) diff --git a/zerver/webhooks/bitbucket3/tests.py b/zerver/webhooks/bitbucket3/tests.py index be1be2e570..7449dad757 100644 --- a/zerver/webhooks/bitbucket3/tests.py +++ b/zerver/webhooks/bitbucket3/tests.py @@ -42,16 +42,16 @@ class Bitbucket3HookTests(WebhookTestCase): def test_bitbucket3_repo_modified(self) -> None: expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) changed the name of the **sandbox** repo from **sandbox** to **sandbox v2**.""" - expected_topic = "sandbox v2" - self.check_webhook("repo_modified", expected_topic, expected_message) + expected_topic_name = "sandbox v2" + self.check_webhook("repo_modified", expected_topic_name, expected_message) # Repo push events: def test_push_add_branch(self) -> None: expected_message = ( """[hypro999](http://139.59.64.214:7990/users/hypro999) created branch2 branch.""" ) - expected_topic = TOPIC_BRANCH_EVENTS.format(branch="branch2") - self.check_webhook("repo_push_add_branch", expected_topic, expected_message) + expected_topic_name = TOPIC_BRANCH_EVENTS.format(branch="branch2") + self.check_webhook("repo_push_add_branch", expected_topic_name, expected_message) def test_push_add_tag(self) -> None: expected_message = ( @@ -63,8 +63,8 @@ class Bitbucket3HookTests(WebhookTestCase): expected_message = ( """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted branch branch2.""" ) - expected_topic = TOPIC_BRANCH_EVENTS.format(branch="branch2") - self.check_webhook("repo_push_delete_branch", expected_topic, expected_message) + expected_topic_name = TOPIC_BRANCH_EVENTS.format(branch="branch2") + self.check_webhook("repo_push_delete_branch", expected_topic_name, expected_message) def test_push_delete_tag(self) -> None: expected_message = ( @@ -74,8 +74,8 @@ class Bitbucket3HookTests(WebhookTestCase): def test_push_update_single_branch(self) -> None: expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) pushed to branch master. Head is now e68c981ef53dbab0a5ca320a2d8d80e216c70528.""" - expected_topic = TOPIC_BRANCH_EVENTS.format(branch="master") - self.check_webhook("repo_push_update_single_branch", expected_topic, expected_message) + expected_topic_name = TOPIC_BRANCH_EVENTS.format(branch="master") + self.check_webhook("repo_push_update_single_branch", expected_topic_name, expected_message) def test_push_update_multiple_branches(self) -> None: branch1_content = """[hypro999](http://139.59.64.214:7990/users/hypro999) pushed to branch branch1. Head is now 3980c2be32a7e23c795741d5dc1a2eecb9b85d6d.""" @@ -110,146 +110,150 @@ class Bitbucket3HookTests(WebhookTestCase): def test_push_update_multiple_branches_with_branch_filter(self) -> None: self.url = self.build_webhook_url(branches="master") expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) pushed to branch master. Head is now fc43d13cff1abb28631196944ba4fc4ad06a2cf2.""" - expected_topic = TOPIC_BRANCH_EVENTS.format(branch="master") - self.check_webhook("repo_push_update_multiple_branches", expected_topic, expected_message) + expected_topic_name = TOPIC_BRANCH_EVENTS.format(branch="master") + self.check_webhook( + "repo_push_update_multiple_branches", expected_topic_name, expected_message + ) self.url = self.build_webhook_url(branches="branch1") expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) pushed to branch branch1. Head is now 3980c2be32a7e23c795741d5dc1a2eecb9b85d6d.""" - expected_topic = TOPIC_BRANCH_EVENTS.format(branch="branch1") - self.check_webhook("repo_push_update_multiple_branches", expected_topic, expected_message) + expected_topic_name = TOPIC_BRANCH_EVENTS.format(branch="branch1") + self.check_webhook( + "repo_push_update_multiple_branches", expected_topic_name, expected_message + ) # Core PR events: def test_pr_opened_without_reviewers(self) -> None: - expected_topic = "sandbox / PR #1 Branch1" + expected_topic_name = "sandbox / PR #1 Branch1" expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) opened [PR #1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) from `branch1` to `master`:\n\n~~~ quote\n* Add file2.txt\r\n* Add file3.txt\n~~~""" self.check_webhook( - "pull_request_opened_without_reviewers", expected_topic, expected_message + "pull_request_opened_without_reviewers", expected_topic_name, expected_message ) def test_pr_opened_without_description(self) -> None: - expected_topic = "sandbox / PR #2 Add notes feature." + expected_topic_name = "sandbox / PR #2 Add notes feature." expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) opened [PR #2](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/2) from `master` to `master`.""" self.check_webhook( - "pull_request_opened_without_description", expected_topic, expected_message + "pull_request_opened_without_description", expected_topic_name, expected_message ) def test_pr_opened_with_two_reviewers(self) -> None: - expected_topic = "sandbox / PR #5 Add Notes Feature" + expected_topic_name = "sandbox / PR #5 Add Notes Feature" expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) opened [PR #5](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/5) from `master` to `master` (assigned reviewers: [shimura](http://139.59.64.214:7990/users/shimura) and [sougo](http://139.59.64.214:7990/users/sougo)).""" self.check_webhook( - "pull_request_opened_with_two_reviewers", expected_topic, expected_message + "pull_request_opened_with_two_reviewers", expected_topic_name, expected_message ) def test_pr_opened_with_two_reviewers_and_user_defined_topic(self) -> None: - expected_topic = "sandbox / PR #5 Add Notes Feature" - expected_topic = "custom_topic" + expected_topic_name = "sandbox / PR #5 Add Notes Feature" + expected_topic_name = "custom_topic" self.url = self.build_webhook_url(topic="custom_topic") expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) opened [PR #5 Add Notes Feature](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/5) from `master` to `master` (assigned reviewers: [shimura](http://139.59.64.214:7990/users/shimura) and [sougo](http://139.59.64.214:7990/users/sougo)).""" self.check_webhook( - "pull_request_opened_with_two_reviewers", expected_topic, expected_message + "pull_request_opened_with_two_reviewers", expected_topic_name, expected_message ) def test_pr_opened_with_multiple_reviewers(self) -> None: - expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." + expected_topic_name = "sandbox / PR #6 sample_file: Add sample_file.txt." expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) opened [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6) from `master` to `master` (assigned reviewers: [sougo](http://139.59.64.214:7990/users/sougo), [zura](http://139.59.64.214:7990/users/zura) and [shimura](http://139.59.64.214:7990/users/shimura)):\n\n~~~ quote\nAdd a simple text file for further testing purposes.\n~~~""" self.check_webhook( - "pull_request_opened_with_multiple_reviewers", expected_topic, expected_message + "pull_request_opened_with_multiple_reviewers", expected_topic_name, expected_message ) def test_pr_modified(self) -> None: - expected_topic = "sandbox / PR #1 Branch1" + expected_topic_name = "sandbox / PR #1 Branch1" expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) modified [PR #1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) (assigned reviewers: [shimura](http://139.59.64.214:7990/users/shimura)):\n\n~~~ quote\n* Add file2.txt\n* Add file3.txt\nBoth of these files would be important additions to the project!\n~~~""" - self.check_webhook("pull_request_modified", expected_topic, expected_message) + self.check_webhook("pull_request_modified", expected_topic_name, expected_message) def test_pr_modified_with_include_title(self) -> None: - expected_topic = "custom_topic" + expected_topic_name = "custom_topic" expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) modified [PR #1 Branch1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) (assigned reviewers: [shimura](http://139.59.64.214:7990/users/shimura)):\n\n~~~ quote\n* Add file2.txt\n* Add file3.txt\nBoth of these files would be important additions to the project!\n~~~""" self.url = self.build_webhook_url(topic="custom_topic") - self.check_webhook("pull_request_modified", expected_topic, expected_message) + self.check_webhook("pull_request_modified", expected_topic_name, expected_message) def test_pr_deleted(self) -> None: - expected_topic = "sandbox / PR #2 Add notes feature." + expected_topic_name = "sandbox / PR #2 Add notes feature." expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted [PR #2](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/2).""" - self.check_webhook("pull_request_deleted", expected_topic, expected_message) + self.check_webhook("pull_request_deleted", expected_topic_name, expected_message) def test_pr_deleted_with_include_title(self) -> None: - expected_topic = "custom_topic" + expected_topic_name = "custom_topic" expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) deleted [PR #2 Add notes feature.](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/2)""" self.url = self.build_webhook_url(topic="custom_topic") - self.check_webhook("pull_request_deleted", expected_topic, expected_message) + self.check_webhook("pull_request_deleted", expected_topic_name, expected_message) def test_pr_declined(self) -> None: - expected_topic = "sandbox / PR #7 Crazy Idea" + expected_topic_name = "sandbox / PR #7 Crazy Idea" expected_message = """[zura](http://139.59.64.214:7990/users/zura) declined [PR #7](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/7).""" - self.check_webhook("pull_request_declined", expected_topic, expected_message) + self.check_webhook("pull_request_declined", expected_topic_name, expected_message) def test_pr_merged(self) -> None: - expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." + expected_topic_name = "sandbox / PR #6 sample_file: Add sample_file.txt." expected_message = """[zura](http://139.59.64.214:7990/users/zura) merged [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6) from `master` to `master`.""" - self.check_webhook("pull_request_merged", expected_topic, expected_message) + self.check_webhook("pull_request_merged", expected_topic_name, expected_message) # PR reviewer events: def test_pr_approved(self) -> None: - expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." + expected_topic_name = "sandbox / PR #6 sample_file: Add sample_file.txt." expected_message = """[zura](http://139.59.64.214:7990/users/zura) approved [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6).""" - self.check_webhook("pull_request_approved", expected_topic, expected_message) + self.check_webhook("pull_request_approved", expected_topic_name, expected_message) def test_pr_unapproved(self) -> None: - expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." + expected_topic_name = "sandbox / PR #6 sample_file: Add sample_file.txt." expected_message = """[zura](http://139.59.64.214:7990/users/zura) unapproved [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6).""" - self.check_webhook("pull_request_unapproved", expected_topic, expected_message) + self.check_webhook("pull_request_unapproved", expected_topic_name, expected_message) def test_pr_marked_as_needs_review(self) -> None: - expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." + expected_topic_name = "sandbox / PR #6 sample_file: Add sample_file.txt." expected_message = """[zura](http://139.59.64.214:7990/users/zura) marked [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6) as \"needs work\".""" - self.check_webhook("pull_request_needs_work", expected_topic, expected_message) + self.check_webhook("pull_request_needs_work", expected_topic_name, expected_message) def test_pr_marked_as_needs_review_and_include_title(self) -> None: - expected_topic = "custom_topic" + expected_topic_name = "custom_topic" expected_message = """[zura](http://139.59.64.214:7990/users/zura) marked [PR #6 sample_file: Add sample_file.txt.](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6) as \"needs work\".""" self.url = self.build_webhook_url(topic="custom_topic") - self.check_webhook("pull_request_needs_work", expected_topic, expected_message) + self.check_webhook("pull_request_needs_work", expected_topic_name, expected_message) def test_pull_request_reviewer_added(self) -> None: expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) reassigned [PR #1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) to [shimura](http://139.59.64.214:7990/users/shimura).""" - expected_topic = "sandbox / PR #1 Branch1" - self.check_webhook("pull_request_add_reviewer", expected_topic, expected_message) + expected_topic_name = "sandbox / PR #1 Branch1" + self.check_webhook("pull_request_add_reviewer", expected_topic_name, expected_message) def test_pull_request_reviewer_added_and_include_title(self) -> None: expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) reassigned [PR #1 Branch1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) to [shimura](http://139.59.64.214:7990/users/shimura).""" - expected_topic = "custom_topic" + expected_topic_name = "custom_topic" self.url = self.build_webhook_url(topic="custom_topic") - self.check_webhook("pull_request_add_reviewer", expected_topic, expected_message) + self.check_webhook("pull_request_add_reviewer", expected_topic_name, expected_message) def test_pull_request_reviewers_added(self) -> None: expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) reassigned [PR #1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1) to [shimura](http://139.59.64.214:7990/users/shimura) and [sougo](http://139.59.64.214:7990/users/sougo).""" - expected_topic = "sandbox / PR #1 Branch1" - self.check_webhook("pull_request_add_two_reviewers", expected_topic, expected_message) + expected_topic_name = "sandbox / PR #1 Branch1" + self.check_webhook("pull_request_add_two_reviewers", expected_topic_name, expected_message) def test_pull_request_remove_all_reviewers(self) -> None: expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) removed all reviewers from [PR #1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1).""" - expected_topic = "sandbox / PR #1 Branch1" - self.check_webhook("pull_request_remove_reviewer", expected_topic, expected_message) + expected_topic_name = "sandbox / PR #1 Branch1" + self.check_webhook("pull_request_remove_reviewer", expected_topic_name, expected_message) def test_pull_request_remove_all_reviewers_with_title(self) -> None: expected_message = """[hypro999](http://139.59.64.214:7990/users/hypro999) removed all reviewers from [PR #1 Branch1](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/1).""" - expected_topic = "sandbox / PR #1 Branch1" - expected_topic = "custom_topic" + expected_topic_name = "sandbox / PR #1 Branch1" + expected_topic_name = "custom_topic" self.url = self.build_webhook_url(topic="custom_topic") - self.check_webhook("pull_request_remove_reviewer", expected_topic, expected_message) + self.check_webhook("pull_request_remove_reviewer", expected_topic_name, expected_message) # PR comment events: def test_pull_request_comment_added(self) -> None: expected_message = """[zura](http://139.59.64.214:7990/users/zura) commented on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6):\n\n~~~ quote\nThis seems like a pretty good idea.\n~~~""" - expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." - self.check_webhook("pull_request_comment_added", expected_topic, expected_message) + expected_topic_name = "sandbox / PR #6 sample_file: Add sample_file.txt." + self.check_webhook("pull_request_comment_added", expected_topic_name, expected_message) def test_pull_request_comment_edited(self) -> None: expected_message = """[zura](http://139.59.64.214:7990/users/zura) edited their comment on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6):\n\n~~~ quote\nThis seems like a pretty good idea. @shimura what do you think?\n~~~""" - expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." - self.check_webhook("pull_request_comment_edited", expected_topic, expected_message) + expected_topic_name = "sandbox / PR #6 sample_file: Add sample_file.txt." + self.check_webhook("pull_request_comment_edited", expected_topic_name, expected_message) def test_pull_request_comment_deleted(self) -> None: expected_message = """[zura](http://139.59.64.214:7990/users/zura) deleted their comment on [PR #6](http://139.59.64.214:7990/projects/SBOX/repos/sandbox/pull-requests/6):\n\n~~~ quote\n~~This seems like a pretty good idea. @shimura what do you think?~~\n~~~""" - expected_topic = "sandbox / PR #6 sample_file: Add sample_file.txt." - self.check_webhook("pull_request_comment_deleted", expected_topic, expected_message) + expected_topic_name = "sandbox / PR #6 sample_file: Add sample_file.txt." + self.check_webhook("pull_request_comment_deleted", expected_topic_name, expected_message) diff --git a/zerver/webhooks/bitbucket3/view.py b/zerver/webhooks/bitbucket3/view.py index f4a5eaac62..c74253b871 100644 --- a/zerver/webhooks/bitbucket3/view.py +++ b/zerver/webhooks/bitbucket3/view.py @@ -76,11 +76,11 @@ def ping_handler( include_title: Optional[str], ) -> List[Dict[str, str]]: if include_title: - topic = include_title + topic_name = include_title else: - topic = "Bitbucket Server Ping" + topic_name = "Bitbucket Server Ping" body = "Congratulations! The Bitbucket Server webhook was configured successfully!" - return [{"topic": topic, "body": body}] + return [{"topic": topic_name, "body": body}] def repo_comment_handler( @@ -90,7 +90,7 @@ def repo_comment_handler( include_title: Optional[str], ) -> List[Dict[str, str]]: repo_name = payload["repository"]["name"].tame(check_string) - topic = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name) + topic_name = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name) sha = payload["commit"].tame(check_string) commit_url = payload["repository"]["links"]["self"][0]["href"].tame(check_string)[ : -len("browse") @@ -106,7 +106,7 @@ def repo_comment_handler( sha=sha, message=message, ) - return [{"topic": topic, "body": body}] + return [{"topic": topic_name, "body": body}] def repo_forked_handler( @@ -115,14 +115,14 @@ def repo_forked_handler( include_title: Optional[str], ) -> List[Dict[str, str]]: repo_name = payload["repository"]["origin"]["name"].tame(check_string) - topic = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name) + topic_name = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name) body = BITBUCKET_FORK_BODY.format( display_name=payload["actor"]["displayName"].tame(check_string), username=get_user_name(payload), fork_name=payload["repository"]["name"].tame(check_string), fork_url=payload["repository"]["links"]["self"][0]["href"].tame(check_string), ) - return [{"topic": topic, "body": body}] + return [{"topic": topic_name, "body": body}] def repo_modified_handler( @@ -130,7 +130,7 @@ def repo_modified_handler( branches: Optional[str], include_title: Optional[str], ) -> List[Dict[str, str]]: - topic_new = BITBUCKET_TOPIC_TEMPLATE.format( + topic_name_new = BITBUCKET_TOPIC_TEMPLATE.format( repository_name=payload["new"]["name"].tame(check_string) ) new_name = payload["new"]["name"].tame(check_string) @@ -143,7 +143,7 @@ def repo_modified_handler( ) # As of writing this, the only change we'd be notified about is a name change. punctuation = "." if new_name[-1] not in string.punctuation else "" body = f"{body}{punctuation}" - return [{"topic": topic_new, "body": body}] + return [{"topic": topic_name_new, "body": body}] def repo_push_branch_data(payload: WildValue, change: WildValue) -> Dict[str, str]: @@ -171,8 +171,8 @@ def repo_push_branch_data(payload: WildValue, change: WildValue) -> Dict[str, st message = "{}.{}".format(payload["eventKey"].tame(check_string), event_type) # nocoverage raise UnsupportedWebhookEventTypeError(message) - topic = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repo_name, branch=branch_name) - return {"topic": topic, "body": body} + topic_name = TOPIC_WITH_BRANCH_TEMPLATE.format(repo=repo_name, branch=branch_name) + return {"topic": topic_name, "body": body} def repo_push_tag_data(payload: WildValue, change: WildValue) -> Dict[str, str]: @@ -188,9 +188,9 @@ def repo_push_tag_data(payload: WildValue, change: WildValue) -> Dict[str, str]: message = "{}.{}".format(payload["eventKey"].tame(check_string), event_type) # nocoverage raise UnsupportedWebhookEventTypeError(message) - topic = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name) + topic_name = BITBUCKET_TOPIC_TEMPLATE.format(repository_name=repo_name) body = get_push_tag_event_message(get_user_name(payload), tag_name, action=action) - return {"topic": topic, "body": body} + return {"topic": topic_name, "body": body} def repo_push_handler( @@ -342,7 +342,7 @@ def pr_handler( include_title: Optional[str], ) -> List[Dict[str, str]]: pr = payload["pullRequest"] - topic = get_pr_topic( + topic_name = get_pr_topic( pr["toRef"]["repository"]["name"].tame(check_string), type="PR", id=pr["id"].tame(check_int), @@ -359,7 +359,7 @@ def pr_handler( else: body = get_simple_pr_body(payload, action, include_title) - return [{"topic": topic, "body": body}] + return [{"topic": topic_name, "body": body}] def pr_comment_handler( @@ -369,7 +369,7 @@ def pr_comment_handler( include_title: Optional[str], ) -> List[Dict[str, str]]: pr = payload["pullRequest"] - topic = get_pr_topic( + topic_name = get_pr_topic( pr["toRef"]["repository"]["name"].tame(check_string), type="PR", id=pr["id"].tame(check_int), @@ -387,7 +387,7 @@ def pr_comment_handler( title=pr["title"].tame(check_string) if include_title else None, ) - return [{"topic": topic, "body": body}] + return [{"topic": topic_name, "body": body}] class EventHandler(Protocol): diff --git a/zerver/webhooks/buildbot/tests.py b/zerver/webhooks/buildbot/tests.py index b38b153134..8d96b5b078 100644 --- a/zerver/webhooks/buildbot/tests.py +++ b/zerver/webhooks/buildbot/tests.py @@ -7,23 +7,23 @@ class BuildbotHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "buildbot" def test_build_started(self) -> None: - expected_topic = "buildbot-hello" + expected_topic_name = "buildbot-hello" expected_message = ( "Build [#33](http://exampleurl.com/#builders/1/builds/33) for **runtests** started." ) - self.check_webhook("started", expected_topic, expected_message) + self.check_webhook("started", expected_topic_name, expected_message) def test_build_success(self) -> None: - expected_topic = "buildbot-hello" + expected_topic_name = "buildbot-hello" expected_message = "Build [#33](http://exampleurl.com/#builders/1/builds/33) (result: success) for **runtests** finished." - self.check_webhook("finished_success", expected_topic, expected_message) + self.check_webhook("finished_success", expected_topic_name, expected_message) def test_build_failure(self) -> None: - expected_topic = "general" # project key is empty + expected_topic_name = "general" # project key is empty expected_message = "Build [#34](http://exampleurl.com/#builders/1/builds/34) (result: failure) for **runtests** finished." - self.check_webhook("finished_failure", expected_topic, expected_message) + self.check_webhook("finished_failure", expected_topic_name, expected_message) def test_build_cancelled(self) -> None: - expected_topic = "zulip/zulip-zapier" + expected_topic_name = "zulip/zulip-zapier" expected_message = "Build [#10434](https://ci.example.org/#builders/79/builds/307) (result: cancelled) for **AMD64 Ubuntu 18.04 Python 3** finished." - self.check_webhook("finished_cancelled", expected_topic, expected_message) + self.check_webhook("finished_cancelled", expected_topic_name, expected_message) diff --git a/zerver/webhooks/buildbot/view.py b/zerver/webhooks/buildbot/view.py index 39e226ea70..2cdbb05ce0 100644 --- a/zerver/webhooks/buildbot/view.py +++ b/zerver/webhooks/buildbot/view.py @@ -18,12 +18,12 @@ def api_buildbot_webhook( *, payload: JsonBodyPayload[WildValue], ) -> HttpResponse: - topic = payload["project"].tame(check_string) - if not topic: - topic = "general" + topic_name = payload["project"].tame(check_string) + if not topic_name: + topic_name = "general" body = get_message(payload) check_send_webhook_message( - request, user_profile, topic, body, payload["event"].tame(check_string) + request, user_profile, topic_name, body, payload["event"].tame(check_string) ) return json_success(request) diff --git a/zerver/webhooks/canarytoken/view.py b/zerver/webhooks/canarytoken/view.py index 861bfa69fa..65e36e59f4 100644 --- a/zerver/webhooks/canarytoken/view.py +++ b/zerver/webhooks/canarytoken/view.py @@ -27,7 +27,7 @@ def api_canarytoken_webhook( https://help.canary.tools/hc/en-gb/articles/360002426577-How-do-I-configure-notifications-for-a-Generic-Webhook- """ - topic = "canarytoken alert" + topic_name = "canarytoken alert" body = ( f"**:alert: Canarytoken has been triggered on {message['time'].tame(check_string)}!**\n\n" f"{message['memo'].tame(check_string)} \n\n" @@ -35,7 +35,7 @@ def api_canarytoken_webhook( ) if user_specified_topic: - topic = user_specified_topic + topic_name = user_specified_topic - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/circleci/tests.py b/zerver/webhooks/circleci/tests.py index 601bae62b4..b5b5cac00c 100644 --- a/zerver/webhooks/circleci/tests.py +++ b/zerver/webhooks/circleci/tests.py @@ -7,78 +7,80 @@ class CircleCiHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "circleci" def test_ping(self) -> None: - expected_topic = "Test event" + expected_topic_name = "Test event" expected_message = "Webhook 'Testing' test event successful." - self.check_webhook("ping", expected_topic, expected_message) + self.check_webhook("ping", expected_topic_name, expected_message) def test_bitbucket_job_completed(self) -> None: - expected_topic = "circleci-webhook-testing" + expected_topic_name = "circleci-webhook-testing" expected_message = """ Job `build-and-test` within Pipeline #4 has succeeded. Triggered on [`8ab595d2de9: app.py edited online with Bitbucket`](https://bitbucket.org/hariprashant1/circleci-webhook-testing/commits/8ab595d2de95767993472837df2cb7884519a92b) on branch `master` by Hari Prashant Bhimaraju. """.strip() - self.check_webhook("bitbucket_job_completed", expected_topic, expected_message) + self.check_webhook("bitbucket_job_completed", expected_topic_name, expected_message) def test_bitbucket_manual_workflow_completed(self) -> None: - expected_topic = "circleci-webhook-testing" + expected_topic_name = "circleci-webhook-testing" expected_message = """ Workflow [`sample`](https://app.circleci.com/pipelines/bitbucket/hariprashant1/circleci-webhook-testing/2/workflows/baa45986-84db-47a0-bc6c-89e9fe751bc9) within Pipeline #2 has succeeded. Triggered on `master`'s HEAD on [cab5eacb4cc](https://bitbucket.org/hariprashant1/circleci-webhook-testing/commits/cab5eacb4ccee2710529894425341fa20a48fe6a). """.strip() - self.check_webhook("bitbucket_manual_workflow_completed", expected_topic, expected_message) + self.check_webhook( + "bitbucket_manual_workflow_completed", expected_topic_name, expected_message + ) def test_bitbucket_workflow_completed(self) -> None: - expected_topic = "circleci-webhook-testing" + expected_topic_name = "circleci-webhook-testing" expected_message = """ Workflow [`sample`](https://app.circleci.com/pipelines/bitbucket/hariprashant1/circleci-webhook-testing/4/workflows/fd29ef0c-3e39-4c8f-b1d5-d8be1bab8165) within Pipeline #4 has succeeded. Triggered on [`8ab595d2de9: app.py edited online with Bitbucket`](https://bitbucket.org/hariprashant1/circleci-webhook-testing/commits/8ab595d2de95767993472837df2cb7884519a92b) on branch `master` by Hari Prashant Bhimaraju. """.strip() - self.check_webhook("bitbucket_workflow_completed", expected_topic, expected_message) + self.check_webhook("bitbucket_workflow_completed", expected_topic_name, expected_message) def test_github_job_completed(self) -> None: - expected_topic = "circleci-webhook-test" + expected_topic_name = "circleci-webhook-test" expected_message = """ Job `build-and-test` within Pipeline #4 has succeeded. Triggered on [`a5e30a90822: .circleci: Update Webhook URL.`](https://github.com/zulip-testing/circleci-webhook-test/commit/a5e30a908224e46626a796d058289475f6d387b5) on branch `main` by Hari Prashant Bhimaraju. """.strip() - self.check_webhook("github_job_completed", expected_topic, expected_message) + self.check_webhook("github_job_completed", expected_topic_name, expected_message) def test_github_tag_workflow_completed(self) -> None: - expected_topic = "circleci-webhook-test" + expected_topic_name = "circleci-webhook-test" expected_message = """ Workflow [`sample`](https://app.circleci.com/pipelines/github/prah23/circleci-webhook-test/20/workflows/045c6271-78e2-4802-8a62-f4fa6d25d0c9) within Pipeline #20 has succeeded. Triggered on the latest tag on [0e6e66c14e6](https://github.com/prah23/circleci-webhook-test/commit/0e6e66c14e61fbcd95db716b0f30d67dbcce7814). """.strip() - self.check_webhook("github_tag_workflow_completed", expected_topic, expected_message) + self.check_webhook("github_tag_workflow_completed", expected_topic_name, expected_message) def test_github_workflow_completed(self) -> None: - expected_topic = "circleci-webhook-test" + expected_topic_name = "circleci-webhook-test" expected_message = """ Workflow [`sample`](https://app.circleci.com/pipelines/github/zulip-testing/circleci-webhook-test/4/workflows/7381218b-d04c-4aa3-b8b8-8c00a9319d1f) within Pipeline #4 has succeeded. Triggered on [`a5e30a90822: .circleci: Update Webhook URL.`](https://github.com/zulip-testing/circleci-webhook-test/commit/a5e30a908224e46626a796d058289475f6d387b5) on branch `main` by Hari Prashant Bhimaraju. """.strip() - self.check_webhook("github_workflow_completed", expected_topic, expected_message) + self.check_webhook("github_workflow_completed", expected_topic_name, expected_message) def test_gitlab_job_completed(self) -> None: - expected_topic = "circleci-webhook-test" + expected_topic_name = "circleci-webhook-test" expected_message = """ Job `build-and-test` within Pipeline #3 has succeeded. Triggered on [`c31f86994c5: app: Enhance message within hello().`](https://gitlab.com/zulip-testing/circleci-webhook-test/-/commit/c31f86994c54672f97b5bd5e544315b7bd40e4c1) on branch `main` by Hari Prashant Bhimaraju. """.strip() - self.check_webhook("gitlab_job_completed", expected_topic, expected_message) + self.check_webhook("gitlab_job_completed", expected_topic_name, expected_message) def test_gitlab_workflow_completed(self) -> None: - expected_topic = "circleci-webhook-test" + expected_topic_name = "circleci-webhook-test" expected_message = """ Workflow [`sample`](https://app.circleci.com/pipelines/circleci/89xcrx7UvWQfzcUPAEmu5Q/63AY3yf3XeUQojmQcGZTtB/3/workflows/b23ceb64-127a-4075-a27c-d204a7a0a3b3) within Pipeline #3 has succeeded. Triggered on [`c31f86994c5: app: Enhance message within hello().`](https://gitlab.com/zulip-testing/circleci-webhook-test/-/commit/c31f86994c54672f97b5bd5e544315b7bd40e4c1) on branch `main` by Hari Prashant Bhimaraju. """.strip() - self.check_webhook("gitlab_workflow_completed", expected_topic, expected_message) + self.check_webhook("gitlab_workflow_completed", expected_topic_name, expected_message) diff --git a/zerver/webhooks/circleci/view.py b/zerver/webhooks/circleci/view.py index dcf78c5190..c2dfc94b3f 100644 --- a/zerver/webhooks/circleci/view.py +++ b/zerver/webhooks/circleci/view.py @@ -67,12 +67,12 @@ def api_circleci_webhook( type = payload["type"].tame(check_string) if type == "ping": # Ping events don't have full payloads, so our normal codepath won't work - topic = "Test event" + topic_name = "Test event" body = "Webhook '{name}' test event successful.".format( name=payload["webhook"]["name"].tame(check_string) ) else: - topic = get_topic(payload) + topic_name = get_topic(payload) body = get_body(payload) # We currently don't support projects using VCS providers other than GitHub, @@ -86,7 +86,7 @@ def api_circleci_webhook( check_send_webhook_message( request, user_profile, - topic, + topic_name, body, payload["type"].tame(check_string), ) diff --git a/zerver/webhooks/clubhouse/view.py b/zerver/webhooks/clubhouse/view.py index abcf493618..059299e85b 100644 --- a/zerver/webhooks/clubhouse/view.py +++ b/zerver/webhooks/clubhouse/view.py @@ -696,11 +696,11 @@ def send_stream_messages_for_actions( if body_func is None or topic_func is None: raise UnsupportedWebhookEventTypeError(event) - topic = topic_func(payload, action) + topic_name = topic_func(payload, action) body = body_func(payload, action) - if topic and body: - check_send_webhook_message(request, user_profile, topic, body, event) + if topic_name and body: + check_send_webhook_message(request, user_profile, topic_name, body, event) EVENT_BODY_FUNCTION_MAPPER: Dict[str, Callable[[WildValue, WildValue], Optional[str]]] = { diff --git a/zerver/webhooks/codeship/tests.py b/zerver/webhooks/codeship/tests.py index ff09f74981..605cff4836 100644 --- a/zerver/webhooks/codeship/tests.py +++ b/zerver/webhooks/codeship/tests.py @@ -4,7 +4,7 @@ from zerver.lib.test_classes import WebhookTestCase class CodeshipHookTests(WebhookTestCase): STREAM_NAME = "codeship" URL_TEMPLATE = "/api/v1/external/codeship?stream={stream}&api_key={api_key}" - TOPIC = "codeship/docs" + TOPIC_NAME = "codeship/docs" WEBHOOK_DIR_NAME = "codeship" def test_codeship_build_in_testing_status_message(self) -> None: @@ -12,25 +12,25 @@ class CodeshipHookTests(WebhookTestCase): Tests if codeship testing status is mapped correctly """ expected_message = "[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch started." - self.check_webhook("testing_build", self.TOPIC, expected_message) + self.check_webhook("testing_build", self.TOPIC_NAME, expected_message) def test_codeship_build_in_error_status_message(self) -> None: """ Tests if codeship error status is mapped correctly """ expected_message = "[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch failed." - self.check_webhook("error_build", self.TOPIC, expected_message) + self.check_webhook("error_build", self.TOPIC_NAME, expected_message) def test_codeship_build_in_success_status_message(self) -> None: """ Tests if codeship success status is mapped correctly """ expected_message = "[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch succeeded." - self.check_webhook("success_build", self.TOPIC, expected_message) + self.check_webhook("success_build", self.TOPIC_NAME, expected_message) def test_codeship_build_in_other_status_status_message(self) -> None: """ Tests if codeship other status is mapped correctly """ expected_message = "[Build](https://www.codeship.com/projects/10213/builds/973711) triggered by beanieboi on master branch has some_other_status status." - self.check_webhook("other_status_build", self.TOPIC, expected_message) + self.check_webhook("other_status_build", self.TOPIC_NAME, expected_message) diff --git a/zerver/webhooks/codeship/view.py b/zerver/webhooks/codeship/view.py index 3d5efca07f..029f004a94 100644 --- a/zerver/webhooks/codeship/view.py +++ b/zerver/webhooks/codeship/view.py @@ -30,10 +30,10 @@ def api_codeship_webhook( payload: JsonBodyPayload[WildValue], ) -> HttpResponse: payload = payload["build"] - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) body = get_body_for_http_request(payload) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/crashlytics/tests.py b/zerver/webhooks/crashlytics/tests.py index 6b7b4a8855..58249a5b64 100644 --- a/zerver/webhooks/crashlytics/tests.py +++ b/zerver/webhooks/crashlytics/tests.py @@ -7,13 +7,13 @@ class CrashlyticsHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "crashlytics" def test_crashlytics_verification_message(self) -> None: - expected_topic = "Setup" + expected_topic_name = "Setup" expected_message = "Webhook has been successfully configured." - self.check_webhook("verification", expected_topic, expected_message) + self.check_webhook("verification", expected_topic_name, expected_message) def test_crashlytics_build_in_success_status(self) -> None: - expected_topic = "123: Issue Title" + expected_topic_name = "123: Issue Title" expected_message = ( "[Issue](http://crashlytics.com/full/url/to/issue) impacts at least 16 device(s)." ) - self.check_webhook("issue_message", expected_topic, expected_message) + self.check_webhook("issue_message", expected_topic_name, expected_message) diff --git a/zerver/webhooks/crashlytics/view.py b/zerver/webhooks/crashlytics/view.py index 298a2b4681..aa481589f9 100644 --- a/zerver/webhooks/crashlytics/view.py +++ b/zerver/webhooks/crashlytics/view.py @@ -27,11 +27,11 @@ def api_crashlytics_webhook( ) -> HttpResponse: event = payload["event"] if event == VERIFICATION_EVENT: - topic = CRASHLYTICS_SETUP_TOPIC_TEMPLATE + topic_name = CRASHLYTICS_SETUP_TOPIC_TEMPLATE body = CRASHLYTICS_SETUP_MESSAGE_TEMPLATE else: issue_body = payload["payload"] - topic = CRASHLYTICS_TOPIC_TEMPLATE.format( + topic_name = CRASHLYTICS_TOPIC_TEMPLATE.format( display_id=issue_body["display_id"].tame(check_int), title=issue_body["title"].tame(check_string), ) @@ -40,5 +40,5 @@ def api_crashlytics_webhook( url=issue_body["url"].tame(check_string), ) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/delighted/tests.py b/zerver/webhooks/delighted/tests.py index 3e77179fd4..212be2bcdc 100644 --- a/zerver/webhooks/delighted/tests.py +++ b/zerver/webhooks/delighted/tests.py @@ -7,7 +7,7 @@ class DelightedHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "delighted" def test_feedback_message_promoter(self) -> None: - expected_topic = "Survey response" + expected_topic_name = "Survey response" expected_message = """ Kudos! You have a new promoter. Score of 9/10 from charlie_gravis@example.com: @@ -18,13 +18,13 @@ Your service is fast and flawless! self.check_webhook( "survey_response_updated_promoter", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_feedback_message_non_promoter(self) -> None: - expected_topic = "Survey response" + expected_topic_name = "Survey response" expected_message = ( "Great! You have new feedback.\n" ">Score of 5/10 from paul_gravis@example.com" @@ -41,7 +41,7 @@ Your service is slow, but nearly flawless! Keep up the good work! self.check_webhook( "survey_response_updated_non_promoter", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/delighted/view.py b/zerver/webhooks/delighted/view.py index 5629cbe370..729e5fb9ea 100644 --- a/zerver/webhooks/delighted/view.py +++ b/zerver/webhooks/delighted/view.py @@ -46,7 +46,7 @@ def api_delighted_webhook( BODY_TEMPLATE = body_template(score) body = BODY_TEMPLATE.format(email=email, score=score, comment=comment) - topic = "Survey response" + topic_name = "Survey response" - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/deskdotcom/tests.py b/zerver/webhooks/deskdotcom/tests.py index 3766865b4a..0140230f77 100644 --- a/zerver/webhooks/deskdotcom/tests.py +++ b/zerver/webhooks/deskdotcom/tests.py @@ -19,19 +19,19 @@ class DeskDotComHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "deskdotcom" def test_static_text_message(self) -> None: - expected_topic = "static text notification" + expected_topic_name = "static text notification" expected_message = "This is a custom action." self.api_stream_message( self.test_user, "static_text", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_case_updated_message(self) -> None: - expected_topic = "case updated notification" + expected_topic_name = "case updated notification" expected_message = ( "Case 2 updated. " "Link: " @@ -41,13 +41,13 @@ class DeskDotComHookTests(WebhookTestCase): self.api_stream_message( self.test_user, "case_updated", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_unicode_text_italian(self) -> None: - expected_topic = "case updated notification" + expected_topic_name = "case updated notification" expected_message = ( "Case 2 updated. " "Link: " @@ -57,13 +57,13 @@ class DeskDotComHookTests(WebhookTestCase): self.api_stream_message( self.test_user, "unicode_text_italian", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_unicode_text_japanese(self) -> None: - expected_topic = "case updated notification" + expected_topic_name = "case updated notification" expected_message = ( "Case 2 updated. " "Link: " @@ -73,7 +73,7 @@ class DeskDotComHookTests(WebhookTestCase): self.api_stream_message( self.test_user, "unicode_text_japanese", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/deskdotcom/view.py b/zerver/webhooks/deskdotcom/view.py index d4b3cb0672..e53b482472 100644 --- a/zerver/webhooks/deskdotcom/view.py +++ b/zerver/webhooks/deskdotcom/view.py @@ -21,6 +21,6 @@ def api_deskdotcom_webhook( *, data: str, ) -> HttpResponse: - topic = "Desk.com notification" - check_send_webhook_message(request, user_profile, topic, data) + topic_name = "Desk.com notification" + check_send_webhook_message(request, user_profile, topic_name, data) return json_success(request) diff --git a/zerver/webhooks/dropbox/tests.py b/zerver/webhooks/dropbox/tests.py index 44f2eb4254..6001f6e980 100644 --- a/zerver/webhooks/dropbox/tests.py +++ b/zerver/webhooks/dropbox/tests.py @@ -8,12 +8,12 @@ class DropboxHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "dropbox" def test_file_updated(self) -> None: - expected_topic = "Dropbox" + expected_topic_name = "Dropbox" expected_message = "File has been updated on Dropbox!" self.check_webhook( "file_updated", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/dropbox/view.py b/zerver/webhooks/dropbox/view.py index 8dbaa25abc..9658fca715 100644 --- a/zerver/webhooks/dropbox/view.py +++ b/zerver/webhooks/dropbox/view.py @@ -19,9 +19,9 @@ def api_dropbox_webhook( challenge: Optional[str] = None, ) -> HttpResponse: if request.method == "POST": - topic = "Dropbox" + topic_name = "Dropbox" check_send_webhook_message( - request, user_profile, topic, "File has been updated on Dropbox!" + request, user_profile, topic_name, "File has been updated on Dropbox!" ) return json_success(request) else: diff --git a/zerver/webhooks/errbit/tests.py b/zerver/webhooks/errbit/tests.py index 78f8f1586d..633c52d439 100644 --- a/zerver/webhooks/errbit/tests.py +++ b/zerver/webhooks/errbit/tests.py @@ -7,6 +7,6 @@ class ErrBitHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "errbit" def test_errbit_error_message(self) -> None: - expected_topic = "ZulipIntegrationTest / ErrbitEnvName" + expected_topic_name = "ZulipIntegrationTest / ErrbitEnvName" expected_message = '[IllegalStateException](https://errbit.example.com/apps/5e1ed1ff1a603f3916f4f0de/problems/5e1fe93e1a603f3916f4f0e3): "Invalid state error" occurred.' - self.check_webhook("error_message", expected_topic, expected_message) + self.check_webhook("error_message", expected_topic_name, expected_message) diff --git a/zerver/webhooks/errbit/view.py b/zerver/webhooks/errbit/view.py index 64a9a92385..a54f2c0e02 100644 --- a/zerver/webhooks/errbit/view.py +++ b/zerver/webhooks/errbit/view.py @@ -19,9 +19,9 @@ def api_errbit_webhook( *, payload: JsonBodyPayload[WildValue], ) -> HttpResponse: - topic = get_topic(payload) + topic_name = get_topic(payload) body = get_body(payload) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/flock/tests.py b/zerver/webhooks/flock/tests.py index 9fe219f805..7a8f4be7a9 100644 --- a/zerver/webhooks/flock/tests.py +++ b/zerver/webhooks/flock/tests.py @@ -7,71 +7,71 @@ class FlockHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "flock" def test_flock_message(self) -> None: - expected_topic = "Flock notifications" + expected_topic_name = "Flock notifications" expected_message = "This is the welcome message!" self.check_webhook( - "messages", expected_topic, expected_message, content_type="application/json" + "messages", expected_topic_name, expected_message, content_type="application/json" ) def test_flock_reply(self) -> None: - expected_topic = "Flock notifications" + expected_topic_name = "Flock notifications" expected_message = "It's interesting how high productivity will go..." self.check_webhook( - "reply", expected_topic, expected_message, content_type="application/json" + "reply", expected_topic_name, expected_message, content_type="application/json" ) def test_flock_note(self) -> None: - expected_topic = "Flock notifications" + expected_topic_name = "Flock notifications" expected_message = "Shared a note" self.check_webhook( - "note", expected_topic, expected_message, content_type="application/json" + "note", expected_topic_name, expected_message, content_type="application/json" ) def test_flock_reply_note(self) -> None: - expected_topic = "Flock notifications" + expected_topic_name = "Flock notifications" expected_message = "This is reply to Note." self.check_webhook( - "reply_note", expected_topic, expected_message, content_type="application/json" + "reply_note", expected_topic_name, expected_message, content_type="application/json" ) def test_flock_reply_pinned(self) -> None: - expected_topic = "Flock notifications" + expected_topic_name = "Flock notifications" expected_message = "This is reply to pinned message." self.check_webhook( - "reply_pinned", expected_topic, expected_message, content_type="application/json" + "reply_pinned", expected_topic_name, expected_message, content_type="application/json" ) def test_flock_reply_reminder(self) -> None: - expected_topic = "Flock notifications" + expected_topic_name = "Flock notifications" expected_message = "This is a reply to Reminder." self.check_webhook( - "reply_reminder", expected_topic, expected_message, content_type="application/json" + "reply_reminder", expected_topic_name, expected_message, content_type="application/json" ) def test_flock_reply_todo(self) -> None: - expected_topic = "Flock notifications" + expected_topic_name = "Flock notifications" expected_message = "This is a reply to Todo notification." self.check_webhook( - "reply_todo", expected_topic, expected_message, content_type="application/json" + "reply_todo", expected_topic_name, expected_message, content_type="application/json" ) def test_flock_pinned(self) -> None: - expected_topic = "Flock notifications" + expected_topic_name = "Flock notifications" expected_message = "Rishabh rawat pinned an item to the conversation" self.check_webhook( - "pinned", expected_topic, expected_message, content_type="application/json" + "pinned", expected_topic_name, expected_message, content_type="application/json" ) def test_flock_reminder(self) -> None: - expected_topic = "Flock notifications" + expected_topic_name = "Flock notifications" expected_message = "Rishabh rawat wanted me to remind All" self.check_webhook( - "reminder", expected_topic, expected_message, content_type="application/json" + "reminder", expected_topic_name, expected_message, content_type="application/json" ) def test_flock_todo(self) -> None: - expected_topic = "Flock notifications" + expected_topic_name = "Flock notifications" expected_message = "Rishabh rawat added a to-do in New List 1 list" self.check_webhook( - "todo", expected_topic, expected_message, content_type="application/json" + "todo", expected_topic_name, expected_message, content_type="application/json" ) diff --git a/zerver/webhooks/flock/view.py b/zerver/webhooks/flock/view.py index a43c8771d1..d8dbaf6105 100644 --- a/zerver/webhooks/flock/view.py +++ b/zerver/webhooks/flock/view.py @@ -23,9 +23,9 @@ def api_flock_webhook( else: message_body = payload["notification"].tame(check_string) - topic = "Flock notifications" + topic_name = "Flock notifications" body = f"{message_body}" - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/freshdesk/tests.py b/zerver/webhooks/freshdesk/tests.py index bdb2da1e80..c754ca0829 100644 --- a/zerver/webhooks/freshdesk/tests.py +++ b/zerver/webhooks/freshdesk/tests.py @@ -13,7 +13,7 @@ class FreshdeskHookTests(WebhookTestCase): Messages are generated on ticket creation through Freshdesk's "Dispatch'r" service. """ - expected_topic = "#11: Test ticket subject ☃" + expected_topic_name = "#11: Test ticket subject ☃" expected_message = """ Requester ☃ Bob created [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11): @@ -29,7 +29,7 @@ Test ticket description ☃. self.api_stream_message( self.test_user, "ticket_created", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -39,7 +39,7 @@ Test ticket description ☃. Messages are generated when a ticket's status changes through Freshdesk's "Observer" service. """ - expected_topic = "#11: Test ticket subject ☃" + expected_topic_name = "#11: Test ticket subject ☃" expected_message = """ Requester Bob updated [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11): @@ -49,7 +49,7 @@ Requester Bob updated [ticket #11](http://test1234zz self.api_stream_message( self.test_user, "status_changed", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -59,7 +59,7 @@ Requester Bob updated [ticket #11](http://test1234zz Messages are generated when a ticket's priority changes through Freshdesk's "Observer" service. """ - expected_topic = "#11: Test ticket subject" + expected_topic_name = "#11: Test ticket subject" expected_message = """ Requester Bob updated [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11): @@ -68,7 +68,7 @@ Requester Bob updated [ticket #11](http://test1234zz self.api_stream_message( self.test_user, "priority_changed", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -94,7 +94,7 @@ Requester Bob updated [ticket #11](http://test1234zz Messages are generated when a note gets added to a ticket through Freshdesk's "Observer" service. """ - expected_topic = "#11: Test ticket subject" + expected_topic_name = "#11: Test ticket subject" expected_message = """ Requester Bob added a {} note to \ [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11). @@ -104,7 +104,7 @@ Requester Bob added a {} note to \ self.api_stream_message( self.test_user, fixture, - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -121,14 +121,14 @@ Requester Bob added a {} note to \ descriptions Zulip Markdown-friendly while still doing our best to preserve links and images. """ - expected_topic = "#12: Not enough ☃ guinea pigs" + expected_topic_name = "#12: Not enough ☃ guinea pigs" expected_message = """ Requester \u2603 Bob created [ticket #12](http://test1234zzz.freshdesk.com/helpdesk/tickets/12):\n\n``` quote\nThere are too many cat pictures on the internet \u2603. We need more guinea pigs.\nExhibit 1:\n\n \n\n[guinea_pig.png](http://cdn.freshdesk.com/data/helpdesk/attachments/production/12744808/original/guinea_pig.png)\n```\n\n* **Type**: Problem\n* **Priority**: Urgent\n* **Status**: Open """.strip() self.api_stream_message( self.test_user, "inline_images", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/freshdesk/view.py b/zerver/webhooks/freshdesk/view.py index 789ce44922..0d4c481cee 100644 --- a/zerver/webhooks/freshdesk/view.py +++ b/zerver/webhooks/freshdesk/view.py @@ -140,7 +140,7 @@ def api_freshdesk_webhook( ) -> HttpResponse: ticket = payload["freshdesk_webhook"] - topic = ( + topic_name = ( f"#{ticket['ticket_id'].tame(check_string)}: {ticket['ticket_subject'].tame(check_string)}" ) event_info = parse_freshdesk_event(ticket["triggered_event"].tame(check_string)) @@ -155,5 +155,5 @@ def api_freshdesk_webhook( # Not an event we know handle; do nothing. return json_success(request) - check_send_webhook_message(request, user_profile, topic, content) + check_send_webhook_message(request, user_profile, topic_name, content) return json_success(request) diff --git a/zerver/webhooks/freshping/tests.py b/zerver/webhooks/freshping/tests.py index 788122fbcc..134fa1248a 100644 --- a/zerver/webhooks/freshping/tests.py +++ b/zerver/webhooks/freshping/tests.py @@ -10,25 +10,25 @@ class FreshpingHookTests(WebhookTestCase): """ Tests if freshping check test is handled correctly """ - expected_topic = "Freshping" + expected_topic_name = "Freshping" expected_message = "Freshping webhook has been successfully configured." - self.check_webhook("freshping_check_test", expected_topic, expected_message) + self.check_webhook("freshping_check_test", expected_topic_name, expected_message) def test_freshping_check_unreachable(self) -> None: """ Tests if freshping check unreachable is handled correctly """ - expected_topic = "Test Check" + expected_topic_name = "Test Check" expected_message = """ https://example.com has just become unreachable. Error code: 521. """.strip() - self.check_webhook("freshping_check_unreachable", expected_topic, expected_message) + self.check_webhook("freshping_check_unreachable", expected_topic_name, expected_message) def test_freshping_check_reachable(self) -> None: """ Tests if freshping check reachable is handled correctly """ - expected_topic = "Test Check" + expected_topic_name = "Test Check" expected_message = "https://example.com is back up and no longer unreachable." - self.check_webhook("freshping_check_reachable", expected_topic, expected_message) + self.check_webhook("freshping_check_reachable", expected_topic_name, expected_message) diff --git a/zerver/webhooks/freshping/view.py b/zerver/webhooks/freshping/view.py index 173b0c8f22..96b3ecbc29 100644 --- a/zerver/webhooks/freshping/view.py +++ b/zerver/webhooks/freshping/view.py @@ -32,12 +32,12 @@ def api_freshping_webhook( if check_state_name not in CHECK_STATE_NAME_TO_EVENT_TYPE: raise UnsupportedWebhookEventTypeError(check_state_name) body = get_body_for_http_request(payload) - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) check_send_webhook_message( request, user_profile, - topic, + topic_name, body, CHECK_STATE_NAME_TO_EVENT_TYPE[check_state_name], ) @@ -47,12 +47,12 @@ def api_freshping_webhook( def get_topic_for_http_request(payload: WildValue) -> str: webhook_event_data = payload["webhook_event_data"] if webhook_event_data["application_name"].tame(check_string) == "Webhook test": - topic = FRESHPING_TOPIC_TEMPLATE_TEST + topic_name = FRESHPING_TOPIC_TEMPLATE_TEST else: - topic = FRESHPING_TOPIC_TEMPLATE.format( + topic_name = FRESHPING_TOPIC_TEMPLATE.format( check_name=webhook_event_data["check_name"].tame(check_string) ) - return topic + return topic_name def get_body_for_http_request(payload: WildValue) -> str: diff --git a/zerver/webhooks/freshstatus/tests.py b/zerver/webhooks/freshstatus/tests.py index a4fd29e04e..2ac1c623a1 100644 --- a/zerver/webhooks/freshstatus/tests.py +++ b/zerver/webhooks/freshstatus/tests.py @@ -13,7 +13,7 @@ class FreshstatusHookTests(WebhookTestCase): """ Tests if freshstatus incident open multiple services is handled correctly """ - expected_topic = "Degradation of Multiple Servers" + expected_topic_name = "Degradation of Multiple Servers" expected_message = """ The following incident has been opened: **Degradation of Multiple Servers** **Description:** This issue is being investigated. @@ -24,14 +24,14 @@ The following incident has been opened: **Degradation of Multiple Servers** * Web Server 2 """.strip() self.check_webhook( - "freshstatus_incident_open_multiple_services", expected_topic, expected_message + "freshstatus_incident_open_multiple_services", expected_topic_name, expected_message ) def test_freshstatus_incident_open_multiple_services_over_limit(self) -> None: """ Tests if freshstatus incident open multiple services over limit is handled correctly """ - expected_topic = "Degradation of Multiple Servers" + expected_topic_name = "Degradation of Multiple Servers" expected_message = """ The following incident has been opened: **Degradation of Multiple Servers** **Description:** This issue is being investigated. @@ -46,7 +46,7 @@ The following incident has been opened: **Degradation of Multiple Servers** """.strip() self.check_webhook( "freshstatus_incident_open_multiple_services_over_limit", - expected_topic, + expected_topic_name, expected_message, ) @@ -54,7 +54,7 @@ The following incident has been opened: **Degradation of Multiple Servers** """ Tests if freshstatus incident open is handled correctly """ - expected_topic = "Degradation of Database Server" + expected_topic_name = "Degradation of Database Server" expected_message = """ The following incident has been opened: **Degradation of Database Server** **Description:** This issue is being investigated. @@ -62,35 +62,37 @@ The following incident has been opened: **Degradation of Database Server** **Affected Services:** * Database Server """.strip() - self.check_webhook("freshstatus_incident_open", expected_topic, expected_message) + self.check_webhook("freshstatus_incident_open", expected_topic_name, expected_message) def test_freshstatus_incident_note_created(self) -> None: """ Tests if freshstatus incident note created is handled correctly """ - expected_topic = "Degradation of Database Server" + expected_topic_name = "Degradation of Database Server" expected_message = """ The following note has been added to the incident: **Degradation of Database Server** **Note:** The incident is being worked on. """.strip() - self.check_webhook("freshstatus_incident_note_created", expected_topic, expected_message) + self.check_webhook( + "freshstatus_incident_note_created", expected_topic_name, expected_message + ) def test_freshstatus_incident_closed(self) -> None: """ Tests if freshstatus incident closed is handled correctly """ - expected_topic = "Degradation of Database Server" + expected_topic_name = "Degradation of Database Server" expected_message = """ The following incident has been closed: **Degradation of Database Server** **Note:** The incident has been resolved. """.strip() - self.check_webhook("freshstatus_incident_closed", expected_topic, expected_message) + self.check_webhook("freshstatus_incident_closed", expected_topic_name, expected_message) def test_freshstatus_scheduled_maintenance_planned(self) -> None: """ Tests if freshstatus scheduled maintenance planned is handled correctly """ - expected_topic = "Expect some services downtime due to server maintenance" + expected_topic_name = "Expect some services downtime due to server maintenance" expected_message = """ The following scheduled maintenance has been opened: **Expect some services downtime due to server maintenance** **Description:** As part of the upgrade routine, we will be carrying out server maintenance work for this Service. This work will affect the Service to be unavailable during the maintenance window. We apologize for any inconvenience this may cause. Please do not hesitate to contact our support team at support@example.com if you have any questions regarding this server upgrading exercise. @@ -100,14 +102,14 @@ The following scheduled maintenance has been opened: **Expect some services down * Sample Service """.strip() self.check_webhook( - "freshstatus_scheduled_maintenance_planned", expected_topic, expected_message + "freshstatus_scheduled_maintenance_planned", expected_topic_name, expected_message ) def test_freshstatus_scheduled_maintenance_planned_multiple_services(self) -> None: """ Tests if freshstatus scheduled maintenance planned multiple services is handled correctly """ - expected_topic = "Expect some services downtime due to server maintenance" + expected_topic_name = "Expect some services downtime due to server maintenance" expected_message = """ The following scheduled maintenance has been opened: **Expect some services downtime due to server maintenance** **Description:** As part of the upgrade routine, we will be carrying out server maintenance work for this Service. This work will affect the Service to be unavailable during the maintenance window. We apologize for any inconvenience this may cause. Please do not hesitate to contact our support team at support@example.com if you have any questions regarding this server upgrading exercise. @@ -119,7 +121,7 @@ The following scheduled maintenance has been opened: **Expect some services down """.strip() self.check_webhook( "freshstatus_scheduled_maintenance_planned_multiple_services", - expected_topic, + expected_topic_name, expected_message, ) @@ -127,7 +129,7 @@ The following scheduled maintenance has been opened: **Expect some services down """ Tests if freshstatus scheduled maintenance planned multiple services over limit is handled correctly """ - expected_topic = "Expect some services downtime due to server maintenance" + expected_topic_name = "Expect some services downtime due to server maintenance" expected_message = """ The following scheduled maintenance has been opened: **Expect some services downtime due to server maintenance** **Description:** As part of the upgrade routine, we will be carrying out server maintenance work for this Service. This work will affect the Service to be unavailable during the maintenance window. We apologize for any inconvenience this may cause. Please do not hesitate to contact our support team at support@example.com if you have any questions regarding this server upgrading exercise. @@ -143,7 +145,7 @@ The following scheduled maintenance has been opened: **Expect some services down """.strip() self.check_webhook( "freshstatus_scheduled_maintenance_planned_multiple_services_over_limit", - expected_topic, + expected_topic_name, expected_message, ) @@ -151,43 +153,43 @@ The following scheduled maintenance has been opened: **Expect some services down """ Tests if freshstatus scheduled maintenance note created is handled correctly """ - expected_topic = "Scheduled Maintenance Test" + expected_topic_name = "Scheduled Maintenance Test" expected_message = """ The following note has been added to the scheduled maintenance: **Scheduled Maintenance Test** **Note:** We are about to start the maintenance. """.strip() self.check_webhook( - "freshstatus_scheduled_maintenance_note_created", expected_topic, expected_message + "freshstatus_scheduled_maintenance_note_created", expected_topic_name, expected_message ) def test_freshstatus_scheduled_maintenance_closed(self) -> None: """ Tests if freshstatus scheduled maintenance closed is handled correctly """ - expected_topic = "Scheduled Maintenance Test" + expected_topic_name = "Scheduled Maintenance Test" expected_message = """ The following scheduled maintenance has been closed: **Scheduled Maintenance Test** **Note:** The maintenance is now complete. """.strip() self.check_webhook( - "freshstatus_scheduled_maintenance_closed", expected_topic, expected_message + "freshstatus_scheduled_maintenance_closed", expected_topic_name, expected_message ) def test_freshstatus_test(self) -> None: """ Tests if freshstatus test is handled correctly """ - expected_topic = "Freshstatus" + expected_topic_name = "Freshstatus" expected_message = "Freshstatus webhook has been successfully configured." - self.check_webhook("freshstatus_test", expected_topic, expected_message) + self.check_webhook("freshstatus_test", expected_topic_name, expected_message) def test_freshstatus_event_not_supported(self) -> None: """ Tests if freshstatus event not supported is handled correctly """ - expected_topic = "Sample title" + expected_topic_name = "Sample title" expected_message = "The event (INCIDENT_REOPEN) is not supported yet." - self.check_webhook("freshstatus_event_not_supported", expected_topic, expected_message) + self.check_webhook("freshstatus_event_not_supported", expected_topic_name, expected_message) def test_freshstatus_invalid_payload_with_missing_data(self) -> None: """ diff --git a/zerver/webhooks/freshstatus/view.py b/zerver/webhooks/freshstatus/view.py index f77c40c275..5368da62bb 100644 --- a/zerver/webhooks/freshstatus/view.py +++ b/zerver/webhooks/freshstatus/view.py @@ -88,7 +88,7 @@ def api_freshstatus_webhook( ) -> HttpResponse: try: body = get_body_for_http_request(payload) - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) except ValidationError: message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format( bot_name=user_profile.full_name, @@ -99,7 +99,11 @@ def api_freshstatus_webhook( raise JsonableError(_("Invalid payload")) check_send_webhook_message( - request, user_profile, topic, body, payload["event_data"]["event_type"].tame(check_string) + request, + user_profile, + topic_name, + body, + payload["event_data"]["event_type"].tame(check_string), ) return json_success(request) diff --git a/zerver/webhooks/front/tests.py b/zerver/webhooks/front/tests.py index 32976c6d3b..a4c4983d09 100644 --- a/zerver/webhooks/front/tests.py +++ b/zerver/webhooks/front/tests.py @@ -12,18 +12,18 @@ class FrontHookTests(WebhookTestCase): # Conversation automatically assigned to a teammate who started it. def test_conversation_assigned_outbound(self) -> None: - expected_topic = "cnv_keo696" + expected_topic_name = "cnv_keo696" expected_message = "**Leela Turanga** assigned themselves." self.check_webhook( "conversation_assigned_outbound", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_outbound_message(self) -> None: - expected_topic = "cnv_keo696" + expected_topic_name = "cnv_keo696" expected_message = ( "[Outbound message](https://app.frontapp.com/open/msg_1176ie2) " "from **support@planet-express.com** " @@ -33,68 +33,68 @@ class FrontHookTests(WebhookTestCase): self.check_webhook( "outbound_message", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_conversation_archived(self) -> None: - expected_topic = "cnv_keo696" + expected_topic_name = "cnv_keo696" expected_message = "Archived by **Leela Turanga**." self.check_webhook( "conversation_archived", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_conversation_reopened(self) -> None: - expected_topic = "cnv_keo696" + expected_topic_name = "cnv_keo696" expected_message = "Reopened by **Leela Turanga**." self.check_webhook( "conversation_reopened", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_conversation_deleted(self) -> None: - expected_topic = "cnv_keo696" + expected_topic_name = "cnv_keo696" expected_message = "Deleted by **Leela Turanga**." self.check_webhook( "conversation_deleted", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_conversation_restored(self) -> None: - expected_topic = "cnv_keo696" + expected_topic_name = "cnv_keo696" expected_message = "Restored by **Leela Turanga**." self.check_webhook( "conversation_restored", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_conversation_unassigned(self) -> None: - expected_topic = "cnv_keo696" + expected_topic_name = "cnv_keo696" expected_message = "Unassigned by **Leela Turanga**." self.check_webhook( "conversation_unassigned", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_mention_all(self) -> None: - expected_topic = "cnv_keo696" + expected_topic_name = "cnv_keo696" expected_message = ( "**Leela Turanga** left a comment:\n" "```quote\n@all Could someone else take this?\n```" @@ -102,7 +102,7 @@ class FrontHookTests(WebhookTestCase): self.check_webhook( "mention_all", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -110,7 +110,7 @@ class FrontHookTests(WebhookTestCase): # Scenario 2: Conversation starts from an inbound message. def test_inbound_message(self) -> None: - expected_topic = "cnv_keocka" + expected_topic_name = "cnv_keocka" expected_message = ( "[Inbound message](https://app.frontapp.com/open/msg_1176r8y) " "from **calculon@momsbot.com** " @@ -120,36 +120,36 @@ class FrontHookTests(WebhookTestCase): self.check_webhook( "inbound_message", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_conversation_tagged(self) -> None: - expected_topic = "cnv_keocka" + expected_topic_name = "cnv_keocka" expected_message = "**Leela Turanga** added tag **Urgent**." self.check_webhook( "conversation_tagged", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) # Conversation automatically assigned to a teammate who replied to it. def test_conversation_assigned_reply(self) -> None: - expected_topic = "cnv_keocka" + expected_topic_name = "cnv_keocka" expected_message = "**Leela Turanga** assigned themselves." self.check_webhook( "conversation_assigned_reply", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_outbound_reply(self) -> None: - expected_topic = "cnv_keocka" + expected_topic_name = "cnv_keocka" expected_message = ( "[Outbound reply](https://app.frontapp.com/open/msg_1176ryy) " "from **support@planet-express.com** " @@ -158,24 +158,24 @@ class FrontHookTests(WebhookTestCase): self.check_webhook( "outbound_reply", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_conversation_untagged(self) -> None: - expected_topic = "cnv_keocka" + expected_topic_name = "cnv_keocka" expected_message = "**Leela Turanga** removed tag **Urgent**." self.check_webhook( "conversation_untagged", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_mention(self) -> None: - expected_topic = "cnv_keocka" + expected_topic_name = "cnv_keocka" expected_message = ( "**Leela Turanga** left a comment:\n" "```quote\n@bender Could you take it from here?\n```" @@ -183,52 +183,52 @@ class FrontHookTests(WebhookTestCase): self.check_webhook( "mention", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_comment(self) -> None: - expected_topic = "cnv_keocka" + expected_topic_name = "cnv_keocka" expected_message = "**Bender Rodriguez** left a comment:\n```quote\nSure.\n```" self.check_webhook( "comment", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) # Conversation manually assigned to another teammate. def test_conversation_assigned(self) -> None: - expected_topic = "cnv_keocka" + expected_topic_name = "cnv_keocka" expected_message = "**Leela Turanga** assigned **Bender Rodriguez**." self.check_webhook( "conversation_assigned", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_conversation_assigned_by_rule(self) -> None: - expected_topic = "cnv_keocka" + expected_topic_name = "cnv_keocka" expected_message = "**'Important deliveries' rule** assigned **Bender Rodriguez**." self.check_webhook( "rule", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_conversation_assigned_by_gmail(self) -> None: - expected_topic = "cnv_keo696" + expected_topic_name = "cnv_keo696" expected_message = "Archived by **(gmail)**." self.check_webhook( "gmail", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/front/view.py b/zerver/webhooks/front/view.py index e6d437da7b..f323c3801d 100644 --- a/zerver/webhooks/front/view.py +++ b/zerver/webhooks/front/view.py @@ -147,8 +147,8 @@ def api_front_webhook( if event not in EVENT_FUNCTION_MAPPER: raise JsonableError(_("Unknown webhook request")) - topic = payload["conversation"]["id"].tame(check_string) + topic_name = payload["conversation"]["id"].tame(check_string) body = get_body_based_on_event(event)(payload) - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/gci/tests.py b/zerver/webhooks/gci/tests.py index 6e80844494..154f741e8d 100644 --- a/zerver/webhooks/gci/tests.py +++ b/zerver/webhooks/gci/tests.py @@ -7,55 +7,59 @@ class GoogleCodeInTests(WebhookTestCase): WEBHOOK_DIR_NAME = "gci" def test_abandon_event_message(self) -> None: - expected_topic = "student-yqqtag" + expected_topic_name = "student-yqqtag" expected_message = "**student-yqqtag** abandoned the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)." - self.check_webhook("task_abandoned_by_student", expected_topic, expected_message) + self.check_webhook("task_abandoned_by_student", expected_topic_name, expected_message) def test_comment_event_message(self) -> None: - expected_topic = "student-yqqtag" + expected_topic_name = "student-yqqtag" expected_message = "**student-yqqtag** commented on the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)." - self.check_webhook("student_commented_on_task", expected_topic, expected_message) + self.check_webhook("student_commented_on_task", expected_topic_name, expected_message) def test_submit_event_message(self) -> None: - expected_topic = "student-yqqtag" + expected_topic_name = "student-yqqtag" expected_message = "**student-yqqtag** submitted the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)." - self.check_webhook("task_submitted_by_student", expected_topic, expected_message) + self.check_webhook("task_submitted_by_student", expected_topic_name, expected_message) def test_claim_event_message(self) -> None: - expected_topic = "student-yqqtag" + expected_topic_name = "student-yqqtag" expected_message = "**student-yqqtag** claimed the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)." - self.check_webhook("task_claimed_by_student", expected_topic, expected_message) + self.check_webhook("task_claimed_by_student", expected_topic_name, expected_message) def test_approve_event_message(self) -> None: - expected_topic = "student-yqqtag" + expected_topic_name = "student-yqqtag" expected_message = "**eeshangarg** approved the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)." - self.check_webhook("task_approved_by_mentor", expected_topic, expected_message) + self.check_webhook("task_approved_by_mentor", expected_topic_name, expected_message) def test_approve_pending_pc_event_message(self) -> None: - expected_topic = "student-yqqtag" + expected_topic_name = "student-yqqtag" expected_message = "**eeshangarg** approved the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/) (pending parental consent)." self.check_webhook( - "task_approved_by_mentor_pending_parental_consent", expected_topic, expected_message + "task_approved_by_mentor_pending_parental_consent", + expected_topic_name, + expected_message, ) def test_needswork_event_message(self) -> None: - expected_topic = "student-yqqtag" + expected_topic_name = "student-yqqtag" expected_message = "**eeshangarg** submitted the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/5136918324969472/) for more work." self.check_webhook( - "task_submitted_by_mentor_for_more_work", expected_topic, expected_message + "task_submitted_by_mentor_for_more_work", expected_topic_name, expected_message ) def test_extend_event_message(self) -> None: - expected_topic = "student-yqqtag" + expected_topic_name = "student-yqqtag" expected_message = "**eeshangarg** extended the deadline for the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/) by 1.0 day(s)." - self.check_webhook("task_deadline_extended_by_mentor", expected_topic, expected_message) + self.check_webhook( + "task_deadline_extended_by_mentor", expected_topic_name, expected_message + ) def test_unassign_event_message(self) -> None: - expected_topic = "student-yqqtag" + expected_topic_name = "student-yqqtag" expected_message = "**eeshangarg** unassigned **student-yqqtag** from the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6296903092273152/)." - self.check_webhook("student_unassigned_by_mentor", expected_topic, expected_message) + self.check_webhook("student_unassigned_by_mentor", expected_topic_name, expected_message) def test_outoftime_event_message(self) -> None: - expected_topic = "student-yqqtag" + expected_topic_name = "student-yqqtag" expected_message = "The deadline for the task [Sails unspread it stopped at kearney](https://codein.withgoogle.com/dashboard/task-instances/6694926301528064/) has passed." - self.check_webhook("task_deadline_has_passed", expected_topic, expected_message) + self.check_webhook("task_deadline_has_passed", expected_topic_name, expected_message) diff --git a/zerver/webhooks/gci/view.py b/zerver/webhooks/gci/view.py index 84a4b64e7e..5c5a80a621 100644 --- a/zerver/webhooks/gci/view.py +++ b/zerver/webhooks/gci/view.py @@ -143,10 +143,10 @@ def api_gci_webhook( event = get_event(payload) if event is not None: body = get_body_based_on_event(event)(payload) - topic = GCI_TOPIC_TEMPLATE.format( + topic_name = GCI_TOPIC_TEMPLATE.format( student_name=payload["task_claimed_by"].tame(check_string), ) - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/gitea/tests.py b/zerver/webhooks/gitea/tests.py index 9decd6185e..5c7167b706 100644 --- a/zerver/webhooks/gitea/tests.py +++ b/zerver/webhooks/gitea/tests.py @@ -9,7 +9,7 @@ class GiteaHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "gitea" def test_multiple_commits(self) -> None: - expected_topic = "test / d" + expected_topic_name = "test / d" expected_message = """kostekIV [pushed](https://try.gitea.io/kostekIV/test/compare/21138d2ca0ce18f8e037696fdbe1b3f0c211f630...2ec0c971d04723523aa20f2b378f8b419b47d4ec) 5 commits to branch d. * commit ([2ec0c971d04](https://try.gitea.io/kostekIV/test/commit/2ec0c971d04723523aa20f2b378f8b419b47d4ec)) @@ -17,85 +17,85 @@ class GiteaHookTests(WebhookTestCase): * commit ([6773eabc077](https://try.gitea.io/kostekIV/test/commit/6773eabc0778a3e38997c06a13f5f0c48b67e5dc)) * commit ([337402cf675](https://try.gitea.io/kostekIV/test/commit/337402cf675ce7082ddcd23d06a116c85241825a)) * commit ([0a38cad3fac](https://try.gitea.io/kostekIV/test/commit/0a38cad3fac3a13bb78b738d13f15ce9cc3343fa))""" - self.check_webhook("push__5_commits", expected_topic, expected_message) + self.check_webhook("push__5_commits", expected_topic_name, expected_message) def test_new_branch(self) -> None: - expected_topic = "test / test-branch" + expected_topic_name = "test / test-branch" expected_message = "kostekIV created [test-branch](https://try.gitea.io/kostekIV/test/src/test-branch) branch." - self.check_webhook("create__branch", expected_topic, expected_message) + self.check_webhook("create__branch", expected_topic_name, expected_message) def test_pull_request_opened(self) -> None: - expected_topic = "test / PR #1905 New pr" + expected_topic_name = "test / PR #1905 New pr" expected_message = """kostekIV opened [PR #4](https://try.gitea.io/kostekIV/test/pulls/4) from `test-branch` to `master`.""" - self.check_webhook("pull_request__opened", expected_topic, expected_message) + self.check_webhook("pull_request__opened", expected_topic_name, expected_message) def test_pull_request_merged(self) -> None: - expected_topic = "test / PR #1905 New pr" + expected_topic_name = "test / PR #1905 New pr" expected_message = """kostekIV merged [PR #4](https://try.gitea.io/kostekIV/test/pulls/4) from `test-branch` to `master`.""" - self.check_webhook("pull_request__merged", expected_topic, expected_message) + self.check_webhook("pull_request__merged", expected_topic_name, expected_message) def test_pull_request_edited(self) -> None: - expected_topic = "test / PR #1906 test 2" + expected_topic_name = "test / PR #1906 test 2" expected_message = ( """kostekIV edited [PR #5](https://try.gitea.io/kostekIV/test/pulls/5).""" ) - self.check_webhook("pull_request__edited", expected_topic, expected_message) + self.check_webhook("pull_request__edited", expected_topic_name, expected_message) def test_pull_request_reopened(self) -> None: - expected_topic = "test / PR #1906 test 2" + expected_topic_name = "test / PR #1906 test 2" expected_message = """kostekIV reopened [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) from `d` to `master`.""" - self.check_webhook("pull_request__reopened", expected_topic, expected_message) + self.check_webhook("pull_request__reopened", expected_topic_name, expected_message) def test_pull_request_closed(self) -> None: - expected_topic = "test / PR #1906 test 2" + expected_topic_name = "test / PR #1906 test 2" expected_message = """kostekIV closed [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) from `d` to `master`.""" - self.check_webhook("pull_request__closed", expected_topic, expected_message) + self.check_webhook("pull_request__closed", expected_topic_name, expected_message) def test_pull_request_assigned(self) -> None: - expected_topic = "test / PR #1906 test 2" + expected_topic_name = "test / PR #1906 test 2" expected_message = """kostekIV assigned [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) from `d` to `master` (assigned to kostekIV).""" - self.check_webhook("pull_request__assigned", expected_topic, expected_message) + self.check_webhook("pull_request__assigned", expected_topic_name, expected_message) def test_issues_opened(self) -> None: - expected_topic = "test / issue #3 Test issue" + expected_topic_name = "test / issue #3 Test issue" expected_message = """kostekIV opened [issue #3](https://try.gitea.io/kostekIV/test/issues/3):\n\n~~~ quote\nTest body\n~~~""" - self.check_webhook("issues__opened", expected_topic, expected_message) + self.check_webhook("issues__opened", expected_topic_name, expected_message) def test_issues_edited(self) -> None: - expected_topic = "test / issue #3 Test issue 2" + expected_topic_name = "test / issue #3 Test issue 2" expected_message = """kostekIV edited [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n~~~ quote\nTest body\n~~~""" - self.check_webhook("issues__edited", expected_topic, expected_message) + self.check_webhook("issues__edited", expected_topic_name, expected_message) def test_issues_closed(self) -> None: - expected_topic = "test / issue #3 Test issue 2" + expected_topic_name = "test / issue #3 Test issue 2" expected_message = """kostekIV closed [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n~~~ quote\nTest body\n~~~""" - self.check_webhook("issues__closed", expected_topic, expected_message) + self.check_webhook("issues__closed", expected_topic_name, expected_message) def test_issues_assigned(self) -> None: - expected_topic = "test / issue #3 Test issue" + expected_topic_name = "test / issue #3 Test issue" expected_message = """kostekIV assigned [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n~~~ quote\nTest body\n~~~""" - self.check_webhook("issues__assigned", expected_topic, expected_message) + self.check_webhook("issues__assigned", expected_topic_name, expected_message) def test_issues_reopened(self) -> None: - expected_topic = "test / issue #3 Test issue 2" + expected_topic_name = "test / issue #3 Test issue 2" expected_message = """kostekIV reopened [issue #3](https://try.gitea.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n~~~ quote\nTest body\n~~~""" - self.check_webhook("issues__reopened", expected_topic, expected_message) + self.check_webhook("issues__reopened", expected_topic_name, expected_message) def test_issue_comment_new(self) -> None: - expected_topic = "test / issue #3 Test issue" + expected_topic_name = "test / issue #3 Test issue" expected_message = """kostekIV [commented](https://try.gitea.io/kostekIV/test/issues/3#issuecomment-24400) on [issue #3](https://try.gitea.io/kostekIV/test/issues/3):\n\n~~~ quote\ntest comment\n~~~""" - self.check_webhook("issue_comment__new", expected_topic, expected_message) + self.check_webhook("issue_comment__new", expected_topic_name, expected_message) def test_issue_comment_in_pr(self) -> None: - expected_topic = "test / issue #1 dummy" + expected_topic_name = "test / issue #1 dummy" expected_message = """kostekIV [commented](https://try.gitea.io/kostekIV/test/pulls/1/files#issuecomment-24399) on [issue #1](https://try.gitea.io/kostekIV/test/issues/1):\n\n~~~ quote\ntest comment\n~~~""" - self.check_webhook("issue_comment__in_pr", expected_topic, expected_message) + self.check_webhook("issue_comment__in_pr", expected_topic_name, expected_message) def test_issue_comment_edited(self) -> None: - expected_topic = "test / issue #3 Test issue 2" + expected_topic_name = "test / issue #3 Test issue 2" expected_message = """kostekIV edited a [comment](https://try.gitea.io/kostekIV/test/issues/3#issuecomment-24400) on [issue #3](https://try.gitea.io/kostekIV/test/issues/3):\n\n~~~ quote\nedit test comment\n~~~""" - self.check_webhook("issue_comment__edited", expected_topic, expected_message) + self.check_webhook("issue_comment__edited", expected_topic_name, expected_message) @patch("zerver.webhooks.gogs.view.check_send_webhook_message") def test_push_filtered_by_branches_ignore( diff --git a/zerver/webhooks/github/tests.py b/zerver/webhooks/github/tests.py index 6cf7ca9dba..28567a85b0 100644 --- a/zerver/webhooks/github/tests.py +++ b/zerver/webhooks/github/tests.py @@ -26,8 +26,8 @@ class GitHubWebhookTest(WebhookTestCase): def test_star_event(self) -> None: expected_message = "[Codertocat](https://github.com/Codertocat) starred the repository [Codertocat/Hello-World](https://github.com/Codertocat/Hello-World)." - expected_topic = "Hello-World" - self.check_webhook("star", expected_topic, expected_message) + expected_topic_name = "Hello-World" + self.check_webhook("star", expected_topic_name, expected_message) def test_ping_organization_event(self) -> None: expected_message = "GitHub webhook has been successfully configured by eeshangarg." @@ -135,15 +135,15 @@ class GitHubWebhookTest(WebhookTestCase): self.check_webhook("issue_comment", TOPIC_ISSUE, expected_message) def test_issue_comment_deleted_msg(self) -> None: - expected_topic = "Scheduler / issue #5 This is a new issue" + expected_topic_name = "Scheduler / issue #5 This is a new issue" expected_message = "eeshangarg deleted a [comment](https://github.com/eeshangarg/Scheduler/issues/5#issuecomment-425164194) on [issue #5](https://github.com/eeshangarg/Scheduler/issues/5):\n\n~~~ quote\nThis is a comment on this new issue.\n~~~" - self.check_webhook("issue_comment__deleted", expected_topic, expected_message) + self.check_webhook("issue_comment__deleted", expected_topic_name, expected_message) def test_issue_comment_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "baxterthehacker [commented](https://github.com/baxterthehacker/public-repo/issues/2#issuecomment-99262140) on [issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nYou are totally right! I'll get this fixed right away.\n~~~" - self.check_webhook("issue_comment", expected_topic, expected_message) + self.check_webhook("issue_comment", expected_topic_name, expected_message) def test_issue_comment_pull_request_comment_msg(self) -> None: expected_message = "sbansal1999 [commented](https://github.com/sbansal1999/public-repo/pull/1#issuecomment-1631445420) on [PR #1](https://github.com/sbansal1999/public-repo/pull/1):\n\n~~~ quote\nSome comment\n~~~" @@ -155,66 +155,66 @@ class GitHubWebhookTest(WebhookTestCase): def test_issue_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "baxterthehacker opened [issue #2 Spelling error in the README file](https://github.com/baxterthehacker/public-repo/issues/2):\n\n~~~ quote\nIt looks like you accidentally spelled 'commit' with two 't's.\n~~~" - self.check_webhook("issues", expected_topic, expected_message) + self.check_webhook("issues", expected_topic_name, expected_message) def test_issue_assigned(self) -> None: expected_message = "sbansal1999 assigned sbansal1999 to [issue #7](https://github.com/sbansal1999/testing-gh/issues/7)." - expected_topic = "testing-gh / issue #7 Testing when issue assigned!" - self.check_webhook("issues__assigned", expected_topic, expected_message) + expected_topic_name = "testing-gh / issue #7 Testing when issue assigned!" + self.check_webhook("issues__assigned", expected_topic_name, expected_message) def test_issue_assigned_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "sbansal1999 assigned sbansal1999 to [issue #7 Testing when issue assigned!](https://github.com/sbansal1999/testing-gh/issues/7)" - self.check_webhook("issues__assigned", expected_topic, expected_message) + self.check_webhook("issues__assigned", expected_topic_name, expected_message) def test_issue_unassigned(self) -> None: expected_message = "sbansal1999 unassigned sbansal1999 from [issue #9](https://github.com/sbansal1999/testing-gh/issues/9)." - expected_topic = "testing-gh / issue #9 idk man" - self.check_webhook("issues__unassigned", expected_topic, expected_message) + expected_topic_name = "testing-gh / issue #9 idk man" + self.check_webhook("issues__unassigned", expected_topic_name, expected_message) def test_issue_unassigned_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "sbansal1999 unassigned sbansal1999 from [issue #9 idk man](https://github.com/sbansal1999/testing-gh/issues/9)." - self.check_webhook("issues__unassigned", expected_topic, expected_message) + self.check_webhook("issues__unassigned", expected_topic_name, expected_message) def test_issue_labeled(self) -> None: - expected_topic = "testing-gh / issue #9 idk man" + expected_topic_name = "testing-gh / issue #9 idk man" expected_message = "[sbansal1999](https://github.com/sbansal1999) added the bug label to [Issue #9](https://github.com/sbansal1999/testing-gh/issues/9)." - self.check_webhook("issues__labeled", expected_topic, expected_message) + self.check_webhook("issues__labeled", expected_topic_name, expected_message) def test_issue_labeled_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[sbansal1999](https://github.com/sbansal1999) added the bug label to [Issue #9 idk man](https://github.com/sbansal1999/testing-gh/issues/9)." - self.check_webhook("issues__labeled", expected_topic, expected_message) + self.check_webhook("issues__labeled", expected_topic_name, expected_message) def test_issue_unlabeled(self) -> None: - expected_topic = "testing-gh / issue #9 idk man" + expected_topic_name = "testing-gh / issue #9 idk man" expected_message = "[sbansal1999](https://github.com/sbansal1999) removed the bug label from [Issue #9](https://github.com/sbansal1999/testing-gh/issues/9)." - self.check_webhook("issues__unlabeled", expected_topic, expected_message) + self.check_webhook("issues__unlabeled", expected_topic_name, expected_message) def test_issue_milestoned(self) -> None: - expected_topic = "testing-gh / issue #6 This is a sample issue to test GH I..." + expected_topic_name = "testing-gh / issue #6 This is a sample issue to test GH I..." expected_message = "[sbansal1999](https://github.com/sbansal1999) added milestone [some_random_milestone](https://github.com/sbansal1999/testing-gh/milestone/1) to [issue #6](https://github.com/sbansal1999/testing-gh/issues/6)." - self.check_webhook("issues__milestoned", expected_topic, expected_message) + self.check_webhook("issues__milestoned", expected_topic_name, expected_message) def test_issue_milestoned_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[sbansal1999](https://github.com/sbansal1999) added milestone [some_random_milestone](https://github.com/sbansal1999/testing-gh/milestone/1) to [issue #6 This is a sample issue to test GH Integration Func](https://github.com/sbansal1999/testing-gh/issues/6)." - self.check_webhook("issues__milestoned", expected_topic, expected_message) + self.check_webhook("issues__milestoned", expected_topic_name, expected_message) def test_issue_demilestoned(self) -> None: - expected_topic = "testing-gh / issue #6 This is a sample issue to test GH I..." + expected_topic_name = "testing-gh / issue #6 This is a sample issue to test GH I..." expected_message = "[sbansal1999](https://github.com/sbansal1999) removed milestone [some_random_milestone](https://github.com/sbansal1999/testing-gh/milestone/1) from [issue #6](https://github.com/sbansal1999/testing-gh/issues/6)." - self.check_webhook("issues__demilestoned", expected_topic, expected_message) + self.check_webhook("issues__demilestoned", expected_topic_name, expected_message) def test_membership_msg(self) -> None: expected_message = ( @@ -235,17 +235,17 @@ class GitHubWebhookTest(WebhookTestCase): self.check_webhook("pull_request__opened", TOPIC_PR, expected_message) def test_pull_request_opened_with_preassigned_assignee_msg(self) -> None: - expected_topic = "Scheduler / PR #4 Improve README" + expected_topic_name = "Scheduler / PR #4 Improve README" expected_message = "eeshangarg opened [PR #4](https://github.com/eeshangarg/Scheduler/pull/4) from `eeshangarg:improve-readme-2` to `eeshangarg:master` (assigned to eeshangarg)." self.check_webhook( - "pull_request__opened_with_preassigned_assignee", expected_topic, expected_message + "pull_request__opened_with_preassigned_assignee", expected_topic_name, expected_message ) def test_pull_request_opened_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "baxterthehacker opened [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1) from `baxterthehacker:changes` to `baxterthehacker:master`:\n\n~~~ quote\nThis is a pretty simple change that we need to pull into master.\n~~~" - self.check_webhook("pull_request__opened", expected_topic, expected_message) + self.check_webhook("pull_request__opened", expected_topic_name, expected_message) def test_pull_request_synchronized_msg(self) -> None: expected_message = "baxterthehacker updated [PR #1](https://github.com/baxterthehacker/public-repo/pull/1)." @@ -257,9 +257,9 @@ class GitHubWebhookTest(WebhookTestCase): def test_pull_request_closed_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "baxterthehacker closed without merge [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1)." - self.check_webhook("pull_request__closed", expected_topic, expected_message) + self.check_webhook("pull_request__closed", expected_topic_name, expected_message) def test_pull_request_merged_msg(self) -> None: expected_message = ( @@ -319,14 +319,14 @@ class GitHubWebhookTest(WebhookTestCase): def test_pull_request_review_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "baxterthehacker submitted [PR review for #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1#pullrequestreview-2626884):\n\n~~~ quote\nLooks great!\n~~~" - self.check_webhook("pull_request_review", expected_topic, expected_message) + self.check_webhook("pull_request_review", expected_topic_name, expected_message) def test_pull_request_review_msg_with_empty_body(self) -> None: - expected_topic = "groonga / PR #1581 grn_db_value_lock: unlock GRN_TYPE obj..." + expected_topic_name = "groonga / PR #1581 grn_db_value_lock: unlock GRN_TYPE obj..." expected_message = "kou submitted [PR review](https://github.com/groonga/groonga/pull/1581#pullrequestreview-1483047907)." - self.check_webhook("pull_request_review__empty_body", expected_topic, expected_message) + self.check_webhook("pull_request_review__empty_body", expected_topic_name, expected_message) def test_pull_request_review_comment_msg(self) -> None: expected_message = "baxterthehacker created [PR review comment](https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692):\n\n~~~ quote\nMaybe you should use more emojji on this line.\n~~~" @@ -334,9 +334,9 @@ class GitHubWebhookTest(WebhookTestCase): def test_pull_request_review_comment_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "baxterthehacker created [PR review comment on #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1#discussion_r29724692):\n\n~~~ quote\nMaybe you should use more emojji on this line.\n~~~" - self.check_webhook("pull_request_review_comment", expected_topic, expected_message) + self.check_webhook("pull_request_review_comment", expected_topic_name, expected_message) def test_pull_request_locked(self) -> None: expected_message = "tushar912 has locked [PR #1](https://github.com/tushar912/public-repo/pull/1) as off-topic and limited conversation to collaborators." @@ -380,9 +380,9 @@ class GitHubWebhookTest(WebhookTestCase): def test_pull_request_assigned_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "baxterthehacker assigned baxterthehacker to [PR #1 Update the README with new information](https://github.com/baxterthehacker/public-repo/pull/1)." - self.check_webhook("pull_request__assigned", expected_topic, expected_message) + self.check_webhook("pull_request__assigned", expected_topic_name, expected_message) def test_pull_request_unassigned_msg(self) -> None: expected_message = ( @@ -420,35 +420,35 @@ class GitHubWebhookTest(WebhookTestCase): def test_pull_request_review_requested_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "**eeshangarg** requested [showell](https://github.com/showell) for a review on [PR #1 This is just a test commit](https://github.com/eeshangarg/Scheduler/pull/1)." - self.check_webhook("pull_request__review_requested", expected_topic, expected_message) + self.check_webhook("pull_request__review_requested", expected_topic_name, expected_message) def test_check_run(self) -> None: - expected_topic = "hello-world / checks" + expected_topic_name = "hello-world / checks" expected_message = """ Check [randscape](http://github.com/github/hello-world/runs/4) completed (success). ([d6fde92930d](http://github.com/github/hello-world/commit/d6fde92930d4715a2b49857d24b940956b26d2d3)) """.strip() - self.check_webhook("check_run__completed", expected_topic, expected_message) + self.check_webhook("check_run__completed", expected_topic_name, expected_message) def test_team_edited_description(self) -> None: - expected_topic = "team Testing" + expected_topic_name = "team Testing" expected_message = """\ **Hypro999** changed the team description to: \n~~~ quote A temporary team so that I can get some webhook fixtures! ~~~""" - self.check_webhook("team__edited_description", expected_topic, expected_message) + self.check_webhook("team__edited_description", expected_topic_name, expected_message) def test_team_edited_name(self) -> None: - expected_topic = "team Testing Team" + expected_topic_name = "team Testing Team" expected_message = """Team `Testing` was renamed to `Testing Team`.""" - self.check_webhook("team__edited_name", expected_topic, expected_message) + self.check_webhook("team__edited_name", expected_topic_name, expected_message) def test_team_edited_privacy(self) -> None: - expected_topic = "team Testing Team" + expected_topic_name = "team Testing Team" expected_message = """Team visibility changed to `secret`""" - self.check_webhook("team__edited_privacy_secret", expected_topic, expected_message) + self.check_webhook("team__edited_privacy_secret", expected_topic_name, expected_message) def verify_post_is_ignored(self, payload: str, http_x_github_event: str) -> None: with patch("zerver.webhooks.github.view.check_send_webhook_message") as m: @@ -584,9 +584,9 @@ A temporary team so that I can get some webhook fixtures! def test_discussion_comment_msg_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "sbansal1999 [commented](https://github.com/sbansal1999/testing-gh/discussions/20#discussioncomment-6332416) on [discussion #20 Lets discuss](https://github.com/sbansal1999/testing-gh/discussions/20):\n\n~~~ quote\nsome random comment\n~~~" - self.check_webhook("discussion_comment", expected_topic, expected_message) + self.check_webhook("discussion_comment", expected_topic_name, expected_message) def test_discussion_comment_edited_msg(self) -> None: expected_message = "sbansal1999 edited a [comment](https://github.com/sbansal1999/testing-gh/discussions/20#discussioncomment-6332416) on [discussion #20](https://github.com/sbansal1999/testing-gh/discussions/20):\n\n~~~ quote\nsome random comment edited\n~~~" diff --git a/zerver/webhooks/github/view.py b/zerver/webhooks/github/view.py index 40533758f5..54e2d08091 100644 --- a/zerver/webhooks/github/view.py +++ b/zerver/webhooks/github/view.py @@ -828,7 +828,7 @@ def api_github_webhook( # for events that are valid but not yet handled by us. # See IGNORED_EVENTS, for example. return json_success(request) - topic = get_topic_based_on_type(payload, event) + topic_name = get_topic_based_on_type(payload, event) body_function = EVENT_FUNCTION_MAPPER[event] @@ -839,7 +839,7 @@ def api_github_webhook( ) body = body_function(helper) - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.py index 78bc49c133..6d83eb1922 100644 --- a/zerver/webhooks/gitlab/tests.py +++ b/zerver/webhooks/gitlab/tests.py @@ -11,87 +11,89 @@ class GitlabHookTests(WebhookTestCase): def test_push_event_specified_topic(self) -> None: self.url = self.build_webhook_url("topic=Specific%20topic") - expected_topic = "Specific topic" + expected_topic_name = "Specific topic" expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek.\n\n* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))" - self.check_webhook("push_hook", expected_topic, expected_message) + self.check_webhook("push_hook", expected_topic_name, expected_message) def test_push_event_message(self) -> None: - expected_topic = "my-awesome-project / tomek" + expected_topic_name = "my-awesome-project / tomek" expected_message = "Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek.\n\n* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))" - self.check_webhook("push_hook", expected_topic, expected_message) + self.check_webhook("push_hook", expected_topic_name, expected_message) def test_push_local_branch_without_commits(self) -> None: - expected_topic = "my-awesome-project / changes" + expected_topic_name = "my-awesome-project / changes" expected_message = "Eeshan Garg [pushed](https://gitlab.com/eeshangarg/my-awesome-project/-/compare/0000000000000000000000000000000000000000...68d7a5528cf423dfaac37dd62a56ac9cc8a884e3) the branch changes." self.check_webhook( - "push_hook__push_local_branch_without_commits", expected_topic, expected_message + "push_hook__push_local_branch_without_commits", expected_topic_name, expected_message ) def test_push_event_message_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="master,tomek") - expected_topic = "my-awesome-project / tomek" + expected_topic_name = "my-awesome-project / tomek" expected_message = "Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek.\n\n* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))" - self.check_webhook("push_hook", expected_topic, expected_message) + self.check_webhook("push_hook", expected_topic_name, expected_message) def test_push_multiple_committers(self) -> None: - expected_topic = "my-awesome-project / tomek" + expected_topic_name = "my-awesome-project / tomek" expected_message = "Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 2 commits to branch tomek. Commits by Ben (1) and Tomasz Kolek (1).\n\n* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n* c ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))" - self.check_webhook("push_hook__push_multiple_committers", expected_topic, expected_message) + self.check_webhook( + "push_hook__push_multiple_committers", expected_topic_name, expected_message + ) def test_push_multiple_committers_with_others(self) -> None: - expected_topic = "my-awesome-project / tomek" + expected_topic_name = "my-awesome-project / tomek" commit_info = "* b ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))\n" expected_message = f"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 7 commits to branch tomek. Commits by Ben (3), baxterthehacker (2), James (1) and others (1).\n\n{commit_info * 6}* b ([eb6ae1e591e](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9))" self.check_webhook( - "push_hook__push_multiple_committers_with_others", expected_topic, expected_message + "push_hook__push_multiple_committers_with_others", expected_topic_name, expected_message ) def test_push_commits_more_than_limit_event_message(self) -> None: - expected_topic = "my-awesome-project / tomek" + expected_topic_name = "my-awesome-project / tomek" commits_info = "* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n" expected_message = f"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek.\n\n{commits_info * COMMITS_LIMIT}[and {50 - COMMITS_LIMIT} more commit(s)]" self.check_webhook( - "push_hook__push_commits_more_than_limit", expected_topic, expected_message + "push_hook__push_commits_more_than_limit", expected_topic_name, expected_message ) def test_push_commits_more_than_limit_message_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="master,tomek") - expected_topic = "my-awesome-project / tomek" + expected_topic_name = "my-awesome-project / tomek" commits_info = "* b ([66abd2da288](https://gitlab.com/tomaszkolek0/my-awesome-project/commit/66abd2da28809ffa128ed0447965cf11d7f863a7))\n" expected_message = f"Tomasz Kolek [pushed](https://gitlab.com/tomaszkolek0/my-awesome-project/-/compare/5fcdd5551fc3085df79bece2c32b1400802ac407...eb6ae1e591e0819dc5bf187c6bfe18ec065a80e9) 50 commits to branch tomek.\n\n{commits_info * COMMITS_LIMIT}[and {50 - COMMITS_LIMIT} more commit(s)]" self.check_webhook( - "push_hook__push_commits_more_than_limit", expected_topic, expected_message + "push_hook__push_commits_more_than_limit", expected_topic_name, expected_message ) def test_remove_branch_event_message(self) -> None: - expected_topic = "my-awesome-project / tomek" + expected_topic_name = "my-awesome-project / tomek" expected_message = "Tomasz Kolek deleted branch tomek." - self.check_webhook("push_hook__remove_branch", expected_topic, expected_message) + self.check_webhook("push_hook__remove_branch", expected_topic_name, expected_message) def test_add_tag_event_message(self) -> None: - expected_topic = "my-awesome-project" + expected_topic_name = "my-awesome-project" expected_message = "Tomasz Kolek pushed tag xyz." self.check_webhook( "tag_push_hook__add_tag", - expected_topic, + expected_topic_name, expected_message, HTTP_X_GITLAB_EVENT="Tag Push Hook", ) def test_remove_tag_event_message(self) -> None: - expected_topic = "my-awesome-project" + expected_topic_name = "my-awesome-project" expected_message = "Tomasz Kolek removed tag xyz." - self.check_webhook("tag_push_hook__remove_tag", expected_topic, expected_message) + self.check_webhook("tag_push_hook__remove_tag", expected_topic_name, expected_message) def test_create_issue_without_assignee_event_message(self) -> None: - expected_topic = "my-awesome-project / issue #1 Issue title" + expected_topic_name = "my-awesome-project / issue #1 Issue title" expected_message = "Tomasz Kolek created [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1):\n\n~~~ quote\nIssue description\n~~~" self.check_webhook( - "issue_hook__issue_created_without_assignee", expected_topic, expected_message + "issue_hook__issue_created_without_assignee", expected_topic_name, expected_message ) def test_create_confidential_issue_without_assignee_event_message(self) -> None: @@ -106,19 +108,19 @@ class GitlabHookTests(WebhookTestCase): def test_create_issue_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek created [issue #1 Issue title](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1):\n\n~~~ quote\nIssue description\n~~~" self.check_webhook( - "issue_hook__issue_created_without_assignee", expected_topic, expected_message + "issue_hook__issue_created_without_assignee", expected_topic_name, expected_message ) def test_create_issue_with_assignee_event_message(self) -> None: - expected_topic = "my-awesome-project / issue #1 Issue title" + expected_topic_name = "my-awesome-project / issue #1 Issue title" expected_message = "Tomasz Kolek created [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1) (assigned to Tomasz Kolek):\n\n~~~ quote\nIssue description\n~~~" self.check_webhook( - "issue_hook__issue_created_with_assignee", expected_topic, expected_message + "issue_hook__issue_created_with_assignee", expected_topic_name, expected_message ) def test_create_issue_with_two_assignees_event_message(self) -> None: @@ -148,12 +150,12 @@ class GitlabHookTests(WebhookTestCase): ) def test_create_issue_with_hidden_comment_in_description(self) -> None: - expected_topic = "public-repo / issue #3 New Issue with hidden comment" + expected_topic_name = "public-repo / issue #3 New Issue with hidden comment" expected_message = "Eeshan Garg created [issue #3](https://gitlab.com/eeshangarg/public-repo/issues/3):\n\n~~~ quote\nThis description actually has a hidden comment in it!\n~~~" self.check_webhook( "issue_hook__issue_created_with_hidden_comment_in_description", - expected_topic, + expected_topic_name, expected_message, ) @@ -168,17 +170,17 @@ class GitlabHookTests(WebhookTestCase): ) def test_create_issue_with_null_description(self) -> None: - expected_topic = "my-awesome-project / issue #7 Issue without description" + expected_topic_name = "my-awesome-project / issue #7 Issue without description" expected_message = "Eeshan Garg created [issue #7](https://gitlab.com/eeshangarg/my-awesome-project/issues/7)." self.check_webhook( - "issue_hook__issue_opened_with_null_description", expected_topic, expected_message + "issue_hook__issue_opened_with_null_description", expected_topic_name, expected_message ) def test_update_issue_event_message(self) -> None: - expected_topic = "my-awesome-project / issue #1 Issue title_new" + expected_topic_name = "my-awesome-project / issue #1 Issue title_new" expected_message = "Tomasz Kolek updated [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)." - self.check_webhook("issue_hook__issue_updated", expected_topic, expected_message) + self.check_webhook("issue_hook__issue_updated", expected_topic_name, expected_message) def test_update_confidential_issue_event_message(self) -> None: expected_subject = "testing / issue #1 Testing" @@ -190,16 +192,16 @@ class GitlabHookTests(WebhookTestCase): def test_update_issue_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek updated [issue #1 Issue title_new](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)." - self.check_webhook("issue_hook__issue_updated", expected_topic, expected_message) + self.check_webhook("issue_hook__issue_updated", expected_topic_name, expected_message) def test_close_issue_event_message(self) -> None: - expected_topic = "my-awesome-project / issue #1 Issue title_new" + expected_topic_name = "my-awesome-project / issue #1 Issue title_new" expected_message = "Tomasz Kolek closed [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)." - self.check_webhook("issue_hook__issue_closed", expected_topic, expected_message) + self.check_webhook("issue_hook__issue_closed", expected_topic_name, expected_message) def test_close_confidential_issue_event_message(self) -> None: expected_subject = "testing / issue #1 Testing Test" @@ -210,10 +212,10 @@ class GitlabHookTests(WebhookTestCase): ) def test_reopen_issue_event_message(self) -> None: - expected_topic = "my-awesome-project / issue #1 Issue title_new" + expected_topic_name = "my-awesome-project / issue #1 Issue title_new" expected_message = "Tomasz Kolek reopened [issue #1](https://gitlab.com/tomaszkolek0/my-awesome-project/issues/1)." - self.check_webhook("issue_hook__issue_reopened", expected_topic, expected_message) + self.check_webhook("issue_hook__issue_reopened", expected_topic_name, expected_message) def test_reopen_confidential_issue_event_message(self) -> None: expected_subject = "testing / issue #1 Testing Test" @@ -224,36 +226,36 @@ class GitlabHookTests(WebhookTestCase): ) def test_note_commit_event_message(self) -> None: - expected_topic = "testing-zulip-gitlab-integration" + expected_topic_name = "testing-zulip-gitlab-integration" expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/commit/82689ddf00fd7bdadb5c2afb3b94bd555edc9d01#note_1406241063) on [82689ddf00f](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/commit/82689ddf00fd7bdadb5c2afb3b94bd555edc9d01):\n~~~ quote\nWow what a beautiful commit.\n~~~" - self.check_webhook("note_hook__commit_note", expected_topic, expected_message) + self.check_webhook("note_hook__commit_note", expected_topic_name, expected_message) def test_note_merge_request_event_message(self) -> None: - expected_topic = "testing-zulip-gitlab-integration / MR #1 add new-feature" + expected_topic_name = "testing-zulip-gitlab-integration / MR #1 add new-feature" expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1#note_1406328457) on [MR #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1):\n\n~~~ quote\nI am not sure if this new feature is even required or not.\n~~~" - self.check_webhook("note_hook__merge_request_note", expected_topic, expected_message) + self.check_webhook("note_hook__merge_request_note", expected_topic_name, expected_message) def test_note_merge_request_event_message_without_merge_request_title(self) -> None: - expected_topic = "testing-zulip-gitlab-integration / MR #1" + expected_topic_name = "testing-zulip-gitlab-integration / MR #1" expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1#note_1406328457) on [MR #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1):\n\n~~~ quote\nI am not sure if this new feature is even required or not.\n~~~" # To keep things as valid JSON. self.url = self.build_webhook_url(use_merge_request_title="false") - self.check_webhook("note_hook__merge_request_note", expected_topic, expected_message) + self.check_webhook("note_hook__merge_request_note", expected_topic_name, expected_message) def test_note_merge_request_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[[testing-zulip-gitlab-integration](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration)] Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1#note_1406328457) on [MR #1 add new-feature](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/merge_requests/1):\n\n~~~ quote\nI am not sure if this new feature is even required or not.\n~~~" - self.check_webhook("note_hook__merge_request_note", expected_topic, expected_message) + self.check_webhook("note_hook__merge_request_note", expected_topic_name, expected_message) def test_note_issue_event_message(self) -> None: - expected_topic = "testing-zulip-gitlab-integration / issue #1 Add more lines" + expected_topic_name = "testing-zulip-gitlab-integration / issue #1 Add more lines" expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1#note_1406279810) on [issue #1](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1):\n\n~~~ quote\nThis is again a random comment.\n~~~" - self.check_webhook("note_hook__issue_note", expected_topic, expected_message) + self.check_webhook("note_hook__issue_note", expected_topic_name, expected_message) def test_note_confidential_issue_event_message(self) -> None: expected_subject = "testing-zulip-gitlab-integration / issue #1 Add more lines" @@ -263,62 +265,62 @@ class GitlabHookTests(WebhookTestCase): def test_note_issue_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[[testing-zulip-gitlab-integration](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration)] Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1#note_1406279810) on [issue #1 Add more lines](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/issues/1):\n\n~~~ quote\nThis is again a random comment.\n~~~" - self.check_webhook("note_hook__issue_note", expected_topic, expected_message) + self.check_webhook("note_hook__issue_note", expected_topic_name, expected_message) def test_note_snippet_old_event_message(self) -> None: - expected_topic = "my-awesome-project / snippet #2 test" + expected_topic_name = "my-awesome-project / snippet #2 test" expected_message = "Tomasz Kolek [commented](https://gitlab.com/tomaszkolek0/my-awesome-project/snippets/2#note_14172058) on [snippet #2](https://gitlab.com/tomaszkolek0/my-awesome-project/-/snippets/2):\n\n~~~ quote\nNice snippet\n~~~" - self.check_webhook("note_hook__snippet_note_old", expected_topic, expected_message) + self.check_webhook("note_hook__snippet_note_old", expected_topic_name, expected_message) def test_note_snippet_event_message(self) -> None: - expected_topic = "testing-zulip-gitlab-integration / snippet #2547713 a ver..." + expected_topic_name = "testing-zulip-gitlab-integration / snippet #2547713 a ver..." expected_message = "Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/snippets/2547713#note_1424268837) on [snippet #2547713](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/snippets/2547713):\n\n~~~ quote\nsome comment\n~~~" - self.check_webhook("note_hook__snippet_note", expected_topic, expected_message) + self.check_webhook("note_hook__snippet_note", expected_topic_name, expected_message) def test_note_snippet_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[[testing-zulip-gitlab-integration](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration)] Satyam Bansal [commented](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/snippets/2547713#note_1424268837) on [snippet #2547713 a very new new feature](https://gitlab.com/sbansal1999/testing-zulip-gitlab-integration/-/snippets/2547713):\n\n~~~ quote\nsome comment\n~~~" - self.check_webhook("note_hook__snippet_note", expected_topic, expected_message) + self.check_webhook("note_hook__snippet_note", expected_topic_name, expected_message) def test_merge_request_created_without_assignee_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #2 NEW MR" + expected_topic_name = "my-awesome-project / MR #2 NEW MR" expected_message = "Tomasz Kolek created [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`:\n\n~~~ quote\ndescription of merge request\n~~~" self.check_webhook( "merge_request_hook__merge_request_created_without_assignee", - expected_topic, + expected_topic_name, expected_message, ) def test_merge_request_created_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek created [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`:\n\n~~~ quote\ndescription of merge request\n~~~" self.check_webhook( "merge_request_hook__merge_request_created_without_assignee", - expected_topic, + expected_topic_name, expected_message, ) def test_merge_request_created_with_assignee_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #3 New Merge Request" + expected_topic_name = "my-awesome-project / MR #3 New Merge Request" expected_message = "Tomasz Kolek created [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) from `tomek` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription of merge request\n~~~" self.check_webhook( "merge_request_hook__merge_request_created_with_assignee", - expected_topic, + expected_topic_name, expected_message, ) def test_merge_request_created_with_multiple_assignees_event_message(self) -> None: - expected_topic = "Demo Project / MR #1 Make a trivial change to the README." + expected_topic_name = "Demo Project / MR #1 Make a trivial change to the README." expected_message = """ Hemanth V. Alluri created [MR #1](https://gitlab.com/Hypro999/demo-project/-/merge_requests/1) from `devel` to `master` (assigned to Hemanth V. Alluri and Hemanth V. Alluri): @@ -328,198 +330,202 @@ A trivial change that should probably be ignored. """.strip() self.check_webhook( "merge_request_hook__merge_request_created_with_multiple_assignees", - expected_topic, + expected_topic_name, expected_message, ) def test_merge_request_closed_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #2 NEW MR" + expected_topic_name = "my-awesome-project / MR #2 NEW MR" expected_message = "Tomasz Kolek closed [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)." self.check_webhook( - "merge_request_hook__merge_request_closed", expected_topic, expected_message + "merge_request_hook__merge_request_closed", expected_topic_name, expected_message ) def test_merge_request_closed_event_message_without_using_title(self) -> None: - expected_topic = "my-awesome-project / MR #2" + expected_topic_name = "my-awesome-project / MR #2" expected_message = "Tomasz Kolek closed [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)." self.url = self.build_webhook_url(use_merge_request_title="false") self.check_webhook( - "merge_request_hook__merge_request_closed", expected_topic, expected_message + "merge_request_hook__merge_request_closed", expected_topic_name, expected_message ) def test_merge_request_closed_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek closed [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)." self.check_webhook( - "merge_request_hook__merge_request_closed", expected_topic, expected_message + "merge_request_hook__merge_request_closed", expected_topic_name, expected_message ) def test_merge_request_reopened_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #1 Update the README with author ..." + expected_topic_name = "my-awesome-project / MR #1 Update the README with author ..." expected_message = "Eeshan Garg reopened [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1)." self.check_webhook( - "merge_request_hook__merge_request_reopened", expected_topic, expected_message + "merge_request_hook__merge_request_reopened", expected_topic_name, expected_message ) def test_merge_request_approved_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #1 Update the README with author ..." + expected_topic_name = "my-awesome-project / MR #1 Update the README with author ..." expected_message = "Eeshan Garg approved [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1)." self.check_webhook( - "merge_request_hook__merge_request_approved", expected_topic, expected_message + "merge_request_hook__merge_request_approved", expected_topic_name, expected_message ) def test_merge_request_updated_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #3 New Merge Request" + expected_topic_name = "my-awesome-project / MR #3 New Merge Request" expected_message = "Tomasz Kolek updated [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) (assigned to Tomasz Kolek):\n\n~~~ quote\nupdated desc\n~~~" self.check_webhook( - "merge_request_hook__merge_request_updated", expected_topic, expected_message + "merge_request_hook__merge_request_updated", expected_topic_name, expected_message ) def test_merge_request_added_commit_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #3 New Merge Request" + expected_topic_name = "my-awesome-project / MR #3 New Merge Request" expected_message = "Tomasz Kolek added commit(s) to [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3)." self.check_webhook( - "merge_request_hook__merge_request_added_commit", expected_topic, expected_message + "merge_request_hook__merge_request_added_commit", expected_topic_name, expected_message ) def test_merge_request_merged_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #3 New Merge Request" + expected_topic_name = "my-awesome-project / MR #3 New Merge Request" expected_message = "Tomasz Kolek merged [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) from `tomek` to `master`." self.check_webhook( - "merge_request_hook__merge_request_merged", expected_topic, expected_message + "merge_request_hook__merge_request_merged", expected_topic_name, expected_message ) def test_wiki_page_opened_event_message(self) -> None: - expected_topic = "my-awesome-project" + expected_topic_name = "my-awesome-project" expected_message = 'Tomasz Kolek created [wiki page "how to"](https://gitlab.com/tomaszkolek0/my-awesome-project/wikis/how-to).' - self.check_webhook("wiki_page_hook__wiki_page_opened", expected_topic, expected_message) + self.check_webhook( + "wiki_page_hook__wiki_page_opened", expected_topic_name, expected_message + ) def test_wiki_page_edited_event_message(self) -> None: - expected_topic = "my-awesome-project" + expected_topic_name = "my-awesome-project" expected_message = 'Tomasz Kolek updated [wiki page "how to"](https://gitlab.com/tomaszkolek0/my-awesome-project/wikis/how-to).' - self.check_webhook("wiki_page_hook__wiki_page_edited", expected_topic, expected_message) + self.check_webhook( + "wiki_page_hook__wiki_page_edited", expected_topic_name, expected_message + ) def test_build_created_event_message(self) -> None: - expected_topic = "my-awesome-project / master" + expected_topic_name = "my-awesome-project / master" expected_message = "Build job_name from test stage was created." self.check_webhook( "build_created", - expected_topic, + expected_topic_name, expected_message, HTTP_X_GITLAB_EVENT="Job Hook", ) def test_build_started_event_message(self) -> None: - expected_topic = "my-awesome-project / master" + expected_topic_name = "my-awesome-project / master" expected_message = "Build job_name from test stage started." self.check_webhook( "build_started", - expected_topic, + expected_topic_name, expected_message, HTTP_X_GITLAB_EVENT="Job Hook", ) def test_build_succeeded_event_message(self) -> None: - expected_topic = "my-awesome-project / master" + expected_topic_name = "my-awesome-project / master" expected_message = "Build job_name from test stage changed status to success." self.check_webhook( "build_succeeded", - expected_topic, + expected_topic_name, expected_message, HTTP_X_GITLAB_EVENT="Job Hook", ) def test_build_created_event_message_legacy_event_name(self) -> None: - expected_topic = "my-awesome-project / master" + expected_topic_name = "my-awesome-project / master" expected_message = "Build job_name from test stage was created." self.check_webhook( "build_created", - expected_topic, + expected_topic_name, expected_message, HTTP_X_GITLAB_EVENT="Build Hook", ) def test_build_started_event_message_legacy_event_name(self) -> None: - expected_topic = "my-awesome-project / master" + expected_topic_name = "my-awesome-project / master" expected_message = "Build job_name from test stage started." self.check_webhook( "build_started", - expected_topic, + expected_topic_name, expected_message, HTTP_X_GITLAB_EVENT="Build Hook", ) def test_build_succeeded_event_message_legacy_event_name(self) -> None: - expected_topic = "my-awesome-project / master" + expected_topic_name = "my-awesome-project / master" expected_message = "Build job_name from test stage changed status to success." self.check_webhook( "build_succeeded", - expected_topic, + expected_topic_name, expected_message, HTTP_X_GITLAB_EVENT="Build Hook", ) def test_pipeline_succeeded_with_artifacts_event_message(self) -> None: - expected_topic = "onlysomeproject / test/links-in-zulip-pipeline-message" + expected_topic_name = "onlysomeproject / test/links-in-zulip-pipeline-message" expected_message = "[Pipeline (22668)](https://gitlab.example.com/group1/onlysomeproject/-/pipelines/22668) changed status to success with build(s):\n* [cleanup:cleanup docker image](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58592) - success\n* [pages](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591) - success\n * built artifact: *artifacts.zip* [[Browse](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591/artifacts/browse)|[Download](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591/artifacts/download)]\n* [black+pytest:future environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58590) - success\n* [docs:anaconda environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589) - success\n * built artifact: *sphinx-docs.zip* [[Browse](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589/artifacts/browse)|[Download](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589/artifacts/download)]\n* [pytest:current environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58588) - success\n* [black:current environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58587) - success\n* [setup:docker image](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58586) - success." self.check_webhook( "pipeline_hook__pipeline_succeeded_with_artifacts", - expected_topic, + expected_topic_name, expected_message, ) def test_pipeline_succeeded_event_message(self) -> None: - expected_topic = "my-awesome-project / master" + expected_topic_name = "my-awesome-project / master" expected_message = "[Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/-/pipelines/4414206) changed status to success with build(s):\n* [job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113) - success\n* [job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112) - success." self.check_webhook( "pipeline_hook__pipeline_succeeded", - expected_topic, + expected_topic_name, expected_message, ) def test_pipeline_started_event_message(self) -> None: - expected_topic = "my-awesome-project / master" + expected_topic_name = "my-awesome-project / master" expected_message = "[Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/-/pipelines/4414206) started with build(s):\n* [job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112) - running\n* [job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113) - pending." self.check_webhook( "pipeline_hook__pipeline_started", - expected_topic, + expected_topic_name, expected_message, ) def test_pipeline_pending_event_message(self) -> None: - expected_topic = "my-awesome-project / master" + expected_topic_name = "my-awesome-project / master" expected_message = "[Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/-/pipelines/4414206) was created with build(s):\n* [job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113) - pending\n* [job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112) - created." self.check_webhook( "pipeline_hook__pipeline_pending", - expected_topic, + expected_topic_name, expected_message, ) def test_issue_type_test_payload(self) -> None: - expected_topic = "public-repo" + expected_topic_name = "public-repo" expected_message = "Webhook for **public-repo** has been configured successfully! :tada:" self.check_webhook( "test_hook__issue_test_payload", - expected_topic, + expected_topic_name, expected_message, ) @@ -548,68 +554,80 @@ A trivial change that should probably be ignored. self.assert_json_success(result) def test_job_hook_event(self) -> None: - expected_topic = "gitlab_test / gitlab-script-trigger" + expected_topic_name = "gitlab_test / gitlab-script-trigger" expected_message = "Build test from test stage was created." - self.check_webhook("job_hook__build_created", expected_topic, expected_message) + self.check_webhook("job_hook__build_created", expected_topic_name, expected_message) def test_job_hook_event_topic(self) -> None: self.url = self.build_webhook_url(topic="provided topic") - expected_topic = "provided topic" + expected_topic_name = "provided topic" expected_message = "[[gitlab_test](http://192.168.64.1:3005/gitlab-org/gitlab-test)] Build test from test stage was created." - self.check_webhook("job_hook__build_created", expected_topic, expected_message) + self.check_webhook("job_hook__build_created", expected_topic_name, expected_message) def test_system_push_event_message(self) -> None: - expected_topic = "gitlab / master" + expected_topic_name = "gitlab / master" expected_message = "John Smith [pushed](http://test.example.com/gitlab/gitlab/-/compare/95790bf891e76fee5e1747ab589903a6a1f80f22...da1560886d4f094c3e6c9ef40349f7d38b5d27d7) 1 commit to branch master. Commits by Test User (1).\n\n* Add simple search to projects in public area ([c5feabde2d8](https://test.example.com/gitlab/gitlab/-/commit/c5feabde2d8cd023215af4d2ceeb7a64839fc428))" - self.check_webhook("system_hook__push_hook", expected_topic, expected_message) + self.check_webhook("system_hook__push_hook", expected_topic_name, expected_message) def test_system_merge_request_created_without_assignee_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #2 NEW MR" + expected_topic_name = "my-awesome-project / MR #2 NEW MR" expected_message = "Tomasz Kolek created [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`:\n\n~~~ quote\ndescription of merge request\n~~~" self.check_webhook( - "system_hook__merge_request_created_without_assignee", expected_topic, expected_message + "system_hook__merge_request_created_without_assignee", + expected_topic_name, + expected_message, ) def test_system_merge_request_created_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek created [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2) from `tomek` to `master`:\n\n~~~ quote\ndescription of merge request\n~~~" self.check_webhook( - "system_hook__merge_request_created_without_assignee", expected_topic, expected_message + "system_hook__merge_request_created_without_assignee", + expected_topic_name, + expected_message, ) def test_system_merge_request_created_with_assignee_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #3 New Merge Request" + expected_topic_name = "my-awesome-project / MR #3 New Merge Request" expected_message = "Tomasz Kolek created [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) from `tomek` to `master` (assigned to Tomasz Kolek):\n\n~~~ quote\ndescription of merge request\n~~~" self.check_webhook( - "system_hook__merge_request_created_with_assignee", expected_topic, expected_message + "system_hook__merge_request_created_with_assignee", + expected_topic_name, + expected_message, ) def test_system_merge_request_closed_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #2 NEW MR" + expected_topic_name = "my-awesome-project / MR #2 NEW MR" expected_message = "Tomasz Kolek closed [MR #2](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)." - self.check_webhook("system_hook__merge_request_closed", expected_topic, expected_message) + self.check_webhook( + "system_hook__merge_request_closed", expected_topic_name, expected_message + ) def test_system_merge_request_merged_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #3 New Merge Request" + expected_topic_name = "my-awesome-project / MR #3 New Merge Request" expected_message = "Tomasz Kolek merged [MR #3](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/3) from `tomek` to `master`." - self.check_webhook("system_hook__merge_request_merged", expected_topic, expected_message) + self.check_webhook( + "system_hook__merge_request_merged", expected_topic_name, expected_message + ) def test_system_merge_request_closed_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[[my-awesome-project](https://gitlab.com/tomaszkolek0/my-awesome-project)] Tomasz Kolek closed [MR #2 NEW MR](https://gitlab.com/tomaszkolek0/my-awesome-project/merge_requests/2)." - self.check_webhook("system_hook__merge_request_closed", expected_topic, expected_message) + self.check_webhook( + "system_hook__merge_request_closed", expected_topic_name, expected_message + ) def test_merge_request_unapproved_event_message(self) -> None: - expected_topic = "my-awesome-project / MR #1 Update the README with author ..." + expected_topic_name = "my-awesome-project / MR #1 Update the README with author ..." expected_message = "Eeshan Garg unapproved [MR #1](https://gitlab.com/eeshangarg/my-awesome-project/merge_requests/1)." self.check_webhook( - "merge_request_hook__merge_request_unapproved", expected_topic, expected_message + "merge_request_hook__merge_request_unapproved", expected_topic_name, expected_message ) diff --git a/zerver/webhooks/gitlab/view.py b/zerver/webhooks/gitlab/view.py index 351525c8f8..038d035074 100644 --- a/zerver/webhooks/gitlab/view.py +++ b/zerver/webhooks/gitlab/view.py @@ -441,8 +441,8 @@ def api_gitlab_webhook( project_url = f"[{get_repo_name(payload)}]({get_project_homepage(payload)})" body = f"[{project_url}] {body}" - topic = get_topic_based_on_event(event, payload, use_merge_request_title) - check_send_webhook_message(request, user_profile, topic, body, event) + topic_name = get_topic_based_on_event(event, payload, use_merge_request_title) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/gocd/tests.py b/zerver/webhooks/gocd/tests.py index befc6f70d2..f2f2f1333f 100644 --- a/zerver/webhooks/gocd/tests.py +++ b/zerver/webhooks/gocd/tests.py @@ -5,7 +5,7 @@ class GocdHookTests(WebhookTestCase): STREAM_NAME = "gocd" URL_TEMPLATE = "/api/v1/external/gocd?stream={stream}&api_key={api_key}" WEBHOOK_DIR_NAME = "gocd" - TOPIC = "https://github.com/gocd/gocd" + TOPIC_NAME = "https://github.com/gocd/gocd" def test_gocd_message(self) -> None: expected_message = ( @@ -18,7 +18,7 @@ class GocdHookTests(WebhookTestCase): self.check_webhook( "pipeline", - self.TOPIC, + self.TOPIC_NAME, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -34,7 +34,7 @@ class GocdHookTests(WebhookTestCase): self.check_webhook( "pipeline_failed", - self.TOPIC, + self.TOPIC_NAME, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/gocd/view.py b/zerver/webhooks/gocd/view.py index 58f1d21ff5..a6c49b3acd 100644 --- a/zerver/webhooks/gocd/view.py +++ b/zerver/webhooks/gocd/view.py @@ -49,8 +49,8 @@ def api_gocd_webhook( modifications["comment"].tame(check_string), ) branch = material["description"].tame(check_string).split(",") - topic = branch[0].split(" ")[1] + topic_name = branch[0].split(" ")[1] - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/gogs/tests.py b/zerver/webhooks/gogs/tests.py index 350033eecb..86bef4b406 100644 --- a/zerver/webhooks/gogs/tests.py +++ b/zerver/webhooks/gogs/tests.py @@ -10,133 +10,137 @@ class GogsHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "gogs" def test_push(self) -> None: - expected_topic = "try-git / master" + expected_topic_name = "try-git / master" expected_message = """john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) 1 commit to branch master. Commits by John (1). * Webhook Test ([d8fce16c72a](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))""" - self.check_webhook("push", expected_topic, expected_message) + self.check_webhook("push", expected_topic_name, expected_message) def test_push_multiple_committers(self) -> None: commit_info = "* Webhook Test ([d8fce16c72a](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))\n" - expected_topic = "try-git / master" + expected_topic_name = "try-git / master" expected_message = f"""john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) 2 commits to branch master. Commits by Benjamin (1) and John (1).\n\n{commit_info}* Webhook Test ([d8fce16c72a](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))""" - self.check_webhook("push__commits_multiple_committers", expected_topic, expected_message) + self.check_webhook( + "push__commits_multiple_committers", expected_topic_name, expected_message + ) def test_push_multiple_committers_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="master,development") commit_info = "* Webhook Test ([d8fce16c72a](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))\n" - expected_topic = "try-git / master" + expected_topic_name = "try-git / master" expected_message = f"""john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) 2 commits to branch master. Commits by Benjamin (1) and John (1).\n\n{commit_info}* Webhook Test ([d8fce16c72a](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))""" - self.check_webhook("push__commits_multiple_committers", expected_topic, expected_message) + self.check_webhook( + "push__commits_multiple_committers", expected_topic_name, expected_message + ) def test_push_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="master,development") - expected_topic = "try-git / master" + expected_topic_name = "try-git / master" expected_message = """john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) 1 commit to branch master. Commits by John (1). * Webhook Test ([d8fce16c72a](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))""" - self.check_webhook("push", expected_topic, expected_message) + self.check_webhook("push", expected_topic_name, expected_message) def test_push_commits_more_than_limits(self) -> None: - expected_topic = "try-git / master" + expected_topic_name = "try-git / master" commits_info = "* Webhook Test ([d8fce16c72a](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))\n" expected_message = f"john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) 30 commits to branch master. Commits by John (30).\n\n{commits_info * COMMITS_LIMIT}[and {30 - COMMITS_LIMIT} more commit(s)]" - self.check_webhook("push__commits_more_than_limits", expected_topic, expected_message) + self.check_webhook("push__commits_more_than_limits", expected_topic_name, expected_message) def test_push_commits_more_than_limits_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="master,development") - expected_topic = "try-git / master" + expected_topic_name = "try-git / master" commits_info = "* Webhook Test ([d8fce16c72a](http://localhost:3000/john/try-git/commit/d8fce16c72a2ff56a5afc8a08645a6ce45491794))\n" expected_message = f"john [pushed](http://localhost:3000/john/try-git/compare/479e6b772b7fba19412457483f50b201286d0103...d8fce16c72a2ff56a5afc8a08645a6ce45491794) 30 commits to branch master. Commits by John (30).\n\n{commits_info * COMMITS_LIMIT}[and {30 - COMMITS_LIMIT} more commit(s)]" - self.check_webhook("push__commits_more_than_limits", expected_topic, expected_message) + self.check_webhook("push__commits_more_than_limits", expected_topic_name, expected_message) def test_new_branch(self) -> None: - expected_topic = "try-git / my_feature" + expected_topic_name = "try-git / my_feature" expected_message = ( "john created [my_feature](http://localhost:3000/john/try-git/src/my_feature) branch." ) - self.check_webhook("create__branch", expected_topic, expected_message) + self.check_webhook("create__branch", expected_topic_name, expected_message) def test_pull_request_opened(self) -> None: - expected_topic = "try-git / PR #1 Title Text for Pull Request" + expected_topic_name = "try-git / PR #1 Title Text for Pull Request" expected_message = """john opened [PR #1](http://localhost:3000/john/try-git/pulls/1) from `feature` to `master`.""" - self.check_webhook("pull_request__opened", expected_topic, expected_message) + self.check_webhook("pull_request__opened", expected_topic_name, expected_message) def test_pull_request_opened_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = """john opened [PR #1 Title Text for Pull Request](http://localhost:3000/john/try-git/pulls/1) from `feature` to `master`.""" - self.check_webhook("pull_request__opened", expected_topic, expected_message) + self.check_webhook("pull_request__opened", expected_topic_name, expected_message) def test_pull_request_closed(self) -> None: - expected_topic = "try-git / PR #1 Title Text for Pull Request" + expected_topic_name = "try-git / PR #1 Title Text for Pull Request" expected_message = """john closed [PR #1](http://localhost:3000/john/try-git/pulls/1) from `feature` to `master`.""" - self.check_webhook("pull_request__closed", expected_topic, expected_message) + self.check_webhook("pull_request__closed", expected_topic_name, expected_message) def test_pull_request_merged(self) -> None: - expected_topic = "try-git / PR #2 Title Text for Pull Request" + expected_topic_name = "try-git / PR #2 Title Text for Pull Request" expected_message = """john merged [PR #2](http://localhost:3000/john/try-git/pulls/2) from `feature` to `master`.""" - self.check_webhook("pull_request__merged", expected_topic, expected_message) + self.check_webhook("pull_request__merged", expected_topic_name, expected_message) def test_pull_request_reopened(self) -> None: - expected_topic = "test / PR #1349 reopened" + expected_topic_name = "test / PR #1349 reopened" expected_message = """kostekIV reopened [PR #2](https://try.gogs.io/kostekIV/test/pulls/2) from `c` to `master`.""" - self.check_webhook("pull_request__reopened", expected_topic, expected_message) + self.check_webhook("pull_request__reopened", expected_topic_name, expected_message) def test_pull_request_edited(self) -> None: - expected_topic = "test / PR #1349 Test" + expected_topic_name = "test / PR #1349 Test" expected_message = """kostekIV edited [PR #2](https://try.gogs.io/kostekIV/test/pulls/2).""" - self.check_webhook("pull_request__edited", expected_topic, expected_message) + self.check_webhook("pull_request__edited", expected_topic_name, expected_message) def test_pull_request_assigned(self) -> None: - expected_topic = "test / PR #1349 Test" + expected_topic_name = "test / PR #1349 Test" expected_message = """kostekIV assigned [PR #2](https://try.gogs.io/kostekIV/test/pulls/2) from `c` to `master`.""" - self.check_webhook("pull_request__assigned", expected_topic, expected_message) + self.check_webhook("pull_request__assigned", expected_topic_name, expected_message) def test_pull_request_synchronized(self) -> None: - expected_topic = "test / PR #1349 Test" + expected_topic_name = "test / PR #1349 Test" expected_message = """kostekIV synchronized [PR #2](https://try.gogs.io/kostekIV/test/pulls/2) from `c` to `master`.""" - self.check_webhook("pull_request__synchronized", expected_topic, expected_message) + self.check_webhook("pull_request__synchronized", expected_topic_name, expected_message) def test_issues_opened(self) -> None: - expected_topic = "test / issue #3 New test issue" + expected_topic_name = "test / issue #3 New test issue" expected_message = """kostekIV opened [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nTest\n~~~""" - self.check_webhook("issues__opened", expected_topic, expected_message) + self.check_webhook("issues__opened", expected_topic_name, expected_message) def test_issues_reopened(self) -> None: - expected_topic = "test / issue #3 New test issue" + expected_topic_name = "test / issue #3 New test issue" expected_message = """kostekIV reopened [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nTest\n~~~""" - self.check_webhook("issues__reopened", expected_topic, expected_message) + self.check_webhook("issues__reopened", expected_topic_name, expected_message) def test_issues_edited(self) -> None: - expected_topic = "test / issue #3 New test issue" + expected_topic_name = "test / issue #3 New test issue" expected_message = """kostekIV edited [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nTest edit\n~~~""" - self.check_webhook("issues__edited", expected_topic, expected_message) + self.check_webhook("issues__edited", expected_topic_name, expected_message) def test_issues_assignee(self) -> None: - expected_topic = "test / issue #3 New test issue" + expected_topic_name = "test / issue #3 New test issue" expected_message = """kostekIV assigned [issue #3](https://try.gogs.io/kostekIV/test/issues/3) (assigned to kostekIV):\n\n~~~ quote\nTest\n~~~""" - self.check_webhook("issues__assigned", expected_topic, expected_message) + self.check_webhook("issues__assigned", expected_topic_name, expected_message) def test_issues_closed(self) -> None: - expected_topic = "test / issue #3 New test issue" + expected_topic_name = "test / issue #3 New test issue" expected_message = """kostekIV closed [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nClosed #3\n~~~""" - self.check_webhook("issues__closed", expected_topic, expected_message) + self.check_webhook("issues__closed", expected_topic_name, expected_message) def test_issue_comment_new(self) -> None: - expected_topic = "test / issue #3 New test issue" + expected_topic_name = "test / issue #3 New test issue" expected_message = """kostekIV [commented](https://try.gogs.io/kostekIV/test/issues/3#issuecomment-3635) on [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nTest comment\n~~~""" - self.check_webhook("issue_comment__new", expected_topic, expected_message) + self.check_webhook("issue_comment__new", expected_topic_name, expected_message) def test_issue_comment_edited(self) -> None: - expected_topic = "test / issue #3 New test issue" + expected_topic_name = "test / issue #3 New test issue" expected_message = """kostekIV edited a [comment](https://try.gogs.io/kostekIV/test/issues/3#issuecomment-3634) on [issue #3](https://try.gogs.io/kostekIV/test/issues/3):\n\n~~~ quote\nedit comment\n~~~""" - self.check_webhook("issue_comment__edited", expected_topic, expected_message) + self.check_webhook("issue_comment__edited", expected_topic_name, expected_message) def test_release_published(self) -> None: - expected_topic = "zulip_test / v1.4 Title" + expected_topic_name = "zulip_test / v1.4 Title" expected_message = """cestrell published release [Title](https://try.gogs.io/cestrell/zulip_test) for tag v1.4.""" - self.check_webhook("release__published", expected_topic, expected_message) + self.check_webhook("release__published", expected_topic_name, expected_message) @patch("zerver.webhooks.gogs.view.check_send_webhook_message") def test_push_filtered_by_branches_ignore( diff --git a/zerver/webhooks/gogs/view.py b/zerver/webhooks/gogs/view.py index d436803889..c6c853caac 100644 --- a/zerver/webhooks/gogs/view.py +++ b/zerver/webhooks/gogs/view.py @@ -194,13 +194,13 @@ def gogs_webhook_main( if branches is not None and branch not in branches.split(","): return json_success(request) body = format_push_event(payload) - topic = TOPIC_WITH_BRANCH_TEMPLATE.format( + topic_name = TOPIC_WITH_BRANCH_TEMPLATE.format( repo=repo, branch=branch, ) elif event == "create": body = format_new_branch_event(payload) - topic = TOPIC_WITH_BRANCH_TEMPLATE.format( + topic_name = TOPIC_WITH_BRANCH_TEMPLATE.format( repo=repo, branch=payload["ref"].tame(check_string), ) @@ -209,7 +209,7 @@ def gogs_webhook_main( payload, include_title=user_specified_topic is not None, ) - topic = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format( + topic_name = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format( repo=repo, type="PR", id=payload["pull_request"]["id"].tame(check_int), @@ -220,7 +220,7 @@ def gogs_webhook_main( payload, include_title=user_specified_topic is not None, ) - topic = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format( + topic_name = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format( repo=repo, type="issue", id=payload["issue"]["number"].tame(check_int), @@ -231,7 +231,7 @@ def gogs_webhook_main( payload, include_title=user_specified_topic is not None, ) - topic = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format( + topic_name = TOPIC_WITH_PR_OR_ISSUE_INFO_TEMPLATE.format( repo=repo, type="issue", id=payload["issue"]["number"].tame(check_int), @@ -242,7 +242,7 @@ def gogs_webhook_main( payload, include_title=user_specified_topic is not None, ) - topic = TOPIC_WITH_RELEASE_TEMPLATE.format( + topic_name = TOPIC_WITH_RELEASE_TEMPLATE.format( repo=repo, tag=payload["release"]["tag_name"].tame(check_string), title=payload["release"]["name"].tame(check_string), @@ -251,5 +251,5 @@ def gogs_webhook_main( else: raise UnsupportedWebhookEventTypeError(event) - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/gosquared/tests.py b/zerver/webhooks/gosquared/tests.py index 8a8bb851fa..1a6a4373c3 100644 --- a/zerver/webhooks/gosquared/tests.py +++ b/zerver/webhooks/gosquared/tests.py @@ -9,20 +9,20 @@ class GoSquaredHookTests(WebhookTestCase): # Note: Include a test function per each distinct message condition your integration supports def test_traffic_message(self) -> None: - expected_topic = "GoSquared - requestb.in" + expected_topic_name = "GoSquared - requestb.in" expected_message = ( "[requestb.in](https://www.gosquared.com/now/GSN-595854-T) has 33 visitors online." ) self.check_webhook( "traffic_spike", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_chat_message(self) -> None: - expected_topic = "Live chat session - Zulip Chat" + expected_topic_name = "Live chat session - Zulip Chat" expected_message = CHAT_MESSAGE_TEMPLATE.format( status="visitor", name="John Smith", @@ -31,7 +31,7 @@ class GoSquaredHookTests(WebhookTestCase): self.check_webhook( "chat_message", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/gosquared/view.py b/zerver/webhooks/gosquared/view.py index 2ed4dc5207..d94bd01763 100644 --- a/zerver/webhooks/gosquared/view.py +++ b/zerver/webhooks/gosquared/view.py @@ -30,7 +30,7 @@ def api_gosquared_webhook( payload: JsonBodyPayload[WildValue], ) -> HttpResponse: body = "" - topic = "" + topic_name = "" # Unfortunately, there is no other way to infer the event type # than just inferring it from the payload's attributes @@ -43,21 +43,21 @@ def api_gosquared_webhook( body = TRAFFIC_SPIKE_TEMPLATE.format( website_name=domain_name, website_url=acc_url, user_num=user_num ) - topic = f"GoSquared - {domain_name}" - check_send_webhook_message(request, user_profile, topic, body, "traffic_spike") + topic_name = f"GoSquared - {domain_name}" + check_send_webhook_message(request, user_profile, topic_name, body, "traffic_spike") # Live chat message event elif payload.get("message") is not None and payload.get("person") is not None: # Only support non-direct messages if not payload["message"]["private"].tame(check_bool): session_title = payload["message"]["session"]["title"].tame(check_string) - topic = f"Live chat session - {session_title}" + topic_name = f"Live chat session - {session_title}" body = CHAT_MESSAGE_TEMPLATE.format( status=payload["person"]["status"].tame(check_string), name=payload["person"]["_anon"]["name"].tame(check_string), content=payload["message"]["content"].tame(check_string), ) - check_send_webhook_message(request, user_profile, topic, body, "chat_message") + check_send_webhook_message(request, user_profile, topic_name, body, "chat_message") else: raise UnsupportedWebhookEventTypeError("unknown_event") diff --git a/zerver/webhooks/grafana/tests.py b/zerver/webhooks/grafana/tests.py index 63f9c79864..e071637b61 100644 --- a/zerver/webhooks/grafana/tests.py +++ b/zerver/webhooks/grafana/tests.py @@ -8,7 +8,7 @@ class GrafanaHookTests(WebhookTestCase): # Note: Include a test function per each distinct message condition your integration supports def test_alert(self) -> None: - expected_topic = "[Alerting] Test notification" + expected_topic_name = "[Alerting] Test notification" expected_message = """ :alert: **ALERTING** @@ -25,13 +25,13 @@ Someone is testing the alert notification within grafana. # use fixture named helloworld_hello self.check_webhook( "alert", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_no_data_alert(self) -> None: - expected_topic = "[Alerting] No Data alert" + expected_topic_name = "[Alerting] No Data alert" expected_message = """ :alert: **ALERTING** @@ -44,13 +44,13 @@ The panel has no data. # use fixture named helloworld_hello self.check_webhook( "no_data_alert", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_no_message_alert(self) -> None: - expected_topic = "[Alerting] No Message alert" + expected_topic_name = "[Alerting] No Message alert" expected_message = """ :alert: **ALERTING** @@ -62,14 +62,14 @@ The panel has no data. # use fixture named helloworld_hello self.check_webhook( "no_message_alert", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) # Note: Include a test function per each distinct message condition your integration supports def test_alert_ok(self) -> None: - expected_topic = "[Ok] Test notification" + expected_topic_name = "[Ok] Test notification" expected_message = """ :squared_ok: **OK** @@ -85,14 +85,14 @@ Someone is testing the alert notification within grafana. # use fixture named helloworld_hello self.check_webhook( "alert_ok", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) # Note: Include a test function per each distinct message condition your integration supports def test_alert_paused(self) -> None: - expected_topic = "[Paused] Test notification" + expected_topic_name = "[Paused] Test notification" expected_message = """ :info: **PAUSED** @@ -107,14 +107,14 @@ Someone is testing the alert notification within grafana. # use fixture named helloworld_hello self.check_webhook( "alert_paused", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) # Note: Include a test function per each distinct message condition your integration supports def test_alert_pending(self) -> None: - expected_topic = "[Pending] Test notification" + expected_topic_name = "[Pending] Test notification" expected_message = """ :info: **PENDING** @@ -131,13 +131,13 @@ Someone is testing the alert notification within grafana. # use fixture named helloworld_hello self.check_webhook( "alert_pending", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_alert_new(self) -> None: - expected_topic = "[RESOLVED:1]" + expected_topic_name = "[RESOLVED:1]" expected_message = """ :checkbox: **RESOLVED** @@ -162,13 +162,13 @@ Annotations: self.check_webhook( "alert_new", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_alert_new_multiple(self) -> None: - expected_topic = "[FIRING:2]" + expected_topic_name = "[FIRING:2]" expected_message = """ :alert: **FIRING** @@ -206,7 +206,7 @@ Annotations: self.check_webhook( "alert_new_multiple", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/grafana/view.py b/zerver/webhooks/grafana/view.py index de2bd0e825..bfcc3113bd 100644 --- a/zerver/webhooks/grafana/view.py +++ b/zerver/webhooks/grafana/view.py @@ -56,7 +56,7 @@ def api_grafana_webhook( status = payload["status"].tame(check_string_in(["firing", "resolved"])) alert_count = len(payload["alerts"]) - topic = NEW_TOPIC_TEMPLATE.format(alert_status=status.upper(), alert_count=alert_count) + topic_name = NEW_TOPIC_TEMPLATE.format(alert_status=status.upper(), alert_count=alert_count) if status == "firing": body = ALERT_STATUS_TEMPLATE.format(alert_icon=":alert:", alert_state=status.upper()) @@ -97,13 +97,13 @@ def api_grafana_webhook( count=payload["truncatedAlerts"].tame(check_int) ) - check_send_webhook_message(request, user_profile, topic, body, status) + check_send_webhook_message(request, user_profile, topic_name, body, status) return json_success(request) # Legacy Grafana alerts. else: - topic = OLD_TOPIC_TEMPLATE.format(alert_title=payload["title"].tame(check_string)) + topic_name = OLD_TOPIC_TEMPLATE.format(alert_title=payload["title"].tame(check_string)) eval_matches_text = "" if "evalMatches" in payload and payload["evalMatches"] is not None: @@ -149,6 +149,6 @@ def api_grafana_webhook( body = body.strip() # send the message - check_send_webhook_message(request, user_profile, topic, body, state) + check_send_webhook_message(request, user_profile, topic_name, body, state) return json_success(request) diff --git a/zerver/webhooks/greenhouse/tests.py b/zerver/webhooks/greenhouse/tests.py index dc57df4dcc..71945fd781 100644 --- a/zerver/webhooks/greenhouse/tests.py +++ b/zerver/webhooks/greenhouse/tests.py @@ -10,7 +10,7 @@ class GreenhouseHookTests(WebhookTestCase): CONTENT_TYPE = "application/x-www-form-urlencoded" def test_message_candidate_hired(self) -> None: - expected_topic = "Hire Candidate - 19" + expected_topic_name = "Hire Candidate - 19" expected_message = """ Hire Candidate Johnny Smith (ID: 19), applying for: * **Role**: Developer @@ -19,11 +19,11 @@ Hire Candidate Johnny Smith (ID: 19), applying for: """.strip() self.check_webhook( - "candidate_hired", expected_topic, expected_message, content_type=self.CONTENT_TYPE + "candidate_hired", expected_topic_name, expected_message, content_type=self.CONTENT_TYPE ) def test_message_candidate_rejected(self) -> None: - expected_topic = "Reject Candidate - 265788" + expected_topic_name = "Reject Candidate - 265788" expected_message = """ Reject Candidate Hector Porter (ID: 265788), applying for: * **Role**: Designer @@ -32,11 +32,14 @@ Reject Candidate Hector Porter (ID: 265788), applying for: """.strip() self.check_webhook( - "candidate_rejected", expected_topic, expected_message, content_type=self.CONTENT_TYPE + "candidate_rejected", + expected_topic_name, + expected_message, + content_type=self.CONTENT_TYPE, ) def test_message_candidate_stage_change(self) -> None: - expected_topic = "Candidate Stage Change - 265772" + expected_topic_name = "Candidate Stage Change - 265772" expected_message = """ Candidate Stage Change Giuseppe Hurley (ID: 265772), applying for: * **Role**: Designer @@ -46,13 +49,13 @@ Candidate Stage Change Giuseppe Hurley (ID: 265772), applying for: self.check_webhook( "candidate_stage_change", - expected_topic, + expected_topic_name, expected_message, content_type=self.CONTENT_TYPE, ) def test_message_prospect_created(self) -> None: - expected_topic = "New Prospect Application - 968190" + expected_topic_name = "New Prospect Application - 968190" expected_message = """ New Prospect Application Trisha Troy (ID: 968190), applying for: * **Role**: Designer @@ -61,7 +64,10 @@ New Prospect Application Trisha Troy (ID: 968190), applying for: """.strip() self.check_webhook( - "prospect_created", expected_topic, expected_message, content_type=self.CONTENT_TYPE + "prospect_created", + expected_topic_name, + expected_message, + content_type=self.CONTENT_TYPE, ) @patch("zerver.webhooks.greenhouse.view.check_send_webhook_message") diff --git a/zerver/webhooks/greenhouse/view.py b/zerver/webhooks/greenhouse/view.py index a13357ebb0..eaf650a27b 100644 --- a/zerver/webhooks/greenhouse/view.py +++ b/zerver/webhooks/greenhouse/view.py @@ -59,7 +59,7 @@ def api_greenhouse_webhook( attachments=dict_list_to_string(application["candidate"]["attachments"]), ) - topic = "{} - {}".format(action, str(candidate["id"].tame(check_int))) + topic_name = "{} - {}".format(action, str(candidate["id"].tame(check_int))) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/groove/tests.py b/zerver/webhooks/groove/tests.py index fd5e2ccb63..ffb7068fa2 100644 --- a/zerver/webhooks/groove/tests.py +++ b/zerver/webhooks/groove/tests.py @@ -8,7 +8,7 @@ class GrooveHookTests(WebhookTestCase): # This test simulates the condition when a new ticket comes. def test_groove_ticket_started(self) -> None: - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = """ Test Name submitted new ticket [#9: Test Subject](https://ghostfox.groovehq.com/groove_client/tickets/68659446): @@ -19,7 +19,7 @@ The content of the body goes here. self.check_webhook( "ticket_started", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -27,11 +27,11 @@ The content of the body goes here. # This simulates the condition when a ticket # is assigned to an agent. def test_groove_ticket_assigned_agent_only(self) -> None: - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[#9: Test Subject](https://testteam.groovehq.com/groove_client/tickets/68659446) (open) assigned to agent@example.com." self.check_webhook( "ticket_assigned__agent_only", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -39,12 +39,12 @@ The content of the body goes here. # This simulates the condition when a ticket # is assigned to an agent in a group. def test_groove_ticket_assigned_agent_and_group(self) -> None: - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[#9: Test Subject](https://testteam.groovehq.com/groove_client/tickets/68659446) (open) assigned to agent@example.com from group2." self.check_webhook( "ticket_assigned__agent_and_group", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -52,11 +52,11 @@ The content of the body goes here. # This simulates the condition when a ticket # is assigned to a group. def test_groove_ticket_assigned_group_only(self) -> None: - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "[#9: Test Subject](https://testteam.groovehq.com/groove_client/tickets/68659446) (pending) assigned to group2." self.check_webhook( "ticket_assigned__group_only", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -75,7 +75,7 @@ The content of the body goes here. # This simulates the notification when an agent replied to a ticket. def test_groove_agent_replied(self) -> None: - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = """ agent@example.com replied to [ticket #776](https://ghostfox.groovehq.com/groove_client/tickets/68667295): @@ -86,14 +86,14 @@ Hello , This is a reply from an agent to a ticket self.check_webhook( "agent_replied", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) # This simulates the condition when a customer replied to a ticket. def test_groove_customer_replied(self) -> None: - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = """ rambo@example.com replied to [ticket #440](https://ghostfox.groovehq.com/groove_client/tickets/68666538): @@ -104,14 +104,14 @@ Hello agent, thanks for getting back. This is how a reply from customer looks li self.check_webhook( "customer_replied", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) # This simulates the condition when an agent left a note. def test_groove_note_added(self) -> None: - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = """ anotheragent@example.com left a note on [ticket #776](https://ghostfox.groovehq.com/groove_client/tickets/68667295): @@ -122,7 +122,7 @@ This is a note added to a ticket self.check_webhook( "note_added", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-ww-form-urlencoded", ) diff --git a/zerver/webhooks/groove/view.py b/zerver/webhooks/groove/view.py index a9a0613081..09a4363ee0 100644 --- a/zerver/webhooks/groove/view.py +++ b/zerver/webhooks/groove/view.py @@ -115,10 +115,10 @@ def api_groove_webhook( raise UnsupportedWebhookEventTypeError(event) body = handler(payload) - topic = "notifications" + topic_name = "notifications" if body is not None: - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/harbor/tests.py b/zerver/webhooks/harbor/tests.py index 74bd14214e..7774bbc44b 100644 --- a/zerver/webhooks/harbor/tests.py +++ b/zerver/webhooks/harbor/tests.py @@ -9,9 +9,9 @@ class HarborHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "harbor" def test_push_image(self) -> None: - expected_topic = "example/test" + expected_topic_name = "example/test" expected_message = """**admin** pushed image `example/test:latest`""" - self.check_webhook("push_image", expected_topic, expected_message) + self.check_webhook("push_image", expected_topic_name, expected_message) @patch("zerver.lib.webhooks.common.check_send_webhook_message") def test_delete_image_ignored(self, check_send_webhook_message_mock: MagicMock) -> None: @@ -22,7 +22,7 @@ class HarborHookTests(WebhookTestCase): self.assert_json_success(result) def test_scanning_completed(self) -> None: - expected_topic = "test/alpine/helm" + expected_topic_name = "test/alpine/helm" expected_message = """ Image scan completed for `test/alpine/helm:3.8.1`. Vulnerabilities by severity: @@ -31,10 +31,10 @@ Image scan completed for `test/alpine/helm:3.8.1`. Vulnerabilities by severity: * Unknown: **1** """.strip() - self.check_webhook("scanning_completed", expected_topic, expected_message) + self.check_webhook("scanning_completed", expected_topic_name, expected_message) def test_scanning_completed_no_vulnerability(self) -> None: - expected_topic = "test123/test-image" + expected_topic_name = "test123/test-image" expected_message = """ Image scan completed for `test123/test-image:latest`. Vulnerabilities by severity: @@ -42,10 +42,12 @@ Image scan completed for `test123/test-image:latest`. Vulnerabilities by severit None """.strip() - self.check_webhook("scanning_completed_no_vulnerability", expected_topic, expected_message) + self.check_webhook( + "scanning_completed_no_vulnerability", expected_topic_name, expected_message + ) def test_scanning_completed_no_tag(self) -> None: - expected_topic = "test/alpine/helm" + expected_topic_name = "test/alpine/helm" expected_message = """ Image scan completed for `test/alpine/helm@sha256:b50334049354ed01330403212605dce2f4676a4e787ed113506861d9cf3c5424`. Vulnerabilities by severity: @@ -54,4 +56,4 @@ Image scan completed for `test/alpine/helm@sha256:b50334049354ed01330403212605dc * Unknown: **1** """.strip() - self.check_webhook("scanning_completed_no_tag", expected_topic, expected_message) + self.check_webhook("scanning_completed_no_tag", expected_topic_name, expected_message) diff --git a/zerver/webhooks/harbor/view.py b/zerver/webhooks/harbor/view.py index ffea69c296..1817d21f29 100644 --- a/zerver/webhooks/harbor/view.py +++ b/zerver/webhooks/harbor/view.py @@ -106,7 +106,7 @@ def api_harbor_webhook( operator_username = f"@**{operator_profile.full_name}**" # nocoverage event = payload["type"].tame(check_string) - topic = payload["event_data"]["repository"]["repo_full_name"].tame(check_string) + topic_name = payload["event_data"]["repository"]["repo_full_name"].tame(check_string) if event in IGNORED_EVENTS: return json_success(request) @@ -119,6 +119,6 @@ def api_harbor_webhook( content: str = content_func(payload, user_profile, operator_username) check_send_webhook_message( - request, user_profile, topic, content, event, unquote_url_parameters=True + request, user_profile, topic_name, content, event, unquote_url_parameters=True ) return json_success(request) diff --git a/zerver/webhooks/hellosign/tests.py b/zerver/webhooks/hellosign/tests.py index 9d4338fce1..0a22b0fdaa 100644 --- a/zerver/webhooks/hellosign/tests.py +++ b/zerver/webhooks/hellosign/tests.py @@ -11,46 +11,49 @@ class HelloSignHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "hellosign" def test_signatures_message(self) -> None: - expected_topic = "NDA with Acme Co." + expected_topic_name = "NDA with Acme Co." expected_message = ( "The `NDA with Acme Co.` document is awaiting the signature of " "Jack, and was just signed by Jill." ) - self.check_webhook("signatures", expected_topic, expected_message, content_type=None) + self.check_webhook("signatures", expected_topic_name, expected_message, content_type=None) def test_signatures_message_signed_by_one(self) -> None: - expected_topic = "NDA with Acme Co." + expected_topic_name = "NDA with Acme Co." expected_message = "The `NDA with Acme Co.` document was just signed by Jill." self.check_webhook( "signatures_signed_by_one_signatory", - expected_topic, + expected_topic_name, expected_message, content_type=None, ) def test_signatures_message_with_four_signatories(self) -> None: - expected_topic = "Signature doc" + expected_topic_name = "Signature doc" expected_message = ( "The `Signature doc` document is awaiting the signature of " "Eeshan Garg, John Smith, Jane Doe, and Stephen Strange." ) self.check_webhook( - "signatures_with_four_signatories", expected_topic, expected_message, content_type=None + "signatures_with_four_signatories", + expected_topic_name, + expected_message, + content_type=None, ) def test_signatures_message_with_own_subject(self) -> None: - expected_topic = "Our own subject." - self.url = self.build_webhook_url(topic=expected_topic) + expected_topic_name = "Our own subject." + self.url = self.build_webhook_url(topic=expected_topic_name) expected_message = ( "The `NDA with Acme Co.` document is awaiting the signature of " "Jack, and was just signed by Jill." ) self.check_webhook( "signatures_with_own_subject", - expected_topic, + expected_topic_name, expected_message, content_type=None, - topic=expected_topic, + topic=expected_topic_name, ) @override diff --git a/zerver/webhooks/hellosign/view.py b/zerver/webhooks/hellosign/view.py index c2eed8e652..e9ccaa474f 100644 --- a/zerver/webhooks/hellosign/view.py +++ b/zerver/webhooks/hellosign/view.py @@ -67,7 +67,7 @@ def api_hellosign_webhook( ) -> HttpResponse: if "signature_request" in payload: body = get_message_body(payload) - topic = payload["signature_request"]["title"].tame(check_string) - check_send_webhook_message(request, user_profile, topic, body) + topic_name = payload["signature_request"]["title"].tame(check_string) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request, data={"msg": "Hello API Event Received"}) diff --git a/zerver/webhooks/helloworld/tests.py b/zerver/webhooks/helloworld/tests.py index 92cdee952e..0ec9f0327a 100644 --- a/zerver/webhooks/helloworld/tests.py +++ b/zerver/webhooks/helloworld/tests.py @@ -13,25 +13,25 @@ class HelloWorldHookTests(WebhookTestCase): # Note: Include a test function per each distinct message condition your integration supports def test_hello_message(self) -> None: - expected_topic = "Hello World" + expected_topic_name = "Hello World" expected_message = "Hello! I am happy to be here! :smile:\nThe Wikipedia featured article for today is **[Marilyn Monroe](https://en.wikipedia.org/wiki/Marilyn_Monroe)**" # use fixture named helloworld_hello self.check_webhook( "hello", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_goodbye_message(self) -> None: - expected_topic = "Hello World" + expected_topic_name = "Hello World" expected_message = "Hello! I am happy to be here! :smile:\nThe Wikipedia featured article for today is **[Goodbye](https://en.wikipedia.org/wiki/Goodbye)**" # use fixture named helloworld_goodbye self.check_webhook( "goodbye", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -64,13 +64,13 @@ class HelloWorldHookTests(WebhookTestCase): def test_custom_topic(self) -> None: # Note that this is really just a test for check_send_webhook_message - expected_topic = "Custom Topic" - self.url = self.build_webhook_url(topic=expected_topic) + expected_topic_name = "Custom Topic" + self.url = self.build_webhook_url(topic=expected_topic_name) expected_message = "Hello! I am happy to be here! :smile:\nThe Wikipedia featured article for today is **[Goodbye](https://en.wikipedia.org/wiki/Goodbye)**" self.check_webhook( "goodbye", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/helloworld/view.py b/zerver/webhooks/helloworld/view.py index 67bc61ae2f..5592d98ac8 100644 --- a/zerver/webhooks/helloworld/view.py +++ b/zerver/webhooks/helloworld/view.py @@ -30,9 +30,9 @@ def api_helloworld_webhook( featured_url=payload["featured_url"].tame(check_string), ) - topic = "Hello World" + topic_name = "Hello World" # send the message - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/heroku/tests.py b/zerver/webhooks/heroku/tests.py index c927c22897..5933c12016 100644 --- a/zerver/webhooks/heroku/tests.py +++ b/zerver/webhooks/heroku/tests.py @@ -8,7 +8,7 @@ class HerokuHookTests(WebhookTestCase): URL_TEMPLATE = "/api/v1/external/heroku?stream={stream}&api_key={api_key}" def test_deployment(self) -> None: - expected_topic = "sample-project" + expected_topic_name = "sample-project" expected_message = """ user@example.com deployed version 3eb5f44 of [sample-project](http://sample-project.herokuapp.com): @@ -18,13 +18,13 @@ user@example.com deployed version 3eb5f44 of [sample-project](http://sample-proj """.strip() self.check_webhook( "deploy", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_deployment_multiple_commits(self) -> None: - expected_topic = "sample-project" + expected_topic_name = "sample-project" expected_message = """user@example.com deployed version 3eb5f44 of \ [sample-project](http://sample-project.herokuapp.com) ``` quote @@ -42,7 +42,7 @@ user@example.com deployed version 3eb5f44 of [sample-project](http://sample-proj """.strip() self.check_webhook( "deploy_multiple_commits", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/homeassistant/tests.py b/zerver/webhooks/homeassistant/tests.py index 411e65de2a..723753d97a 100644 --- a/zerver/webhooks/homeassistant/tests.py +++ b/zerver/webhooks/homeassistant/tests.py @@ -7,23 +7,23 @@ class HomeAssistantHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "homeassistant" def test_simplereq(self) -> None: - expected_topic = "homeassistant" + expected_topic_name = "homeassistant" expected_message = "The sun will be shining today!" self.check_webhook( "simplereq", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_req_with_title(self) -> None: - expected_topic = "Weather forecast" + expected_topic_name = "Weather forecast" expected_message = "It will be 30 degrees Celsius out there today!" self.check_webhook( "reqwithtitle", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/homeassistant/view.py b/zerver/webhooks/homeassistant/view.py index 001a4faee5..1910754ad4 100644 --- a/zerver/webhooks/homeassistant/view.py +++ b/zerver/webhooks/homeassistant/view.py @@ -21,12 +21,12 @@ def api_homeassistant_webhook( # set the topic to the topic parameter, if given if "topic" in payload: - topic = payload["topic"].tame(check_string) + topic_name = payload["topic"].tame(check_string) else: - topic = "homeassistant" + topic_name = "homeassistant" # send the message - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) # return json result return json_success(request) diff --git a/zerver/webhooks/ifttt/tests.py b/zerver/webhooks/ifttt/tests.py index dfba84ecc6..5faa917ea0 100644 --- a/zerver/webhooks/ifttt/tests.py +++ b/zerver/webhooks/ifttt/tests.py @@ -8,14 +8,14 @@ class IFTTTHookTests(WebhookTestCase): VIEW_FUNCTION_NAME = "api_iftt_app_webhook" def test_ifttt_when_subject_and_body_are_correct(self) -> None: - expected_topic = "Email sent from email@email.com" + expected_topic_name = "Email sent from email@email.com" expected_message = "Email subject: Subject" - self.check_webhook("correct_subject_and_body", expected_topic, expected_message) + self.check_webhook("correct_subject_and_body", expected_topic_name, expected_message) def test_ifttt_when_topic_and_body_are_correct(self) -> None: - expected_topic = "Email sent from email@email.com" + expected_topic_name = "Email sent from email@email.com" expected_message = "Email subject: Subject" - self.check_webhook("correct_topic_and_body", expected_topic, expected_message) + self.check_webhook("correct_topic_and_body", expected_topic_name, expected_message) def test_ifttt_when_topic_is_missing(self) -> None: self.url = self.build_webhook_url() diff --git a/zerver/webhooks/ifttt/view.py b/zerver/webhooks/ifttt/view.py index c08cac8897..8e712baadc 100644 --- a/zerver/webhooks/ifttt/view.py +++ b/zerver/webhooks/ifttt/view.py @@ -20,14 +20,14 @@ def api_iftt_app_webhook( payload: JsonBodyPayload[WildValue], ) -> HttpResponse: try: - topic = payload.get("topic").tame(check_none_or(check_string)) + topic_name = payload.get("topic").tame(check_none_or(check_string)) content = payload.get("content").tame(check_none_or(check_string)) - if topic is None: - topic = payload.get("subject").tame( + if topic_name is None: + topic_name = payload.get("subject").tame( check_none_or(check_string) ) # Backwards-compatibility - if topic is None: + if topic_name is None: raise JsonableError(_("Topic can't be empty")) if content is None: @@ -36,5 +36,5 @@ def api_iftt_app_webhook( except ValidationError: raise JsonableError(_("Malformed payload")) - check_send_webhook_message(request, user_profile, topic, content) + check_send_webhook_message(request, user_profile, topic_name, content) return json_success(request) diff --git a/zerver/webhooks/insping/tests.py b/zerver/webhooks/insping/tests.py index 7cb9bd7943..c33d99c6a4 100644 --- a/zerver/webhooks/insping/tests.py +++ b/zerver/webhooks/insping/tests.py @@ -7,7 +7,7 @@ class InspingHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "insping" def test_website_state_available_message(self) -> None: - expected_topic = "insping" + expected_topic_name = "insping" expected_message = """ State changed to **Available**: * **URL**: http://privisus.zulipdev.org:9991 @@ -17,13 +17,13 @@ State changed to **Available**: self.check_webhook( "website_state_available", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_website_state_not_responding_message(self) -> None: - expected_topic = "insping" + expected_topic_name = "insping" expected_message = """ State changed to **Not Responding**: * **URL**: http://privisus.zulipdev.org:9991 @@ -33,7 +33,7 @@ State changed to **Not Responding**: self.check_webhook( "website_state_not_responding", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/insping/view.py b/zerver/webhooks/insping/view.py index 78565df7a7..3928111634 100644 --- a/zerver/webhooks/insping/view.py +++ b/zerver/webhooks/insping/view.py @@ -41,8 +41,8 @@ def api_insping_webhook( timestamp=time_formatted, ) - topic = "insping" + topic_name = "insping" - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/intercom/tests.py b/zerver/webhooks/intercom/tests.py index dbd813c86a..920011db9f 100644 --- a/zerver/webhooks/intercom/tests.py +++ b/zerver/webhooks/intercom/tests.py @@ -17,7 +17,7 @@ class IntercomWebHookTests(WebhookTestCase): self.assert_json_success(result) def test_company_created(self) -> None: - expected_topic = "Companies" + expected_topic_name = "Companies" expected_message = """ New company **Kandra Labs** created: * **User count**: 1 @@ -25,21 +25,21 @@ New company **Kandra Labs** created: """.strip() self.check_webhook( "company_created", - expected_topic, + expected_topic_name, expected_message, ) def test_contact_added_email(self) -> None: - expected_topic = "Contact: Azure Bus from St. John's" + expected_topic_name = "Contact: Azure Bus from St. John's" expected_message = "New email jerryguitarist@gmail.com added to contact." self.check_webhook( "contact_added_email", - expected_topic, + expected_topic_name, expected_message, ) def test_contact_created(self) -> None: - expected_topic = "Contact: Azure Bus from St. John's" + expected_topic_name = "Contact: Azure Bus from St. John's" expected_message = """ New contact created: * **Name (or pseudonym)**: Azure Bus from St. John's @@ -48,12 +48,12 @@ New contact created: """.strip() self.check_webhook( "contact_created", - expected_topic, + expected_topic_name, expected_message, ) def test_contact_signed_up(self) -> None: - expected_topic = "User: Lilac Raindrop from St. John's" + expected_topic_name = "User: Lilac Raindrop from St. John's" expected_message = """ Contact signed up: * **Email**: iago@zulip.com @@ -61,75 +61,75 @@ Contact signed up: """.strip() self.check_webhook( "contact_signed_up", - expected_topic, + expected_topic_name, expected_message, ) def test_contact_tag_created(self) -> None: - expected_topic = "Contact: Eeshan Garg" + expected_topic_name = "Contact: Eeshan Garg" expected_message = "Contact tagged with the `developer` tag." self.check_webhook( "contact_tag_created", - expected_topic, + expected_topic_name, expected_message, ) def test_contact_tag_deleted(self) -> None: - expected_topic = "Contact: Eeshan Garg" + expected_topic_name = "Contact: Eeshan Garg" expected_message = "The tag `developer` was removed from the contact." self.check_webhook( "contact_tag_deleted", - expected_topic, + expected_topic_name, expected_message, ) def test_conversation_admin_assigned(self) -> None: - expected_topic = "Lead: Eeshan Garg" + expected_topic_name = "Lead: Eeshan Garg" expected_message = "Tim Abbott assigned to conversation." self.check_webhook( "conversation_admin_assigned", - expected_topic, + expected_topic_name, expected_message, ) def test_conversation_admin_opened(self) -> None: - expected_topic = "Lead: Cordelia, Lear's daughter" + expected_topic_name = "Lead: Cordelia, Lear's daughter" expected_message = "Eeshan Garg opened the conversation." self.check_webhook( "conversation_admin_opened", - expected_topic, + expected_topic_name, expected_message, ) def test_conversation_admin_closed(self) -> None: - expected_topic = "Lead: Eeshan Garg" + expected_topic_name = "Lead: Eeshan Garg" expected_message = "Cordelia, Lear's daughter closed the conversation." self.check_webhook( "conversation_admin_closed", - expected_topic, + expected_topic_name, expected_message, ) def test_conversation_admin_snoozed(self) -> None: - expected_topic = "Lead: Eeshan Garg" + expected_topic_name = "Lead: Eeshan Garg" expected_message = "Cordelia, Lear's daughter snoozed the conversation." self.check_webhook( "conversation_admin_snoozed", - expected_topic, + expected_topic_name, expected_message, ) def test_conversation_admin_unsnoozed(self) -> None: - expected_topic = "Lead: Eeshan Garg" + expected_topic_name = "Lead: Eeshan Garg" expected_message = "Cordelia, Lear's daughter unsnoozed the conversation." self.check_webhook( "conversation_admin_unsnoozed", - expected_topic, + expected_topic_name, expected_message, ) def test_conversation_admin_replied(self) -> None: - expected_topic = "Lead: Eeshan Garg" + expected_topic_name = "Lead: Eeshan Garg" expected_message = """ Cordelia, Lear's daughter replied to the conversation: @@ -139,12 +139,12 @@ Hey Eeshan! How can I help? """.strip() self.check_webhook( "conversation_admin_replied", - expected_topic, + expected_topic_name, expected_message, ) def test_conversation_admin_noted(self) -> None: - expected_topic = "Lead: Eeshan Garg" + expected_topic_name = "Lead: Eeshan Garg" expected_message = """ Cordelia, Lear's daughter added a note to the conversation: @@ -154,12 +154,12 @@ Talk to Tim about this user's query. """.strip() self.check_webhook( "conversation_admin_noted", - expected_topic, + expected_topic_name, expected_message, ) def test_conversation_admin_single_created(self) -> None: - expected_topic = "Lead: Eeshan Garg" + expected_topic_name = "Lead: Eeshan Garg" expected_message = """ Cordelia, Lear's daughter initiated a conversation: @@ -169,12 +169,12 @@ Hi Eeshan, What's up """.strip() self.check_webhook( "conversation_admin_single_created", - expected_topic, + expected_topic_name, expected_message, ) def test_conversation_user_created(self) -> None: - expected_topic = "Lead: Rose Poodle from St. John's" + expected_topic_name = "Lead: Rose Poodle from St. John's" expected_message = """ Rose Poodle from St. John's initiated a conversation: @@ -184,12 +184,12 @@ Hello everyone! """.strip() self.check_webhook( "conversation_user_created", - expected_topic, + expected_topic_name, expected_message, ) def test_conversation_user_replied(self) -> None: - expected_topic = "Lead: Eeshan Garg" + expected_topic_name = "Lead: Eeshan Garg" expected_message = """ Eeshan Garg replied to the conversation: @@ -199,21 +199,21 @@ Well, I need some help getting access to a developer account. """.strip() self.check_webhook( "conversation_user_replied", - expected_topic, + expected_topic_name, expected_message, ) def test_event_created(self) -> None: - expected_topic = "Events" + expected_topic_name = "Events" expected_message = "New event **invited-friend** created." self.check_webhook( "event_created", - expected_topic, + expected_topic_name, expected_message, ) def test_user_created(self) -> None: - expected_topic = "User: Aaron Smith" + expected_topic_name = "User: Aaron Smith" expected_message = """ New user created: * **Name**: Aaron Smith @@ -222,7 +222,7 @@ New user created: self.check_webhook( "user_created", - expected_topic, + expected_topic_name, expected_message, ) @@ -248,14 +248,14 @@ New user created: ) def test_user_tag_deleted(self) -> None: - expected_topic = "User: eeshangarg" + expected_topic_name = "User: eeshangarg" expected_message = ( "The tag `CSV Import - 2019-03-26 22:46:04 UTC` was removed from the user." ) self.check_webhook( "user_tag_deleted", - expected_topic, + expected_topic_name, expected_message, ) diff --git a/zerver/webhooks/intercom/view.py b/zerver/webhooks/intercom/view.py index 2e2eefb92d..52b02dc42c 100644 --- a/zerver/webhooks/intercom/view.py +++ b/zerver/webhooks/intercom/view.py @@ -89,14 +89,14 @@ def strip_tags(html: str) -> str: def get_topic_for_contacts(user: WildValue) -> str: - topic = "{type}: {name}".format( + topic_name = "{type}: {name}".format( type=user["type"].tame(check_string).capitalize(), name=user.get("name").tame(check_none_or(check_string)) or user.get("pseudonym").tame(check_none_or(check_string)) or user.get("email").tame(check_none_or(check_string)), ) - return topic + return topic_name def get_company_created_message(payload: WildValue) -> Tuple[str, str]: @@ -111,8 +111,8 @@ def get_company_created_message(payload: WildValue) -> Tuple[str, str]: def get_contact_added_email_message(payload: WildValue) -> Tuple[str, str]: user = payload["data"]["item"] body = CONTACT_EMAIL_ADDED.format(email=user["email"].tame(check_string)) - topic = get_topic_for_contacts(user) - return (topic, body) + topic_name = get_topic_for_contacts(user) + return (topic_name, body) def get_contact_created_message(payload: WildValue) -> Tuple[str, str]: @@ -127,8 +127,8 @@ def get_contact_created_message(payload: WildValue) -> Tuple[str, str]: country_name=contact["location_data"]["country_name"].tame(check_string), ), ) - topic = get_topic_for_contacts(contact) - return (topic, body) + topic_name = get_topic_for_contacts(contact) + return (topic_name, body) def get_contact_signed_up_message(payload: WildValue) -> Tuple[str, str]: @@ -141,8 +141,8 @@ def get_contact_signed_up_message(payload: WildValue) -> Tuple[str, str]: country_name=contact["location_data"]["country_name"].tame(check_string), ), ) - topic = get_topic_for_contacts(contact) - return (topic, body) + topic_name = get_topic_for_contacts(contact) + return (topic_name, body) def get_contact_tag_created_message(payload: WildValue) -> Tuple[str, str]: @@ -150,8 +150,8 @@ def get_contact_tag_created_message(payload: WildValue) -> Tuple[str, str]: name=payload["data"]["item"]["tag"]["name"].tame(check_string) ) contact = payload["data"]["item"]["contact"] - topic = get_topic_for_contacts(contact) - return (topic, body) + topic_name = get_topic_for_contacts(contact) + return (topic_name, body) def get_contact_tag_deleted_message(payload: WildValue) -> Tuple[str, str]: @@ -159,8 +159,8 @@ def get_contact_tag_deleted_message(payload: WildValue) -> Tuple[str, str]: name=payload["data"]["item"]["tag"]["name"].tame(check_string) ) contact = payload["data"]["item"]["contact"] - topic = get_topic_for_contacts(contact) - return (topic, body) + topic_name = get_topic_for_contacts(contact) + return (topic_name, body) def get_conversation_admin_assigned_message(payload: WildValue) -> Tuple[str, str]: @@ -168,8 +168,8 @@ def get_conversation_admin_assigned_message(payload: WildValue) -> Tuple[str, st name=payload["data"]["item"]["assignee"]["name"].tame(check_string) ) user = payload["data"]["item"]["user"] - topic = get_topic_for_contacts(user) - return (topic, body) + topic_name = get_topic_for_contacts(user) + return (topic_name, body) def get_conversation_admin_message( @@ -182,8 +182,8 @@ def get_conversation_admin_message( admin_name=assignee.get("name").tame(check_none_or(check_string)), action=action, ) - topic = get_topic_for_contacts(user) - return (topic, body) + topic_name = get_topic_for_contacts(user) + return (topic_name, body) def get_conversation_admin_reply_message( @@ -199,8 +199,8 @@ def get_conversation_admin_reply_message( action=action, content=content, ) - topic = get_topic_for_contacts(user) - return (topic, body) + topic_name = get_topic_for_contacts(user) + return (topic_name, body) def get_conversation_admin_single_created_message(payload: WildValue) -> Tuple[str, str]: @@ -212,8 +212,8 @@ def get_conversation_admin_single_created_message(payload: WildValue) -> Tuple[s admin_name=assignee.get("name").tame(check_none_or(check_string)), content=content, ) - topic = get_topic_for_contacts(user) - return (topic, body) + topic_name = get_topic_for_contacts(user) + return (topic_name, body) def get_conversation_user_created_message(payload: WildValue) -> Tuple[str, str]: @@ -224,8 +224,8 @@ def get_conversation_user_created_message(payload: WildValue) -> Tuple[str, str] admin_name=user.get("name").tame(check_none_or(check_string)), content=content, ) - topic = get_topic_for_contacts(user) - return (topic, body) + topic_name = get_topic_for_contacts(user) + return (topic_name, body) def get_conversation_user_replied_message(payload: WildValue) -> Tuple[str, str]: @@ -237,8 +237,8 @@ def get_conversation_user_replied_message(payload: WildValue) -> Tuple[str, str] action="replied to", content=content, ) - topic = get_topic_for_contacts(user) - return (topic, body) + topic_name = get_topic_for_contacts(user) + return (topic_name, body) def get_event_created_message(payload: WildValue) -> Tuple[str, str]: @@ -252,21 +252,21 @@ def get_user_created_message(payload: WildValue) -> Tuple[str, str]: body = USER_CREATED.format( name=user["name"].tame(check_string), email=user["email"].tame(check_string) ) - topic = get_topic_for_contacts(user) - return (topic, body) + topic_name = get_topic_for_contacts(user) + return (topic_name, body) def get_user_deleted_message(payload: WildValue) -> Tuple[str, str]: user = payload["data"]["item"] - topic = get_topic_for_contacts(user) - return (topic, "User deleted.") + topic_name = get_topic_for_contacts(user) + return (topic_name, "User deleted.") def get_user_email_updated_message(payload: WildValue) -> Tuple[str, str]: user = payload["data"]["item"] body = "User's email was updated to {}.".format(user["email"].tame(check_string)) - topic = get_topic_for_contacts(user) - return (topic, body) + topic_name = get_topic_for_contacts(user) + return (topic_name, body) def get_user_tagged_message( @@ -275,19 +275,19 @@ def get_user_tagged_message( ) -> Tuple[str, str]: user = payload["data"]["item"]["user"] tag = payload["data"]["item"]["tag"] - topic = get_topic_for_contacts(user) + topic_name = get_topic_for_contacts(user) body = "The tag `{tag_name}` was {action} the user.".format( tag_name=tag["name"].tame(check_string), action=action, ) - return (topic, body) + return (topic_name, body) def get_user_unsubscribed_message(payload: WildValue) -> Tuple[str, str]: user = payload["data"]["item"] body = "User unsubscribed from emails." - topic = get_topic_for_contacts(user) - return (topic, body) + topic_name = get_topic_for_contacts(user) + return (topic_name, body) EVENT_TO_FUNCTION_MAPPER: Dict[str, Callable[[WildValue], Tuple[str, str]]] = { @@ -343,7 +343,7 @@ def api_intercom_webhook( handler = EVENT_TO_FUNCTION_MAPPER.get(event_type) if handler is None: raise UnsupportedWebhookEventTypeError(event_type) - topic, body = handler(payload) + topic_name, body = handler(payload) - check_send_webhook_message(request, user_profile, topic, body, event_type) + check_send_webhook_message(request, user_profile, topic_name, body, event_type) return json_success(request) diff --git a/zerver/webhooks/jira/tests.py b/zerver/webhooks/jira/tests.py index d269005cde..f617058d83 100644 --- a/zerver/webhooks/jira/tests.py +++ b/zerver/webhooks/jira/tests.py @@ -34,15 +34,15 @@ Leo Franchi created [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/ ) def test_created(self) -> None: - expected_topic = "BUG-15: New bug with hook" + expected_topic_name = "BUG-15: New bug with hook" expected_message = """ Leo Franchi created [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15): * **Priority**: Major * **Assignee**: no one """.strip() - self.check_webhook("created_v1", expected_topic, expected_message) - self.check_webhook("created_v2", expected_topic, expected_message) + self.check_webhook("created_v1", expected_topic_name, expected_message) + self.check_webhook("created_v2", expected_topic_name, expected_message) def test_ignored_events(self) -> None: ignored_actions = [ @@ -74,7 +74,7 @@ Leo Franchi created [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/ self.assert_json_success(result) - expected_topic = "BUG-15: New bug with hook" + expected_topic_name = "BUG-15: New bug with hook" expected_message = """ Leo Franchi created [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15): @@ -83,7 +83,7 @@ Leo Franchi created [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/ """.strip() msg = self.get_last_message() self.assertEqual(msg.content, expected_message) - self.assertEqual(msg.topic_name(), expected_topic) + self.assertEqual(msg.topic_name(), expected_topic_name) def test_created_with_stream_with_spaces_double_escaped(self) -> None: self.STREAM_NAME = quote(quote("jira alerts")) @@ -95,7 +95,7 @@ Leo Franchi created [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/ self.assert_json_success(result) - expected_topic = "BUG-15: New bug with hook" + expected_topic_name = "BUG-15: New bug with hook" expected_message = """ Leo Franchi created [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15): @@ -104,43 +104,43 @@ Leo Franchi created [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/ """.strip() msg = self.get_last_message() self.assertEqual(msg.content, expected_message) - self.assertEqual(msg.topic_name(), expected_topic) + self.assertEqual(msg.topic_name(), expected_topic_name) def test_created_with_topic_with_spaces_double_escaped(self) -> None: self.url = self.build_webhook_url(topic=quote(quote("alerts test"))) - expected_topic = "alerts test" + expected_topic_name = "alerts test" expected_message = """ Leo Franchi created [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15): * **Priority**: Major * **Assignee**: no one """.strip() - self.check_webhook("created_v1", expected_topic, expected_message) + self.check_webhook("created_v1", expected_topic_name, expected_message) def test_created_with_unicode(self) -> None: - expected_topic = "BUG-15: New bug with à hook" + expected_topic_name = "BUG-15: New bug with à hook" expected_message = """ Leo Franchià created [BUG-15: New bug with à hook](http://lfranchi.com:8080/browse/BUG-15): * **Priority**: Major * **Assignee**: no one """.strip() - self.check_webhook("created_with_unicode_v1", expected_topic, expected_message) - self.check_webhook("created_with_unicode_v2", expected_topic, expected_message) + self.check_webhook("created_with_unicode_v1", expected_topic_name, expected_message) + self.check_webhook("created_with_unicode_v2", expected_topic_name, expected_message) def test_created_assignee(self) -> None: - expected_topic = "TEST-4: Test Created Assignee" + expected_topic_name = "TEST-4: Test Created Assignee" expected_message = """ Leonardo Franchi [Administrator] created [TEST-4: Test Created Assignee](https://zulipp.atlassian.net/browse/TEST-4): * **Priority**: Major * **Assignee**: Leonardo Franchi [Administrator] """.strip() - self.check_webhook("created_assignee_v1", expected_topic, expected_message) - self.check_webhook("created_assignee_v2", expected_topic, expected_message) + self.check_webhook("created_assignee_v1", expected_topic_name, expected_message) + self.check_webhook("created_assignee_v2", expected_topic_name, expected_message) def test_commented(self) -> None: - expected_topic = "BUG-15: New bug with hook" + expected_topic_name = "BUG-15: New bug with hook" expected_message = """ Leo Franchi commented on [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**): @@ -148,11 +148,11 @@ Leo Franchi commented on [BUG-15: New bug with hook](http://lfranchi.com:8080/br Adding a comment. Oh, what a comment it is! ``` """.strip() - self.check_webhook("commented_v1", expected_topic, expected_message) - self.check_webhook("commented_v2", expected_topic, expected_message) + self.check_webhook("commented_v1", expected_topic_name, expected_message) + self.check_webhook("commented_v2", expected_topic_name, expected_message) def test_commented_with_two_full_links(self) -> None: - expected_topic = "BUG-15: New bug with hook" + expected_topic_name = "BUG-15: New bug with hook" expected_message = """ Leo Franchi commented on [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**): @@ -160,10 +160,12 @@ Leo Franchi commented on [BUG-15: New bug with hook](http://lfranchi.com:8080/br This is the [first link](https://google.com) and this is the [second link](https://google.com) and this is the end. ``` """.strip() - self.check_webhook("commented_v2_with_two_full_links", expected_topic, expected_message) + self.check_webhook( + "commented_v2_with_two_full_links", expected_topic_name, expected_message + ) def test_comment_edited(self) -> None: - expected_topic = "BUG-15: New bug with hook" + expected_topic_name = "BUG-15: New bug with hook" expected_message = """ Leo Franchi edited a comment on [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**): @@ -171,69 +173,71 @@ Leo Franchi edited a comment on [BUG-15: New bug with hook](http://lfranchi.com: Adding a comment. Oh, what a comment it is! ``` """.strip() - self.check_webhook("comment_edited_v2", expected_topic, expected_message) + self.check_webhook("comment_edited_v2", expected_topic_name, expected_message) def test_comment_deleted(self) -> None: - expected_topic = "TOM-1: New Issue" + expected_topic_name = "TOM-1: New Issue" expected_message = "Tomasz Kolek deleted a comment from [TOM-1: New Issue](https://zuliptomek.atlassian.net/browse/TOM-1) (assigned to **kolaszek@go2.pl**)." - self.check_webhook("comment_deleted_v2", expected_topic, expected_message) + self.check_webhook("comment_deleted_v2", expected_topic_name, expected_message) def test_commented_markup(self) -> None: - expected_topic = "TEST-7: Testing of rich text" + expected_topic_name = "TEST-7: Testing of rich text" expected_message = """Leonardo Franchi [Administrator] commented on [TEST-7: Testing of rich text](https://zulipp.atlassian.net/browse/TEST-7):\n\n``` quote\nThis is a comment that likes to **exercise** a lot of _different_ `conventions` that `jira uses`.\r\n\r\n~~~\n\r\nthis code is not highlighted, but monospaced\r\n\n~~~\r\n\r\n~~~\n\r\ndef python():\r\n print "likes to be formatted"\r\n\n~~~\r\n\r\n[http://www.google.com](http://www.google.com) is a bare link, and [Google](http://www.google.com) is given a title.\r\n\r\nThanks!\r\n\r\n~~~ quote\n\r\nSomeone said somewhere\r\n\n~~~\n```""" - self.check_webhook("commented_markup_v1", expected_topic, expected_message) - self.check_webhook("commented_markup_v2", expected_topic, expected_message) + self.check_webhook("commented_markup_v1", expected_topic_name, expected_message) + self.check_webhook("commented_markup_v2", expected_topic_name, expected_message) def test_deleted(self) -> None: - expected_topic = "BUG-15: New bug with hook" + expected_topic_name = "BUG-15: New bug with hook" expected_message = "Leo Franchi deleted [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15)." - self.check_webhook("deleted_v1", expected_topic, expected_message) - self.check_webhook("deleted_v2", expected_topic, expected_message) + self.check_webhook("deleted_v1", expected_topic_name, expected_message) + self.check_webhook("deleted_v2", expected_topic_name, expected_message) def test_reassigned(self) -> None: - expected_topic = "BUG-15: New bug with hook" + expected_topic_name = "BUG-15: New bug with hook" expected_message = """Leo Franchi updated [BUG-15: New bug with hook](http://lfranchi.com:8080/browse/BUG-15) (assigned to **Othello, the Moor of Venice**): * Changed assignee to **Othello, the Moor of Venice**""" - self.check_webhook("reassigned_v1", expected_topic, expected_message) - self.check_webhook("reassigned_v2", expected_topic, expected_message) + self.check_webhook("reassigned_v1", expected_topic_name, expected_message) + self.check_webhook("reassigned_v2", expected_topic_name, expected_message) def test_priority_updated(self) -> None: - expected_topic = "TEST-1: Fix That" + expected_topic_name = "TEST-1: Fix That" expected_message = """Leonardo Franchi [Administrator] updated [TEST-1: Fix That](https://zulipp.atlassian.net/browse/TEST-1) (assigned to **leo@zulip.com**): * Changed priority from **Critical** to **Major**""" - self.check_webhook("updated_priority_v1", expected_topic, expected_message) - self.check_webhook("updated_priority_v2", expected_topic, expected_message) + self.check_webhook("updated_priority_v1", expected_topic_name, expected_message) + self.check_webhook("updated_priority_v2", expected_topic_name, expected_message) def test_status_changed(self) -> None: - expected_topic = "TEST-1: Fix That" + expected_topic_name = "TEST-1: Fix That" expected_message = """Leonardo Franchi [Administrator] updated [TEST-1: Fix That](https://zulipp.atlassian.net/browse/TEST-1): * Changed status from **To Do** to **In Progress**""" - self.check_webhook("change_status_v1", expected_topic, expected_message) - self.check_webhook("change_status_v2", expected_topic, expected_message) + self.check_webhook("change_status_v1", expected_topic_name, expected_message) + self.check_webhook("change_status_v2", expected_topic_name, expected_message) def test_comment_event_comment_created(self) -> None: - expected_topic = "SP-1: Add support for newer format Jira issue comment events" + expected_topic_name = "SP-1: Add support for newer format Jira issue comment events" expected_message = """Hemanth V. Alluri commented on issue: *"Add support for newer format Jira issue comment events"*\n``` quote\nSounds like it’s pretty important. I’ll get this fixed ASAP!\n```""" - self.check_webhook("comment_created", expected_topic, expected_message) + self.check_webhook("comment_created", expected_topic_name, expected_message) def test_comment_event_comment_created_no_issue_details(self) -> None: - expected_topic = "10000: Upgrade Jira to get the issue title here." + expected_topic_name = "10000: Upgrade Jira to get the issue title here." expected_message = """Hemanth V. Alluri commented on issue: *"Upgrade Jira to get the issue title here."*\n``` quote\nSounds like it’s pretty important. I’ll get this fixed ASAP!\n```""" - self.check_webhook("comment_created_no_issue_details", expected_topic, expected_message) + self.check_webhook( + "comment_created_no_issue_details", expected_topic_name, expected_message + ) def test_comment_event_comment_edited(self) -> None: - expected_topic = "SP-1: Add support for newer format Jira issue comment events" + expected_topic_name = "SP-1: Add support for newer format Jira issue comment events" expected_message = """Hemanth V. Alluri updated their comment on issue: *"Add support for newer format Jira issue comment events"*\n``` quote\nThis is a very important issue! I’m on it!\n```""" - self.check_webhook("comment_updated", expected_topic, expected_message) + self.check_webhook("comment_updated", expected_topic_name, expected_message) def test_comment_event_comment_deleted(self) -> None: - expected_topic = "SP-1: Add support for newer format Jira issue comment events" + expected_topic_name = "SP-1: Add support for newer format Jira issue comment events" expected_message = """Hemanth V. Alluri deleted their comment on issue: *"Add support for newer format Jira issue comment events"*\n``` quote\n~~This is a very important issue! I’m on it!~~\n```""" - self.check_webhook("comment_deleted", expected_topic, expected_message) + self.check_webhook("comment_deleted", expected_topic_name, expected_message) def test_anomalous_webhook_payload_error(self) -> None: with self.assertRaises(AssertionError) as e: diff --git a/zerver/webhooks/jira/view.py b/zerver/webhooks/jira/view.py index 08118a1f17..f322e1abdf 100644 --- a/zerver/webhooks/jira/view.py +++ b/zerver/webhooks/jira/view.py @@ -372,10 +372,10 @@ def api_jira_webhook( if content_func is None: raise UnsupportedWebhookEventTypeError(event) - topic = get_issue_topic(payload) + topic_name = get_issue_topic(payload) content: str = content_func(payload, user_profile) check_send_webhook_message( - request, user_profile, topic, content, event, unquote_url_parameters=True + request, user_profile, topic_name, content, event, unquote_url_parameters=True ) return json_success(request) diff --git a/zerver/webhooks/jotform/view.py b/zerver/webhooks/jotform/view.py index 36740e914e..641816b232 100644 --- a/zerver/webhooks/jotform/view.py +++ b/zerver/webhooks/jotform/view.py @@ -18,7 +18,7 @@ def api_jotform_webhook( *, payload: JsonBodyPayload[WildValue], ) -> HttpResponse: - topic = payload["formTitle"].tame(check_string) + topic_name = payload["formTitle"].tame(check_string) submission_id = payload["submissionID"].tame(check_string) fields = payload["pretty"].tame(check_string).split(", ") @@ -28,5 +28,5 @@ def api_jotform_webhook( message = form_response.strip() - check_send_webhook_message(request, user_profile, topic, message) + check_send_webhook_message(request, user_profile, topic_name, message) return json_success(request) diff --git a/zerver/webhooks/json/tests.py b/zerver/webhooks/json/tests.py index fd97dfd8e1..3c3463db7c 100644 --- a/zerver/webhooks/json/tests.py +++ b/zerver/webhooks/json/tests.py @@ -15,11 +15,11 @@ class JsonHookTests(WebhookTestCase): with open("zerver/webhooks/json/fixtures/json_github_push__1_commit.json") as f: original_fixture = json.load(f) - expected_topic = "JSON" + expected_topic_name = "JSON" expected_message = f"""```json {json.dumps(original_fixture, indent=2)} ```""" - self.check_webhook("json_github_push__1_commit", expected_topic, expected_message) + self.check_webhook("json_github_push__1_commit", expected_topic_name, expected_message) def test_json_pingdom_http_up_to_down_message(self) -> None: """ @@ -28,11 +28,11 @@ class JsonHookTests(WebhookTestCase): with open("zerver/webhooks/json/fixtures/json_pingdom_http_up_to_down.json") as f: original_fixture = json.load(f) - expected_topic = "JSON" + expected_topic_name = "JSON" expected_message = f"""```json {json.dumps(original_fixture, indent=2)} ```""" - self.check_webhook("json_pingdom_http_up_to_down", expected_topic, expected_message) + self.check_webhook("json_pingdom_http_up_to_down", expected_topic_name, expected_message) def test_json_sentry_event_for_exception_js_message(self) -> None: """ @@ -41,8 +41,10 @@ class JsonHookTests(WebhookTestCase): with open("zerver/webhooks/json/fixtures/json_sentry_event_for_exception_js.json") as f: original_fixture = json.load(f) - expected_topic = "JSON" + expected_topic_name = "JSON" expected_message = f"""```json {json.dumps(original_fixture, indent=2)} ```""" - self.check_webhook("json_sentry_event_for_exception_js", expected_topic, expected_message) + self.check_webhook( + "json_sentry_event_for_exception_js", expected_topic_name, expected_message + ) diff --git a/zerver/webhooks/json/view.py b/zerver/webhooks/json/view.py index 77e302f097..584e2c1f3e 100644 --- a/zerver/webhooks/json/view.py +++ b/zerver/webhooks/json/view.py @@ -25,9 +25,9 @@ def api_json_webhook( payload: JsonBodyPayload[Dict[str, Any]], ) -> HttpResponse: body = get_body_for_http_request(payload) - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/librato/tests.py b/zerver/webhooks/librato/tests.py index d35691ebd7..b1856e139f 100644 --- a/zerver/webhooks/librato/tests.py +++ b/zerver/webhooks/librato/tests.py @@ -20,53 +20,53 @@ class LibratoHookTests(WebhookTestCase): ) def test_alert_message_with_default_topic(self) -> None: - expected_topic = "Alert alert.name" + expected_topic_name = "Alert alert.name" 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.check_webhook( "alert", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_alert_message_with_custom_topic(self) -> None: - custom_topic = "custom_name" - self.url = self.build_webhook_url(topic=custom_topic) + custom_topic_name = "custom_name" + self.url = self.build_webhook_url(topic=custom_topic_name) 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.check_webhook( "alert", - custom_topic, + custom_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_three_conditions_alert_message(self) -> None: expected_message = "Alert [alert_name](https://metrics.librato.com/alerts#/6294535) has triggered! [Reaction steps](http://www.use.water.pl):\n * Metric `collectd.interface.eth0.if_octets.tx`, absolute_value was above 4 by 300s, recorded at 2016-04-11 20:40:14 UTC.\n * Metric `collectd.load.load.longterm`, max was above 99, recorded at 2016-04-11 20:40:14 UTC.\n * Metric `librato.swap.swap.cached`, average was absent by 60s, recorded at 2016-04-11 20:40:14 UTC." - expected_topic = "Alert TooHighTemperature" + expected_topic_name = "Alert TooHighTemperature" self.check_webhook( "three_conditions_alert", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_alert_clear(self) -> None: - expected_topic = "Alert Alert_name" + expected_topic_name = "Alert Alert_name" expected_message = "Alert [alert_name](https://metrics.librato.com/alerts#/6309313) has cleared at 2016-04-12 13:11:44 UTC!" self.check_webhook( "alert_cleared", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_snapshot(self) -> None: self.IS_ATTACHMENT = True - expected_topic = "Snapshots" + expected_topic_name = "Snapshots" expected_message = "**Hamlet** sent a [snapshot](http://snapshots.librato.com/chart/nr5l3n0c-82162.png) of [metric](https://metrics.librato.com/s/spaces/167315/explore/1731491?duration=72039&end_time=1460569409)." self.check_webhook( "snapshot", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/librato/view.py b/zerver/webhooks/librato/view.py index f0da7175d0..4b0e9981c1 100644 --- a/zerver/webhooks/librato/view.py +++ b/zerver/webhooks/librato/view.py @@ -177,12 +177,12 @@ def api_librato_webhook( raise JsonableError(_("Malformed JSON input")) message_handler = LibratoWebhookHandler(payload, attachments) - topic = message_handler.generate_topic() + topic_name = message_handler.generate_topic() try: content = message_handler.handle() except Exception as e: raise JsonableError(str(e)) - check_send_webhook_message(request, user_profile, topic, content) + check_send_webhook_message(request, user_profile, topic_name, content) return json_success(request) diff --git a/zerver/webhooks/lidarr/tests.py b/zerver/webhooks/lidarr/tests.py index 5598060e2a..16c723ced4 100644 --- a/zerver/webhooks/lidarr/tests.py +++ b/zerver/webhooks/lidarr/tests.py @@ -10,31 +10,31 @@ class LidarrHookTests(WebhookTestCase): """ Tests if lidarr test payload is handled correctly """ - expected_topic = "Lidarr - Test" + expected_topic_name = "Lidarr - Test" expected_message = "Lidarr webhook has been successfully configured." - self.check_webhook("lidarr_test", expected_topic, expected_message) + self.check_webhook("lidarr_test", expected_topic_name, expected_message) def test_lidarr_tracks_renamed(self) -> None: """ Tests if lidarr tracks renamed payload is handled correctly """ - expected_topic = "Little Mix" + expected_topic_name = "Little Mix" expected_message = "The artist Little Mix has had its tracks renamed." - self.check_webhook("lidarr_tracks_renamed", expected_topic, expected_message) + self.check_webhook("lidarr_tracks_renamed", expected_topic_name, expected_message) def test_lidarr_tracks_retagged(self) -> None: """ Tests if lidarr tracks retagged payload is handled correctly """ - expected_topic = "Little Mix" + expected_topic_name = "Little Mix" expected_message = "The artist Little Mix has had its tracks retagged." - self.check_webhook("lidarr_tracks_retagged", expected_topic, expected_message) + self.check_webhook("lidarr_tracks_retagged", expected_topic_name, expected_message) def test_lidarr_tracks_imported(self) -> None: """ Tests if lidarr tracks imported payload is handled correctly """ - expected_topic = "UB40" + expected_topic_name = "UB40" expected_message = """ The following tracks by UB40 have been imported: * Cherry Oh Baby @@ -48,13 +48,13 @@ The following tracks by UB40 have been imported: * Version Girl * Many Rivers to Cross """.strip() - self.check_webhook("lidarr_tracks_imported", expected_topic, expected_message) + self.check_webhook("lidarr_tracks_imported", expected_topic_name, expected_message) def test_lidarr_tracks_imported_upgrade(self) -> None: """ Tests if lidarr tracks imported upgrade payload is handled correctly """ - expected_topic = "Little Mix" + expected_topic_name = "Little Mix" expected_message = """ The following tracks by Little Mix have been imported due to upgrade: * The National Manthem @@ -76,21 +76,21 @@ The following tracks by Little Mix have been imported due to upgrade: * The Cure (stripped) * Only You """.strip() - self.check_webhook("lidarr_tracks_imported_upgrade", expected_topic, expected_message) + self.check_webhook("lidarr_tracks_imported_upgrade", expected_topic_name, expected_message) def test_lidarr_album_grabbed(self) -> None: """ Tests if lidarr album grabbed payload is handled correctly """ - expected_topic = "UB40" + expected_topic_name = "UB40" expected_message = "The album Labour of Love by UB40 has been grabbed." - self.check_webhook("lidarr_album_grabbed", expected_topic, expected_message) + self.check_webhook("lidarr_album_grabbed", expected_topic_name, expected_message) def test_lidarr_tracks_imported_over_limit(self) -> None: """ Tests if lidarr tracks imported over limit payload is handled correctly """ - expected_topic = "Michael Jackson" + expected_topic_name = "Michael Jackson" expected_message = """ The following tracks by Michael Jackson have been imported: * Scream @@ -115,13 +115,15 @@ The following tracks by Michael Jackson have been imported: * Childhood (theme from “Free Willy 2”) [and 10 more tracks(s)] """.strip() - self.check_webhook("lidarr_tracks_imported_over_limit", expected_topic, expected_message) + self.check_webhook( + "lidarr_tracks_imported_over_limit", expected_topic_name, expected_message + ) def test_lidarr_tracks_imported_upgrade_over_limit(self) -> None: """ Tests if lidarr tracks imported upgrade over limit payload is handled correctly """ - expected_topic = "Michael Jackson" + expected_topic_name = "Michael Jackson" expected_message = """ The following tracks by Michael Jackson have been imported due to upgrade: * Scream @@ -147,5 +149,5 @@ The following tracks by Michael Jackson have been imported due to upgrade: [and 10 more tracks(s)] """.strip() self.check_webhook( - "lidarr_tracks_imported_upgrade_over_limit", expected_topic, expected_message + "lidarr_tracks_imported_upgrade_over_limit", expected_topic_name, expected_message ) diff --git a/zerver/webhooks/lidarr/view.py b/zerver/webhooks/lidarr/view.py index 227070b7ec..cd45ac828a 100644 --- a/zerver/webhooks/lidarr/view.py +++ b/zerver/webhooks/lidarr/view.py @@ -62,23 +62,23 @@ def api_lidarr_webhook( payload: JsonBodyPayload[WildValue], ) -> HttpResponse: body = get_body_for_http_request(payload) - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) check_send_webhook_message( - request, user_profile, topic, body, payload["eventType"].tame(check_string) + request, user_profile, topic_name, body, payload["eventType"].tame(check_string) ) return json_success(request) def get_topic_for_http_request(payload: WildValue) -> str: if payload["eventType"].tame(check_string) == "Test": - topic = LIDARR_TOPIC_TEMPLATE_TEST + topic_name = LIDARR_TOPIC_TEMPLATE_TEST else: - topic = LIDARR_TOPIC_TEMPLATE.format( + topic_name = LIDARR_TOPIC_TEMPLATE.format( artist_name=payload["artist"]["name"].tame(check_string) ) - return topic + return topic_name def get_body_for_album_grabbed_event(payload: WildValue) -> str: diff --git a/zerver/webhooks/linear/tests.py b/zerver/webhooks/linear/tests.py index 2acbeb9c59..70c5954943 100644 --- a/zerver/webhooks/linear/tests.py +++ b/zerver/webhooks/linear/tests.py @@ -7,73 +7,73 @@ class LinearHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "linear" def test_issue_create_simple_without_description(self) -> None: - expected_topic = "21e12515-fe5e-4923-88a1-e9ace5056473" + expected_topic_name = "21e12515-fe5e-4923-88a1-e9ace5056473" expected_message = "Issue [#42 Drop-down overflow in the select menu.](https://linear.app/webhooks/issue/WEB-42/drop-down-overflow-in-the-select-menu) was created in team Webhooks.\nPriority: High, Status: Todo." self.check_webhook( "issue_create_simple_without_description", - expected_topic, + expected_topic_name, expected_message, ) def test_issue_create_simple_without_description_with_custom_topic_in_url(self) -> None: self.url = self.build_webhook_url(topic="notifications") - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = "Issue [#42 Drop-down overflow in the select menu.](https://linear.app/webhooks/issue/WEB-42/drop-down-overflow-in-the-select-menu) was created in team Webhooks.\nPriority: High, Status: Todo." self.check_webhook( "issue_create_simple_without_description", - expected_topic, + expected_topic_name, expected_message, ) def test_issue_create_simple(self) -> None: - expected_topic = "a4344dc7-7d8d-4b28-a93c-553ac9aba41a" + expected_topic_name = "a4344dc7-7d8d-4b28-a93c-553ac9aba41a" expected_message = 'Issue [#43 Very small font in tooltip](https://linear.app/webhooks/issue/WEB-43/very-small-font-in-tooltip) was created in team Webhooks:\n~~~ quote\nThe tooltips at the "Select Drawing" and "Edit Drawing" buttons have a very small font and therefore are not very legible. Apart from this, the wording of the text has to be changed to fit better with the overall design pattern.\n~~~\n\nStatus: Todo.' - self.check_webhook("issue_create_simple", expected_topic, expected_message) + self.check_webhook("issue_create_simple", expected_topic_name, expected_message) def test_issue_create_complex(self) -> None: - expected_topic = "3443a709-f2b5-46f2-a136-a0445fd432be" + expected_topic_name = "3443a709-f2b5-46f2-a136-a0445fd432be" expected_message = "Issue [#44 This is regarding the outage that we faced during 11/12/22 from 2000 to 2200.](https://linear.app/webhooks/issue/WEB-44/this-is-regarding-the-outage-that-we-faced-during-111222-from-2000-to) was created in team Webhooks:\n~~~ quote\nThe outage that occurred on the above-mentioned date is a cause for concern as it could have significant implications for the organization and its users. A prolonged outage can result in lost revenue, productivity, and customer confidence. Therefore, it is essential to conduct a detailed assessment and analysis to identify the root cause of the outage and take appropriate measures to prevent its recurrence.\n\nThe analysis process may involve the use of specialized tools and techniques to help pinpoint the exact cause of the outage. Once the root cause has been identified, the organization can take steps to implement effective solutions that can mitigate the risk of a similar outage happening in the future. The assessment and analysis process will help the organization to develop a more robust and reliable IT infrastructure that can provide uninterrupted services to its users.\n~~~\n\nPriority: Urgent, Assignee: Satyam Bansal, Status: In Progress." - self.check_webhook("issue_create_complex", expected_topic, expected_message) + self.check_webhook("issue_create_complex", expected_topic_name, expected_message) def test_comment_create(self) -> None: - expected_topic = "f9a37fcf-eb52-44be-a52c-0477f70e9952" + expected_topic_name = "f9a37fcf-eb52-44be-a52c-0477f70e9952" expected_message = "Satyam Bansal [commented](https://linear.app/webhooks/issue/WEB-46#comment-c7cafc52) on issue **Thorough Impact Analysis and Cost Realization**:\n~~~ quote\nPerforming a thorough impact analysis and cost realization is a crucial step in responding to any system outage or incident. By examining the extent of the outage, the affected systems or services, the number of users impacted, and any error messages or logs generated during the incident, we can gain a comprehensive understanding of the scope of the incident.\n\nThis information can then be used to prioritize the resolution efforts and minimize the impact on our organization's operations. Additionally, cost realization allows us to evaluate the financial impact of the outage on our organization and make informed decisions regarding resource allocation for future incidents.\n\nOverall, conducting a thorough impact analysis and cost realization can help us effectively manage incidents and prevent similar issues from occurring in the future.\n~~~" - self.check_webhook("comment_create", expected_topic, expected_message) + self.check_webhook("comment_create", expected_topic_name, expected_message) def test_comment_remove(self) -> None: - expected_topic = "f9a37fcf-eb52-44be-a52c-0477f70e9952" + expected_topic_name = "f9a37fcf-eb52-44be-a52c-0477f70e9952" expected_message = "Satyam Bansal has removed a comment." - self.check_webhook("comment_remove", expected_topic, expected_message) + self.check_webhook("comment_remove", expected_topic_name, expected_message) def test_comment_update(self) -> None: - expected_topic = "f9a37fcf-eb52-44be-a52c-0477f70e9952" + expected_topic_name = "f9a37fcf-eb52-44be-a52c-0477f70e9952" expected_message = "Satyam Bansal [updated comment](https://linear.app/webhooks/issue/WEB-46#comment-c7cafc52) on issue **Thorough Impact Analysis and Cost Realization**:\n~~~ quote\nInvalid response to any system outage or incident, it is essential to perform a comprehensive impact analysis and cost evaluation. By examining factors such as the extent of the outage, the affected systems or services, the number of users affected, and any error messages or logs generated during the incident, we can gain a detailed understanding of the incident's scope.\n\nThis information is then critical in prioritizing resolution efforts and reducing the impact on our organization's operations. Additionally, conducting cost realization allows us to assess the financial implications of the outage and make informed decisions about allocating resources for future incidents.\n\nOverall, performing a thorough impact analysis and cost realization is an effective way to manage incidents and prevent similar issues from recurring.\n~~~" - self.check_webhook("comment_update", expected_topic, expected_message) + self.check_webhook("comment_update", expected_topic_name, expected_message) def test_issue_remove(self) -> None: - expected_topic = "3443a709-f2b5-46f2-a136-a0445fd432be" + expected_topic_name = "3443a709-f2b5-46f2-a136-a0445fd432be" expected_message = "Issue **#44 This is regarding the outage that we faced on 11/12/22 from 2000 to 2200 and also on 25/12/22 from 0000 to 0230** has been removed from team Webhooks." - self.check_webhook("issue_remove", expected_topic, expected_message) + self.check_webhook("issue_remove", expected_topic_name, expected_message) def test_issue_sub_issue_create(self) -> None: - expected_topic = "3443a709-f2b5-46f2-a136-a0445fd432be" + expected_topic_name = "3443a709-f2b5-46f2-a136-a0445fd432be" expected_message = "Sub-Issue [#46 Impact Analysis](https://linear.app/webhooks/issue/WEB-46/impact-analysis) was created in team Webhooks:\n~~~ quote\nExamining the extent of the outage, the affected systems or services, the number of users impacted, and any error messages or logs generated during the incident.\n~~~\n\nStatus: Todo." - self.check_webhook("issue_sub_issue_create", expected_topic, expected_message) + self.check_webhook("issue_sub_issue_create", expected_topic_name, expected_message) def test_issue_sub_issue_remove(self) -> None: - expected_topic = "3443a709-f2b5-46f2-a136-a0445fd432be" + expected_topic_name = "3443a709-f2b5-46f2-a136-a0445fd432be" expected_message = "Sub-Issue **#46 Thorough Impact Analysis and Cost Realization** has been removed from team Webhooks." - self.check_webhook("issue_sub_issue_remove", expected_topic, expected_message) + self.check_webhook("issue_sub_issue_remove", expected_topic_name, expected_message) def test_issue_sub_issue_update(self) -> None: - expected_topic = "3443a709-f2b5-46f2-a136-a0445fd432be" + expected_topic_name = "3443a709-f2b5-46f2-a136-a0445fd432be" expected_message = "Sub-Issue [#46 Thorough Impact Analysis and Cost Realization](https://linear.app/webhooks/issue/WEB-46/thorough-impact-analysis-and-cost-realization) was updated in team Webhooks:\n~~~ quote\nExamining the extent of the outage, the affected systems or services, the number of users impacted, and any error messages or logs generated during the incident.\n~~~\n\nStatus: Todo." - self.check_webhook("issue_sub_issue_update", expected_topic, expected_message) + self.check_webhook("issue_sub_issue_update", expected_topic_name, expected_message) def test_issue_update(self) -> None: - expected_topic = "3443a709-f2b5-46f2-a136-a0445fd432be" + expected_topic_name = "3443a709-f2b5-46f2-a136-a0445fd432be" expected_message = "Issue [#44 This is regarding the outage that we faced on 11/12/22 from 2000 to 2200 and also on 25/12/22 from 0000 to 0230](https://linear.app/webhooks/issue/WEB-44/this-is-regarding-the-outage-that-we-faced-on-111222-from-2000-to-2200) was updated in team Webhooks:\n~~~ quote\nThe outage that occurred on the above-mentioned date is a cause for concern as it could have significant implications for the organization and its users. A prolonged outage can result in lost revenue, productivity, and customer confidence. Therefore, it is essential to conduct a detailed assessment and analysis to identify the root cause of the outage and take appropriate measures to prevent its recurrence.\n\nThe analysis process may involve the use of specialized tools and techniques to help pinpoint the exact cause of the outage. Once the root cause has been identified, the organization can take steps to implement effective solutions that can mitigate the risk of a similar outage happening in the future. The assessment and analysis process will help the organization to develop a more robust and reliable IT infrastructure that can provide uninterrupted services to its users.\n~~~\n\nPriority: Urgent, Assignee: Satyam Bansal, Status: In Progress." - self.check_webhook("issue_update", expected_topic, expected_message) + self.check_webhook("issue_update", expected_topic_name, expected_message) def test_project_create(self) -> None: payload = self.get_body("project_create") diff --git a/zerver/webhooks/linear/view.py b/zerver/webhooks/linear/view.py index b67e39646d..5e7f3c6d9a 100644 --- a/zerver/webhooks/linear/view.py +++ b/zerver/webhooks/linear/view.py @@ -123,12 +123,12 @@ def api_linear_webhook( if event_type is None: return json_success(request) - topic = get_topic(user_specified_topic, event_type, payload) + topic_name = get_topic(user_specified_topic, event_type, payload) body_function = EVENT_FUNCTION_MAPPER[event_type] body = body_function(payload, event_type) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/mention/tests.py b/zerver/webhooks/mention/tests.py index 65f31bacdb..261ac59cea 100644 --- a/zerver/webhooks/mention/tests.py +++ b/zerver/webhooks/mention/tests.py @@ -7,7 +7,7 @@ class MentionHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "mention" def test_mention_webfeed(self) -> None: - expected_topic = "news" + expected_topic_name = "news" expected_message = """ **[Historical Sexual Abuse (Football): 29 Nov 2016: House of Commons debates - TheyWorkForYou](https://www.theyworkforyou.com/debates/?id=2016-11-29b.1398.7&p=24887)**: @@ -20,7 +20,7 @@ Children up and down the country are \u2026 # use fixture named mention_webfeeds self.check_webhook( "webfeeds", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/mention/view.py b/zerver/webhooks/mention/view.py index 9c8a65150a..3114f62256 100644 --- a/zerver/webhooks/mention/view.py +++ b/zerver/webhooks/mention/view.py @@ -29,9 +29,9 @@ def api_mention_webhook( ``` """.strip() body = template.format(title=title, url=source_url, description=description) - topic = "news" + topic_name = "news" # send the message - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/netlify/tests.py b/zerver/webhooks/netlify/tests.py index 37bdfd818b..99254797c1 100644 --- a/zerver/webhooks/netlify/tests.py +++ b/zerver/webhooks/netlify/tests.py @@ -7,50 +7,56 @@ class NetlifyHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "netlify" def test_building_message(self) -> None: - expected_topic = "master" + expected_topic_name = "master" expected_message = "The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) on branch master is now building." self.check_webhook( - "deploy_building", expected_topic, expected_message, content_type="application/json" + "deploy_building", + expected_topic_name, + expected_message, + content_type="application/json", ) def test_created_message(self) -> None: - expected_topic = "master" + expected_topic_name = "master" expected_message = "The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) on branch master is now ready." self.check_webhook( - "deploy_created", expected_topic, expected_message, content_type="application/json" + "deploy_created", expected_topic_name, expected_message, content_type="application/json" ) def test_failed_message(self) -> None: - expected_topic = "master" + expected_topic_name = "master" expected_message = ( "The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) " "on branch master failed during stage 'building site': Build script returned non-zero exit code: 127" ) self.check_webhook( - "deploy_failed", expected_topic, expected_message, content_type="application/json" + "deploy_failed", expected_topic_name, expected_message, content_type="application/json" ) def test_locked_message(self) -> None: - expected_topic = "master" + expected_topic_name = "master" expected_message = ( "The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) " "on branch master is now locked." ) self.check_webhook( - "deploy_locked", expected_topic, expected_message, content_type="application/json" + "deploy_locked", expected_topic_name, expected_message, content_type="application/json" ) def test_unlocked_message(self) -> None: - expected_topic = "master" + expected_topic_name = "master" expected_message = ( "The build [objective-jepsen-35fbb2](http://objective-jepsen-35fbb2.netlify.com) " "on branch master is now unlocked." ) self.check_webhook( - "deploy_unlocked", expected_topic, expected_message, content_type="application/json" + "deploy_unlocked", + expected_topic_name, + expected_message, + content_type="application/json", ) diff --git a/zerver/webhooks/netlify/view.py b/zerver/webhooks/netlify/view.py index 4dea627a92..e517809d62 100644 --- a/zerver/webhooks/netlify/view.py +++ b/zerver/webhooks/netlify/view.py @@ -42,9 +42,9 @@ def api_netlify_webhook( state=payload["state"].tame(check_string), ) - topic = "{topic}".format(topic=payload["branch"].tame(check_string)) + topic_name = "{topic}".format(topic=payload["branch"].tame(check_string)) - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/newrelic/tests.py b/zerver/webhooks/newrelic/tests.py index 1f56a069e7..8d94b7c6d2 100644 --- a/zerver/webhooks/newrelic/tests.py +++ b/zerver/webhooks/newrelic/tests.py @@ -11,7 +11,7 @@ class NewRelicHookTests(WebhookTestCase): # These tests and fixtures are to be deleted when old notifications EOLed def test_open_old(self) -> None: - expected_topic = "Test policy name (1234)" + expected_topic_name = "Test policy name (1234)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **opened** for condition: **Server Down** at ``` quote @@ -21,33 +21,33 @@ Violation description test. self.check_webhook( "incident_opened_old", - expected_topic, + expected_topic_name, expected_message, content_type="application/json", ) def test_closed_old(self) -> None: - expected_topic = "Test policy name (1234)" + expected_topic_name = "Test policy name (1234)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **closed** for condition: **Server Down** """.strip() self.check_webhook( "incident_closed_old", - expected_topic, + expected_topic_name, expected_message, content_type="application/json", ) def test_acknowledged_old(self) -> None: - expected_topic = "Test policy name (1234)" + expected_topic_name = "Test policy name (1234)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **acknowledged** by **Alice** for condition: **Server Down** """.strip() self.check_webhook( "incident_acknowledged_old", - expected_topic, + expected_topic_name, expected_message, content_type="application/json", ) @@ -66,7 +66,7 @@ Violation description test. ) def test_missing_fields_old(self) -> None: - expected_topic = "Unknown Policy (Unknown ID)" + expected_topic_name = "Unknown Policy (Unknown ID)" expected_message = """ [Incident](https://alerts.newrelic.com) **opened** for condition: **Unknown condition** at ``` quote @@ -76,7 +76,7 @@ No details. self.check_webhook( "incident_default_fields_old", - expected_topic, + expected_topic_name, expected_message, content_type="application/json", ) @@ -131,7 +131,7 @@ No details. # corresponding json fixtures have "_new" trailing in the name def test_activated_new(self) -> None: - expected_topic = "Test policy name (8ceed342-f305-4bfa-adb8-97ba93f5dd26)" + expected_topic_name = "Test policy name (8ceed342-f305-4bfa-adb8-97ba93f5dd26)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **active** for condition: **Server Down** at ``` quote @@ -141,46 +141,46 @@ Violation description test. self.check_webhook( "incident_active_new", - expected_topic, + expected_topic_name, expected_message, content_type="application/json", ) def test_created_new(self) -> None: - expected_topic = "Test policy name (8114ada3-572e-4550-a310-12375371669e)" + expected_topic_name = "Test policy name (8114ada3-572e-4550-a310-12375371669e)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **created** for condition: **Server Down** """.strip() self.check_webhook( "incident_created_new", - expected_topic, + expected_topic_name, expected_message, content_type="application/json", ) def test_closed_new(self) -> None: - expected_topic = "Test policy name (f0d98b28-bf9d-49e7-b9d0-ac7cbb52e73a)" + expected_topic_name = "Test policy name (f0d98b28-bf9d-49e7-b9d0-ac7cbb52e73a)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **closed** for condition: **Server Down** """.strip() self.check_webhook( "incident_closed_new", - expected_topic, + expected_topic_name, expected_message, content_type="application/json", ) def test_acknowledged_new(self) -> None: - expected_topic = "Test policy name (3576f543-dc3c-4d97-9f16-5c81f35195cb)" + expected_topic_name = "Test policy name (3576f543-dc3c-4d97-9f16-5c81f35195cb)" expected_message = """ [Incident](https://alerts.newrelic.com/accounts/2941966/incidents/1234) **acknowledged** by **Alice** for condition: **Server Down** """.strip() self.check_webhook( "incident_acknowledged_new", - expected_topic, + expected_topic_name, expected_message, content_type="application/json", ) @@ -199,7 +199,7 @@ Violation description test. ) def test_missing_fields_new(self) -> None: - expected_topic = "Unknown Policy (e04156e4-4cac-4f39-9d27-75d361e40a6d)" + expected_topic_name = "Unknown Policy (e04156e4-4cac-4f39-9d27-75d361e40a6d)" expected_message = """ [Incident](https://alerts.newrelic.com) **active** for condition: **Unknown condition** at ``` quote @@ -209,7 +209,7 @@ No details. self.check_webhook( "incident_default_fields_new", - expected_topic, + expected_topic_name, expected_message, content_type="application/json", ) diff --git a/zerver/webhooks/newrelic/view.py b/zerver/webhooks/newrelic/view.py index 3a4aaffe59..24d201a161 100644 --- a/zerver/webhooks/newrelic/view.py +++ b/zerver/webhooks/newrelic/view.py @@ -105,9 +105,9 @@ def api_newrelic_webhook( check_union([check_string, check_int]) ), } - topic = TOPIC_TEMPLATE.format(**topic_info) + topic_name = TOPIC_TEMPLATE.format(**topic_info) - check_send_webhook_message(request, user_profile, topic, content, info["status"]) + check_send_webhook_message(request, user_profile, topic_name, content, info["status"]) return json_success(request) # Handle new format @@ -163,7 +163,7 @@ def api_newrelic_webhook( "policy_name": policy_names_str, "incident_id": payload.get("id", "Unknown ID").tame(check_string), } - topic = TOPIC_TEMPLATE.format(**topic_info) + topic_name = TOPIC_TEMPLATE.format(**topic_info) - check_send_webhook_message(request, user_profile, topic, content, info["status"]) + check_send_webhook_message(request, user_profile, topic_name, content, info["status"]) return json_success(request) diff --git a/zerver/webhooks/opbeat/tests.py b/zerver/webhooks/opbeat/tests.py index 2d12efbd3f..588a713ee9 100644 --- a/zerver/webhooks/opbeat/tests.py +++ b/zerver/webhooks/opbeat/tests.py @@ -9,7 +9,7 @@ class OpbeatHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "opbeat" def test_comment(self) -> None: - expected_topic = "foo commented on E#2" + expected_topic_name = "foo commented on E#2" expected_message = """\ **[foo commented on E#2](https://opbeat.com/foo/test-flask-app/errors/2/#activity-5df00003ea4e42458db48446692f6d37)** test comment @@ -21,11 +21,11 @@ test comment >in app.py >A warning occurred (42 apples)""" self.check_webhook( - "new_comment", expected_topic, expected_message, content_type="application/json" + "new_comment", expected_topic_name, expected_message, content_type="application/json" ) def test_new_app(self) -> None: - expected_topic = "foo" + expected_topic_name = "foo" expected_message = """\ **foo** App foo created @@ -34,7 +34,7 @@ App foo created >language: nodejs >framework: custom""" self.check_webhook( - "new_app", expected_topic, expected_message, content_type="application/json" + "new_app", expected_topic_name, expected_message, content_type="application/json" ) def test_get_empty_value(self) -> None: @@ -42,19 +42,19 @@ App foo created self.assertEqual(get_value(test_dictionary, "foo"), "") def test_no_subject_type(self) -> None: - expected_topic = "test title" + expected_topic_name = "test title" expected_message = """\ **test title** test summary""" self.check_webhook( "unsupported_object", - expected_topic, + expected_topic_name, expected_message, content_type="application/json", ) def test_error_fixed(self) -> None: - expected_topic = "foo marked E#2 as fixed" + expected_topic_name = "foo marked E#2 as fixed" expected_message = """\ **[foo marked E#2 as fixed](https://opbeat.com/test_org/test-flask-app/errors/2/#activity-bf991a45d9184b0ca6fb3d48d3db4c38)** foo marked the error group as fixed @@ -65,11 +65,11 @@ foo marked the error group as fixed >in app.py >A warning occurred (42 apples)""" self.check_webhook( - "error_fixed", expected_topic, expected_message, content_type="application/json" + "error_fixed", expected_topic_name, expected_message, content_type="application/json" ) def test_error_reopened(self) -> None: - expected_topic = "foo reopened E#2" + expected_topic_name = "foo reopened E#2" expected_message = """\ **[foo reopened E#2](https://opbeat.com/test_org/test-flask-app/errors/2/#activity-38a556dfc0b04a59a586359bbce1463d)** foo reopened the error group @@ -80,11 +80,11 @@ foo reopened the error group >in app.py >A warning occurred (42 apples)""" self.check_webhook( - "error_reopen", expected_topic, expected_message, content_type="application/json" + "error_reopen", expected_topic_name, expected_message, content_type="application/json" ) def test_error_regressed(self) -> None: - expected_topic = "E#2 regressed" + expected_topic_name = "E#2 regressed" expected_message = """\ **[E#2 regressed](https://opbeat.com/test_org/test-flask-app/errors/2/#activity-c0396f38323a4fa7b314f87d5ed9cdd2)** The error group regressed @@ -95,5 +95,5 @@ The error group regressed >in app.py >A warning occurred (42 apples)""" self.check_webhook( - "new_error", expected_topic, expected_message, content_type="application/json" + "new_error", expected_topic_name, expected_message, content_type="application/json" ) diff --git a/zerver/webhooks/opbeat/view.py b/zerver/webhooks/opbeat/view.py index 30dfcb0993..6110ade934 100644 --- a/zerver/webhooks/opbeat/view.py +++ b/zerver/webhooks/opbeat/view.py @@ -114,9 +114,9 @@ def api_opbeat_webhook( details about the object mentioned. """ - topic = payload["title"].tame(check_string) + topic_name = payload["title"].tame(check_string) message = format_object(payload, "base", "") - check_send_webhook_message(request, user_profile, topic, message) + check_send_webhook_message(request, user_profile, topic_name, message) return json_success(request) diff --git a/zerver/webhooks/opencollective/tests.py b/zerver/webhooks/opencollective/tests.py index 5bd9511741..63a6b7c900 100644 --- a/zerver/webhooks/opencollective/tests.py +++ b/zerver/webhooks/opencollective/tests.py @@ -8,24 +8,24 @@ class OpenCollectiveHookTests(WebhookTestCase): # Note: Include a test function per each distinct message condition your integration supports def test_one_time_donation(self) -> None: # test one time donation - expected_topic = "New Member" + expected_topic_name = "New Member" expected_message = "@_**Λευτέρης Κυριαζάνος** donated **€1.00**! :tada:" self.check_webhook( "one_time_donation", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_one_time_incognito_donation(self) -> None: # test one time incognito donation - expected_topic = "New Member" + expected_topic_name = "New Member" expected_message = "An **Incognito** member donated **$1.00**! :tada:" # use fixture named helloworld_hello self.check_webhook( "one_time_incognito_donation", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/opencollective/view.py b/zerver/webhooks/opencollective/view.py index 85a1593b41..aec6c628f4 100644 --- a/zerver/webhooks/opencollective/view.py +++ b/zerver/webhooks/opencollective/view.py @@ -30,10 +30,10 @@ def api_opencollective_webhook( else: # non-Incognito donation body = f"@_**{name}** donated **{amount}**! :tada:" - topic = "New Member" + topic_name = "New Member" # send the message - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/opsgenie/tests.py b/zerver/webhooks/opsgenie/tests.py index ed54b9da94..c0554633aa 100644 --- a/zerver/webhooks/opsgenie/tests.py +++ b/zerver/webhooks/opsgenie/tests.py @@ -7,7 +7,7 @@ class OpsgenieHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "opsgenie" def test_acknowledge_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: Acknowledge @@ -17,13 +17,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "acknowledge", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_addnote_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: AddNote @@ -34,13 +34,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "addnote", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_addrecipient_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: AddRecipient @@ -51,13 +51,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "addrecipient", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_addtags_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: AddTags @@ -68,13 +68,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "addtags", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_addteam_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: AddTeam @@ -85,13 +85,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "addteam", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_assignownership_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: AssignOwnership @@ -102,13 +102,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "assignownership", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_close_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: Close @@ -117,13 +117,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "close", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_create_alert(self) -> None: - expected_topic = "Webhook" + expected_topic_name = "Webhook" expected_message = """ [Opsgenie alert for Webhook](https://app.opsgenie.com/alert/V2#/show/ec03dad6-62c8-4c94-b38b-d88f398e900f): * **Type**: Create @@ -133,13 +133,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "create", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customaction_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: TestAction @@ -149,13 +149,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "customaction", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_delete_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: Delete @@ -164,13 +164,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "delete", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_escalate_alert(self) -> None: - expected_topic = "Webhook_Test" + expected_topic_name = "Webhook_Test" expected_message = """ [Opsgenie alert for Webhook_Test](https://app.opsgenie.com/alert/V2#/show/7ba97e3a-d328-4b5e-8f9a-39e945a3869a): * **Type**: Escalate @@ -179,13 +179,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "escalate", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_removetags_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: RemoveTags @@ -196,13 +196,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "removetags", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_takeownership_alert(self) -> None: - expected_topic = "Webhook" + expected_topic_name = "Webhook" expected_message = """ [Opsgenie alert for Webhook](https://app.opsgenie.com/alert/V2#/show/8a745a79-3ed3-4044-8427-98e067c0623c): * **Type**: TakeOwnership @@ -212,13 +212,13 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "takeownership", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_unacknowledge_alert(self) -> None: - expected_topic = "Integration1" + expected_topic_name = "Integration1" expected_message = """ [Opsgenie alert for Integration1](https://app.opsgenie.com/alert/V2#/show/052652ac-5d1c-464a-812a-7dd18bbfba8c): * **Type**: UnAcknowledge @@ -228,7 +228,7 @@ class OpsgenieHookTests(WebhookTestCase): self.check_webhook( "unacknowledge", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/opsgenie/view.py b/zerver/webhooks/opsgenie/view.py index b8efe1e9cb..48c43fe4fb 100644 --- a/zerver/webhooks/opsgenie/view.py +++ b/zerver/webhooks/opsgenie/view.py @@ -44,7 +44,7 @@ def api_opsgenie_webhook( ), } - topic = info["integration_name"] + topic_name = info["integration_name"] bullet_template = "* **{key}**: {value}\n" if "note" in payload["alert"]: @@ -100,6 +100,6 @@ def api_opsgenie_webhook( """.strip() body = body_template.format(**info) - check_send_webhook_message(request, user_profile, topic, body, info["alert_type"]) + check_send_webhook_message(request, user_profile, topic_name, body, info["alert_type"]) return json_success(request) diff --git a/zerver/webhooks/pagerduty/view.py b/zerver/webhooks/pagerduty/view.py index f93a0daabc..4592996070 100644 --- a/zerver/webhooks/pagerduty/view.py +++ b/zerver/webhooks/pagerduty/view.py @@ -224,10 +224,10 @@ def send_formatted_pagerduty( else: template = INCIDENT_WITH_ASSIGNEE - topic = "Incident {incident_num_title}".format(**format_dict) + topic_name = "Incident {incident_num_title}".format(**format_dict) body = template.format(**format_dict) assert isinstance(format_dict["action"], str) - check_send_webhook_message(request, user_profile, topic, body, format_dict["action"]) + check_send_webhook_message(request, user_profile, topic_name, body, format_dict["action"]) @webhook_view("PagerDuty", all_event_types=ALL_EVENT_TYPES) diff --git a/zerver/webhooks/papertrail/tests.py b/zerver/webhooks/papertrail/tests.py index 1862d14257..7053d1dcd9 100644 --- a/zerver/webhooks/papertrail/tests.py +++ b/zerver/webhooks/papertrail/tests.py @@ -11,7 +11,7 @@ class PapertrailHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "papertrail" def test_short_message(self) -> None: - expected_topic = "logs" + expected_topic_name = "logs" expected_message = """ [Search for "Important stuff"](https://papertrailapp.com/searches/42) found **2** matches: @@ -27,7 +27,7 @@ A short event self.check_webhook( "short_post", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/papertrail/view.py b/zerver/webhooks/papertrail/view.py index 2ceac96b76..5f184ba306 100644 --- a/zerver/webhooks/papertrail/view.py +++ b/zerver/webhooks/papertrail/view.py @@ -56,7 +56,7 @@ def api_papertrail_webhook( break post = "\n".join(message) - topic = "logs" + topic_name = "logs" - check_send_webhook_message(request, user_profile, topic, post) + check_send_webhook_message(request, user_profile, topic_name, post) return json_success(request) diff --git a/zerver/webhooks/pingdom/view.py b/zerver/webhooks/pingdom/view.py index c8ae719b22..370658acdc 100644 --- a/zerver/webhooks/pingdom/view.py +++ b/zerver/webhooks/pingdom/view.py @@ -49,12 +49,12 @@ def api_pingdom_webhook( check_type = get_check_type(payload) if check_type in SUPPORTED_CHECK_TYPES: - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) body = get_body_for_http_request(payload) else: raise UnsupportedWebhookEventTypeError(check_type) - check_send_webhook_message(request, user_profile, topic, body, check_type) + check_send_webhook_message(request, user_profile, topic_name, body, check_type) return json_success(request) diff --git a/zerver/webhooks/pivotal/tests.py b/zerver/webhooks/pivotal/tests.py index 22622c9235..3356e5b2c8 100644 --- a/zerver/webhooks/pivotal/tests.py +++ b/zerver/webhooks/pivotal/tests.py @@ -14,93 +14,96 @@ class PivotalV3HookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "pivotal" def test_accepted(self) -> None: - expected_topic = "My new Feature story" + expected_topic_name = "My new Feature story" expected_message = 'Leo Franchi accepted "My new Feature story" \ [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573).' self.check_webhook( - "accepted", expected_topic, expected_message, content_type="application/xml" + "accepted", expected_topic_name, expected_message, content_type="application/xml" ) def test_bad_subject(self) -> None: - expected_topic = "Story changed" + expected_topic_name = "Story changed" expected_message = "Leo Franchi accepted My new Feature story \ [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573)." self.check_webhook( - "bad_accepted", expected_topic, expected_message, content_type="application/xml" + "bad_accepted", expected_topic_name, expected_message, content_type="application/xml" ) def test_commented(self) -> None: - expected_topic = "Comment added" + expected_topic_name = "Comment added" expected_message = 'Leo Franchi added comment: "FIX THIS NOW" \ [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573).' self.check_webhook( - "commented", expected_topic, expected_message, content_type="application/xml" + "commented", expected_topic_name, expected_message, content_type="application/xml" ) def test_created(self) -> None: - expected_topic = "My new Feature story" + expected_topic_name = "My new Feature story" expected_message = 'Leo Franchi added "My new Feature story" \ (unscheduled feature):\n\n~~~ quote\nThis is my long description\n~~~\n\n \ [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573).' self.check_webhook( - "created", expected_topic, expected_message, content_type="application/xml" + "created", expected_topic_name, expected_message, content_type="application/xml" ) def test_delivered(self) -> None: - expected_topic = "Another new story" + expected_topic_name = "Another new story" expected_message = 'Leo Franchi delivered "Another new story" \ [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48278289).' self.check_webhook( - "delivered", expected_topic, expected_message, content_type="application/xml" + "delivered", expected_topic_name, expected_message, content_type="application/xml" ) def test_finished(self) -> None: - expected_topic = "Another new story" + expected_topic_name = "Another new story" expected_message = 'Leo Franchi finished "Another new story" \ [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48278289).' self.check_webhook( - "finished", expected_topic, expected_message, content_type="application/xml" + "finished", expected_topic_name, expected_message, content_type="application/xml" ) def test_moved(self) -> None: - expected_topic = "My new Feature story" + expected_topic_name = "My new Feature story" expected_message = 'Leo Franchi edited "My new Feature story" \ [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573).' self.check_webhook( - "moved", expected_topic, expected_message, content_type="application/xml" + "moved", expected_topic_name, expected_message, content_type="application/xml" ) def test_rejected(self) -> None: - expected_topic = "Another new story" + expected_topic_name = "Another new story" expected_message = 'Leo Franchi rejected "Another new story" with comments: \ "Not good enough, sorry" [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48278289).' self.check_webhook( - "rejected", expected_topic, expected_message, content_type="application/xml" + "rejected", expected_topic_name, expected_message, content_type="application/xml" ) def test_started(self) -> None: - expected_topic = "Another new story" + expected_topic_name = "Another new story" expected_message = 'Leo Franchi started "Another new story" \ [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48278289).' self.check_webhook( - "started", expected_topic, expected_message, content_type="application/xml" + "started", expected_topic_name, expected_message, content_type="application/xml" ) def test_created_estimate(self) -> None: - expected_topic = "Another new story" + expected_topic_name = "Another new story" expected_message = 'Leo Franchi added "Another new story" \ (unscheduled feature worth 2 story points):\n\n~~~ quote\nSome loong description\n~~~\n\n \ [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48278289).' self.check_webhook( - "created_estimate", expected_topic, expected_message, content_type="application/xml" + "created_estimate", + expected_topic_name, + expected_message, + content_type="application/xml", ) def test_type_changed(self) -> None: - expected_topic = "My new Feature story" + expected_topic_name = "My new Feature story" expected_message = 'Leo Franchi edited "My new Feature story" \ [(view)](https://www.pivotaltracker.com/s/projects/807213/stories/48276573).' self.check_webhook( - "type_changed", expected_topic, expected_message, content_type="application/xml" + "type_changed", expected_topic_name, expected_message, content_type="application/xml" ) @override @@ -114,59 +117,59 @@ class PivotalV5HookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "pivotal" def test_accepted(self) -> None: - expected_topic = "#63486316: Story of the Year" + expected_topic_name = "#63486316: Story of the Year" expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316): * state changed from **unstarted** to **accepted**""" self.check_webhook( - "accepted", expected_topic, expected_message, content_type="application/xml" + "accepted", expected_topic_name, expected_message, content_type="application/xml" ) def test_commented(self) -> None: - expected_topic = "#63486316: Story of the Year" + expected_topic_name = "#63486316: Story of the Year" expected_message = """Leo Franchi added a comment to [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316): ~~~quote A comment on the story ~~~""" self.check_webhook( - "commented", expected_topic, expected_message, content_type="application/xml" + "commented", expected_topic_name, expected_message, content_type="application/xml" ) def test_created(self) -> None: - expected_topic = "#63495662: Story that I created" + expected_topic_name = "#63495662: Story that I created" expected_message = """Leo Franchi created bug: [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story that I created](http://www.pivotaltracker.com/story/show/63495662) * State is **unscheduled** * Description is > What a description""" self.check_webhook( - "created", expected_topic, expected_message, content_type="application/xml" + "created", expected_topic_name, expected_message, content_type="application/xml" ) def test_delivered(self) -> None: - expected_topic = "#63486316: Story of the Year" + expected_topic_name = "#63486316: Story of the Year" expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316): * state changed from **accepted** to **delivered**""" self.check_webhook( - "delivered", expected_topic, expected_message, content_type="application/xml" + "delivered", expected_topic_name, expected_message, content_type="application/xml" ) def test_finished(self) -> None: - expected_topic = "#63486316: Story of the Year" + expected_topic_name = "#63486316: Story of the Year" expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316): * state changed from **delivered** to **accepted**""" self.check_webhook( - "finished", expected_topic, expected_message, content_type="application/xml" + "finished", expected_topic_name, expected_message, content_type="application/xml" ) def test_moved(self) -> None: - expected_topic = "#63496066: Pivotal Test" + expected_topic_name = "#63496066: Pivotal Test" expected_message = """Leo Franchi moved [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Pivotal Test](http://www.pivotaltracker.com/story/show/63496066) from **unstarted** to **unscheduled**.""" self.check_webhook( - "moved", expected_topic, expected_message, content_type="application/xml" + "moved", expected_topic_name, expected_message, content_type="application/xml" ) def test_rejected(self) -> None: - expected_topic = "#63486316: Story of the Year" + expected_topic_name = "#63486316: Story of the Year" expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Story of the Year](http://www.pivotaltracker.com/story/show/63486316): * Comment added: ~~~quote @@ -174,32 +177,35 @@ Try again next time ~~~ * state changed from **delivered** to **rejected**""" self.check_webhook( - "rejected", expected_topic, expected_message, content_type="application/xml" + "rejected", expected_topic_name, expected_message, content_type="application/xml" ) def test_started(self) -> None: - expected_topic = "#63495972: Fresh Story" + expected_topic_name = "#63495972: Fresh Story" expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Fresh Story](http://www.pivotaltracker.com/story/show/63495972): * state changed from **unstarted** to **started**""" self.check_webhook( - "started", expected_topic, expected_message, content_type="application/xml" + "started", expected_topic_name, expected_message, content_type="application/xml" ) def test_created_estimate(self) -> None: - expected_topic = "#63496066: Pivotal Test" + expected_topic_name = "#63496066: Pivotal Test" expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Pivotal Test](http://www.pivotaltracker.com/story/show/63496066): * estimate is now **3 points**""" self.check_webhook( - "created_estimate", expected_topic, expected_message, content_type="application/xml" + "created_estimate", + expected_topic_name, + expected_message, + content_type="application/xml", ) def test_type_changed(self) -> None: - expected_topic = "#63496066: Pivotal Test" + expected_topic_name = "#63496066: Pivotal Test" expected_message = """Leo Franchi updated [Hard Code](https://www.pivotaltracker.com/s/projects/807213): [Pivotal Test](http://www.pivotaltracker.com/story/show/63496066): * estimate changed from 3 to **0 points** * type changed from **feature** to **bug**""" self.check_webhook( - "type_changed", expected_topic, expected_message, content_type="application/xml" + "type_changed", expected_topic_name, expected_message, content_type="application/xml" ) def test_bad_payload(self) -> None: diff --git a/zerver/webhooks/pivotal/view.py b/zerver/webhooks/pivotal/view.py index 8ef729a82d..051d4cac50 100644 --- a/zerver/webhooks/pivotal/view.py +++ b/zerver/webhooks/pivotal/view.py @@ -46,10 +46,10 @@ def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> T more_info = f" [(view)]({url})." if event_type == "story_update": - topic = name + topic_name = name content = description + more_info elif event_type == "note_create": - topic = "Comment added" + topic_name = "Comment added" content = description + more_info elif event_type == "story_create": issue_desc = get_text(["stories", "story", "description"]) @@ -58,9 +58,9 @@ def api_pivotal_webhook_v3(request: HttpRequest, user_profile: UserProfile) -> T estimate = get_text(["stories", "story", "estimate"]) if estimate != "": estimate = f" worth {estimate} story points" - topic = name + topic_name = name content = f"{description} ({issue_status} {issue_type}{estimate}):\n\n~~~ quote\n{issue_desc}\n~~~\n\n{more_info}" - return topic, content, f"{event_type}_v3" + return topic_name, content, f"{event_type}_v3" UNSUPPORTED_EVENT_TYPES = [ @@ -107,7 +107,7 @@ def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> T changes = payload.get("changes", []) content = "" - topic = f"#{story_id}: {story_name}" + topic_name = f"#{story_id}: {story_name}" def extract_comment(change: Dict[str, Any]) -> Optional[str]: if change.get("kind") == "comment": @@ -172,21 +172,21 @@ def api_pivotal_webhook_v5(request: HttpRequest, user_profile: UserProfile) -> T else: raise UnsupportedWebhookEventTypeError(event_type) - return topic, content, f"{event_type}_v5" + return topic_name, content, f"{event_type}_v5" @webhook_view("Pivotal", all_event_types=ALL_EVENT_TYPES) @has_request_variables def api_pivotal_webhook(request: HttpRequest, user_profile: UserProfile) -> HttpResponse: - topic = content = None + topic_name = content = None try: - topic, content, event_type = api_pivotal_webhook_v3(request, user_profile) + topic_name, content, event_type = api_pivotal_webhook_v3(request, user_profile) except Exception: # Attempt to parse v5 JSON payload - topic, content, event_type = api_pivotal_webhook_v5(request, user_profile) + topic_name, content, event_type = api_pivotal_webhook_v5(request, user_profile) if not content: raise JsonableError(_("Unable to handle Pivotal payload")) - check_send_webhook_message(request, user_profile, topic, content, event_type) + check_send_webhook_message(request, user_profile, topic_name, content, event_type) return json_success(request) diff --git a/zerver/webhooks/radarr/tests.py b/zerver/webhooks/radarr/tests.py index 680d189daf..402bef73e5 100644 --- a/zerver/webhooks/radarr/tests.py +++ b/zerver/webhooks/radarr/tests.py @@ -10,88 +10,88 @@ class RadarrHookTests(WebhookTestCase): """ Tests if radarr test payload is handled correctly """ - expected_topic = "Radarr - Test" + expected_topic_name = "Radarr - Test" expected_message = "Radarr webhook has been successfully configured." - self.check_webhook("radarr_test", expected_topic, expected_message) + self.check_webhook("radarr_test", expected_topic_name, expected_message) def test_radarr_application_update(self) -> None: """ Tests if radarr application update payload is handled correctly """ - expected_topic = "Radarr - Application update" + expected_topic_name = "Radarr - Application update" expected_message = "Radarr was updated from 4.2.0.6370 to 4.2.0.6372." - self.check_webhook("radarr_application_update", expected_topic, expected_message) + self.check_webhook("radarr_application_update", expected_topic_name, expected_message) def test_radarr_health_check_warning(self) -> None: """ Tests if radarr health check warning payload is handled correctly """ - expected_topic = "Health warning" + expected_topic_name = "Health warning" expected_message = "No download client is available." - self.check_webhook("radarr_health_check_warning", expected_topic, expected_message) + self.check_webhook("radarr_health_check_warning", expected_topic_name, expected_message) def test_radarr_health_check_error(self) -> None: """ Tests if radarr health check error payload is handled correctly """ - expected_topic = "Health error" + expected_topic_name = "Health error" expected_message = "Movie Gotham City Sirens (tmdbid 416649) was removed from TMDb." - self.check_webhook("radarr_health_check_error", expected_topic, expected_message) + self.check_webhook("radarr_health_check_error", expected_topic_name, expected_message) def test_radarr_movie_renamed(self) -> None: """ Tests if radarr movie renamed payload is handled correctly """ - expected_topic = "Marley & Me" + expected_topic_name = "Marley & Me" expected_message = "The movie Marley & Me has been renamed." - self.check_webhook("radarr_movie_renamed", expected_topic, expected_message) + self.check_webhook("radarr_movie_renamed", expected_topic_name, expected_message) def test_radarr_movie_imported(self) -> None: """ Tests if radarr movie imported payload is handled correctly """ - expected_topic = "Batman v Superman: Dawn of Justice" + expected_topic_name = "Batman v Superman: Dawn of Justice" expected_message = "The movie Batman v Superman: Dawn of Justice has been imported." - self.check_webhook("radarr_movie_imported", expected_topic, expected_message) + self.check_webhook("radarr_movie_imported", expected_topic_name, expected_message) def test_radarr_movie_imported_upgrade(self) -> None: """ Tests if radarr movie imported upgrade payload is handled correctly """ - expected_topic = "Greenland" + expected_topic_name = "Greenland" expected_message = "The movie Greenland has been upgraded from WEBRip-720p to WEBRip-1080p." - self.check_webhook("radarr_movie_imported_upgrade", expected_topic, expected_message) + self.check_webhook("radarr_movie_imported_upgrade", expected_topic_name, expected_message) def test_radarr_movie_grabbed(self) -> None: """ Tests if radarr movie grabbed payload is handled correctly """ - expected_topic = "Greenland" + expected_topic_name = "Greenland" expected_message = "The movie Greenland has been grabbed." - self.check_webhook("radarr_movie_grabbed", expected_topic, expected_message) + self.check_webhook("radarr_movie_grabbed", expected_topic_name, expected_message) def test_radarr_movie_deleted(self) -> None: """ Tests if radarr movie deleted payload is handled correctly """ - expected_topic = "Batman v Superman: Dawn of Justice" + expected_topic_name = "Batman v Superman: Dawn of Justice" expected_message = ( "The movie Batman v Superman: Dawn of Justice was deleted; its files were also deleted." ) - self.check_webhook("radarr_movie_deleted", expected_topic, expected_message) + self.check_webhook("radarr_movie_deleted", expected_topic_name, expected_message) def test_radarr_movie_file_deleted(self) -> None: """ Tests if radarr movie file deleted payload is handled correctly """ - expected_topic = "Marley & Me" + expected_topic_name = "Marley & Me" expected_message = "A file with quality Bluray-1080p for the movie Marley & Me was deleted, because it is missing from disk." - self.check_webhook("radarr_movie_file_deleted", expected_topic, expected_message) + self.check_webhook("radarr_movie_file_deleted", expected_topic_name, expected_message) def test_radarr_movie_added(self) -> None: """ Tests if radarr movie added payload is handled correctly """ - expected_topic = "Batman v Superman: Dawn of Justice" + expected_topic_name = "Batman v Superman: Dawn of Justice" expected_message = "The movie Batman v Superman: Dawn of Justice was added." - self.check_webhook("radarr_movie_added", expected_topic, expected_message) + self.check_webhook("radarr_movie_added", expected_topic_name, expected_message) diff --git a/zerver/webhooks/radarr/view.py b/zerver/webhooks/radarr/view.py index e971d86fd8..eac9f9f918 100644 --- a/zerver/webhooks/radarr/view.py +++ b/zerver/webhooks/radarr/view.py @@ -53,10 +53,10 @@ def api_radarr_webhook( payload: JsonBodyPayload[WildValue], ) -> HttpResponse: body = get_body_for_http_request(payload) - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) check_send_webhook_message( - request, user_profile, topic, body, payload["eventType"].tame(check_string) + request, user_profile, topic_name, body, payload["eventType"].tame(check_string) ) return json_success(request) diff --git a/zerver/webhooks/raygun/tests.py b/zerver/webhooks/raygun/tests.py index fcf2565803..a89a919de3 100644 --- a/zerver/webhooks/raygun/tests.py +++ b/zerver/webhooks/raygun/tests.py @@ -7,7 +7,7 @@ class RaygunHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "raygun" def test_status_changed_message(self) -> None: - expected_topic = "test" + expected_topic_name = "test" expected_message = """ [Error](https://app.raygun.com/error-url) status changed to **Ignored** by Emma Cat: * **Timestamp**: Wed Jan 28 01:49:36 1970 @@ -16,13 +16,13 @@ class RaygunHookTests(WebhookTestCase): self.check_webhook( "error_status_changed", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_comment_added_to_error_message(self) -> None: - expected_topic = "test" + expected_topic_name = "test" expected_message = """ Anita Peacock commented on [Error](https://app.raygun.com/error-url): @@ -35,13 +35,13 @@ Ignoring these errors self.check_webhook( "comment_added_to_error", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_error_assigned_to_user_message(self) -> None: - expected_topic = "test" + expected_topic_name = "test" expected_message = """ Amy Loondon assigned [Error](https://app.raygun.com/error-url) to Kyle Kenny: * **Timestamp**: Wed Jan 28 01:49:36 1970 @@ -50,13 +50,13 @@ Amy Loondon assigned [Error](https://app.raygun.com/error-url) to Kyle Kenny: self.check_webhook( "error_assigned_to_user", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_one_minute_followup_error_message(self) -> None: - expected_topic = "test" + expected_topic_name = "test" expected_message = """ One minute [follow-up error](http://app.raygun.io/error-url): * **First occurred**: Wed Jan 28 01:49:36 1970 @@ -67,13 +67,13 @@ One minute [follow-up error](http://app.raygun.io/error-url): self.check_webhook( "one_minute_followup_error", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_hourly_followup_error_message(self) -> None: - expected_topic = "test" + expected_topic_name = "test" expected_message = """ Hourly [follow-up error](http://app.raygun.io/error-url): * **First occurred**: Wed Jan 28 01:49:36 1970 @@ -84,13 +84,13 @@ Hourly [follow-up error](http://app.raygun.io/error-url): self.check_webhook( "hourly_followup_error", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_new_error_message(self) -> None: - expected_topic = "test" + expected_topic_name = "test" expected_message = """ New [Error](http://app.raygun.io/error-url) occurred: * **First occurred**: Wed Jan 28 01:49:36 1970 @@ -105,13 +105,13 @@ New [Error](http://app.raygun.io/error-url) occurred: self.check_webhook( "new_error", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_reoccurred_error_message(self) -> None: - expected_topic = "test" + expected_topic_name = "test" expected_message = """ [Error](http://app.raygun.io/error-url) reoccurred: * **First occurred**: Wed Jan 28 01:49:36 1970 @@ -126,7 +126,7 @@ New [Error](http://app.raygun.io/error-url) occurred: self.check_webhook( "reoccurred_error", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/raygun/view.py b/zerver/webhooks/raygun/view.py index 5808d42018..426fc37b67 100644 --- a/zerver/webhooks/raygun/view.py +++ b/zerver/webhooks/raygun/view.py @@ -39,9 +39,9 @@ def api_raygun_webhook( else: raise UnsupportedWebhookEventTypeError(event) - topic = "test" + topic_name = "test" - check_send_webhook_message(request, user_profile, topic, message, event) + check_send_webhook_message(request, user_profile, topic_name, message, event) return json_success(request) diff --git a/zerver/webhooks/reviewboard/tests.py b/zerver/webhooks/reviewboard/tests.py index e841b55bb5..07d43ea598 100644 --- a/zerver/webhooks/reviewboard/tests.py +++ b/zerver/webhooks/reviewboard/tests.py @@ -7,35 +7,35 @@ class ReviewBoardHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "reviewboard" def test_review_request_published(self) -> None: - expected_topic = "Scheduler" + expected_topic_name = "Scheduler" expected_message = "**eeshangarg** opened [#2: Initial commit](https://rbcommons.com/s/zulip/r/2/):\n\n``` quote\n**Description**: Initial commit\n**Status**: pending\n**Target people**: **drsbgarg**\n**Branch**: master\n```" - self.check_webhook("review_request_published", expected_topic, expected_message) + self.check_webhook("review_request_published", expected_topic_name, expected_message) def test_review_request_published_with_multiple_target_people(self) -> None: - expected_topic = "Scheduler" + expected_topic_name = "Scheduler" expected_message = "**eeshangarg** opened [#2: Initial commit](https://rbcommons.com/s/zulip/r/2/):\n\n``` quote\n**Description**: Initial commit\n**Status**: pending\n**Target people**: **drsbgarg**, **johndoe**, and **janedoe**\n**Branch**: master\n```" self.check_webhook( "review_request_published__with_multiple_target_people", - expected_topic, + expected_topic_name, expected_message, ) def test_review_request_reopened(self) -> None: - expected_topic = "Scheduler" + expected_topic_name = "Scheduler" expected_message = "**eeshangarg** reopened [#1: Initial commit (first iteration)](https://rbcommons.com/s/zulip/r/1/):\n\n``` quote\n**Description**: Initial commit (first iteration)\n**Status**: pending\n**Target people**: **drsbgarg**\n**Branch**: master\n```" - self.check_webhook("review_request_reopened", expected_topic, expected_message) + self.check_webhook("review_request_reopened", expected_topic_name, expected_message) def test_review_request_closed(self) -> None: - expected_topic = "Scheduler" + expected_topic_name = "Scheduler" expected_message = "**eeshangarg** closed [#1: Initial commit (first iteration)](https://rbcommons.com/s/zulip/r/1/):\n\n``` quote\n**Description**: Initial commit (first iteration)\n**Status**: submitted\n**Target people**: **drsbgarg**\n**Close type**: submitted\n**Branch**: master\n```" - self.check_webhook("review_request_closed", expected_topic, expected_message) + self.check_webhook("review_request_closed", expected_topic_name, expected_message) def test_review_published(self) -> None: - expected_topic = "Scheduler" + expected_topic_name = "Scheduler" expected_message = "**eeshangarg** [reviewed](https://rbcommons.com/s/zulip/r/1/#review651728) [#1: Initial commit (first iteration)](https://rbcommons.com/s/zulip/r/1/):\n\n**Review**:\n``` quote\nLeft some minor comments, thanks!\n```" - self.check_webhook("review_published", expected_topic, expected_message) + self.check_webhook("review_published", expected_topic_name, expected_message) def test_reply_published(self) -> None: - expected_topic = "Scheduler" + expected_topic_name = "Scheduler" expected_message = "**drsbgarg** [replied](https://rbcommons.com/s/zulip/api/review-requests/1/reviews/651728/replies/651732/) to [#1: Initial commit (first iteration)](https://rbcommons.com/s/zulip/api/review-requests/1/):\n\n**Reply**:\n``` quote\n\n```" - self.check_webhook("reply_published", expected_topic, expected_message) + self.check_webhook("reply_published", expected_topic_name, expected_message) diff --git a/zerver/webhooks/reviewboard/view.py b/zerver/webhooks/reviewboard/view.py index 9c09b46317..4d734e1779 100644 --- a/zerver/webhooks/reviewboard/view.py +++ b/zerver/webhooks/reviewboard/view.py @@ -191,8 +191,8 @@ def api_reviewboard_webhook( body_function = RB_MESSAGE_FUNCTIONS.get(event_type) if body_function is not None: body = body_function(payload) - topic = get_review_request_repo_title(payload) - check_send_webhook_message(request, user_profile, topic, body, event_type) + topic_name = get_review_request_repo_title(payload) + check_send_webhook_message(request, user_profile, topic_name, body, event_type) else: raise UnsupportedWebhookEventTypeError(event_type) diff --git a/zerver/webhooks/rhodecode/tests.py b/zerver/webhooks/rhodecode/tests.py index 7d77902ae3..4158474ab1 100644 --- a/zerver/webhooks/rhodecode/tests.py +++ b/zerver/webhooks/rhodecode/tests.py @@ -10,15 +10,15 @@ class RhodecodeHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "rhodecode" def test_push_event_message(self) -> None: - expected_topic = "u/yuroitaki/zulip-testing / master" + expected_topic_name = "u/yuroitaki/zulip-testing / master" expected_message = "yuroitaki pushed 1 commit to branch master. Commits by Yuro Itaki (1).\n\n* Modify README ([2b8c0ebf507](https://code.rhodecode.com/u/yuroitaki/zulip-testing/changeset/2b8c0ebf50710bc2e1cdb6a33071dd2435ad667c))" - self.check_webhook("push", expected_topic, expected_message) + self.check_webhook("push", expected_topic_name, expected_message) def test_push_event_message_filtered_by_branches(self) -> None: self.url = self.build_webhook_url(branches="master,dev") - expected_topic = "u/yuroitaki/zulip-testing / master" + expected_topic_name = "u/yuroitaki/zulip-testing / master" expected_message = "yuroitaki pushed 1 commit to branch master. Commits by Yuro Itaki (1).\n\n* Modify README ([2b8c0ebf507](https://code.rhodecode.com/u/yuroitaki/zulip-testing/changeset/2b8c0ebf50710bc2e1cdb6a33071dd2435ad667c))" - self.check_webhook("push", expected_topic, expected_message) + self.check_webhook("push", expected_topic_name, expected_message) @patch("zerver.lib.webhooks.common.check_send_webhook_message") def test_push_event_message_filtered_by_branches_ignore( @@ -31,30 +31,32 @@ class RhodecodeHookTests(WebhookTestCase): self.assert_json_success(result) def test_push_local_branch_without_commits(self) -> None: - expected_topic = "u/yuroitaki/zulip-testing / dev" + expected_topic_name = "u/yuroitaki/zulip-testing / dev" expected_message = "yuroitaki pushed the branch dev." - self.check_webhook("push__local_branch_without_commits", expected_topic, expected_message) + self.check_webhook( + "push__local_branch_without_commits", expected_topic_name, expected_message + ) def test_push_multiple_committers(self) -> None: - expected_topic = "u/yuroitaki/zulip-testing / master" + expected_topic_name = "u/yuroitaki/zulip-testing / master" expected_message = "yuroitaki pushed 2 commits to branch master. Commits by Itachi Sensei (1) and Yuro Itaki (1).\n\n* Add test.py ([b0d892e1cdd](https://code.rhodecode.com/u/yuroitaki/zulip-testing/changeset/b0d892e1cdd4236b1f74debca1772ea330ff5acd))\n* Modify test.py ([6dbae5f842f](https://code.rhodecode.com/u/yuroitaki/zulip-testing/changeset/6dbae5f842f80ccb05508a1de7aace9d0f327473))" - self.check_webhook("push__multiple_committers", expected_topic, expected_message) + self.check_webhook("push__multiple_committers", expected_topic_name, expected_message) def test_push_multiple_committers_with_others(self) -> None: - expected_topic = "u/yuroitaki/zulip-testing / master" + expected_topic_name = "u/yuroitaki/zulip-testing / master" commits_info = "* Modify test.py ([6dbae5f842f](https://code.rhodecode.com/u/yuroitaki/zulip-testing/changeset/6dbae5f842f80ccb05508a1de7aace9d0f327473))\n" expected_message = f"yuroitaki pushed 6 commits to branch master. Commits by Itachi Sensei (2), Yuro Itaki (2), Jonas Nielsen (1) and others (1).\n\n* Add test.py ([b0d892e1cdd](https://code.rhodecode.com/u/yuroitaki/zulip-testing/changeset/b0d892e1cdd4236b1f74debca1772ea330ff5acd))\n{commits_info * 4}* Add test.py ([b0d892e1cdd](https://code.rhodecode.com/u/yuroitaki/zulip-testing/changeset/b0d892e1cdd4236b1f74debca1772ea330ff5acd))" self.check_webhook( - "push__multiple_committers_with_others", expected_topic, expected_message + "push__multiple_committers_with_others", expected_topic_name, expected_message ) def test_push_commits_more_than_limit(self) -> None: - expected_topic = "u/yuroitaki/zulip-testing / master" + expected_topic_name = "u/yuroitaki/zulip-testing / master" commits_info = "* Modify README ([2b8c0ebf507](https://code.rhodecode.com/u/yuroitaki/zulip-testing/changeset/2b8c0ebf50710bc2e1cdb6a33071dd2435ad667c))\n" expected_message = f"yuroitaki pushed 50 commits to branch master. Commits by Yuro Itaki (50).\n\n{commits_info * COMMITS_LIMIT}[and {50 - COMMITS_LIMIT} more commit(s)]" - self.check_webhook("push__commits_more_than_limit", expected_topic, expected_message) + self.check_webhook("push__commits_more_than_limit", expected_topic_name, expected_message) def test_push_remove_branch(self) -> None: - expected_topic = "u/yuroitaki/zulip-testing / dev" + expected_topic_name = "u/yuroitaki/zulip-testing / dev" expected_message = "yuroitaki pushed 1 commit to branch dev. Commits by Yuro Itaki (1).\n\n* Deleted branch dev ([delete_bran](https://code.rhodecode.com/u/yuroitaki/zulip-testing/changeset/delete_branch=%3Edev))" - self.check_webhook("push__remove_branch", expected_topic, expected_message) + self.check_webhook("push__remove_branch", expected_topic_name, expected_message) diff --git a/zerver/webhooks/rhodecode/view.py b/zerver/webhooks/rhodecode/view.py index eef66d20ea..0670a365a2 100644 --- a/zerver/webhooks/rhodecode/view.py +++ b/zerver/webhooks/rhodecode/view.py @@ -88,10 +88,10 @@ def api_rhodecode_webhook( if event is None: return json_success(request) - topic = get_topic_based_on_event(payload, event) + topic_name = get_topic_based_on_event(payload, event) body_function = EVENT_FUNCTION_MAPPER[event] body = body_function(payload) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/rundeck/view.py b/zerver/webhooks/rundeck/view.py index 74072430c2..f7dc004312 100644 --- a/zerver/webhooks/rundeck/view.py +++ b/zerver/webhooks/rundeck/view.py @@ -19,10 +19,10 @@ def api_rundeck_webhook( *, payload: JsonBodyPayload[WildValue], ) -> HttpResponse: - topic = get_topic(payload) + topic_name = get_topic(payload) body = get_body(payload) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/semaphore/tests.py b/zerver/webhooks/semaphore/tests.py index 8609610784..c7744fe80e 100644 --- a/zerver/webhooks/semaphore/tests.py +++ b/zerver/webhooks/semaphore/tests.py @@ -16,7 +16,7 @@ class SemaphoreHookTests(WebhookTestCase): # Tests for Semaphore Classic def test_semaphore_build(self) -> None: - expected_topic = "knighthood/master" # repo/branch + expected_topic_name = "knighthood/master" # repo/branch expected_message = """ [Build 314](https://semaphoreci.com/donquixote/knighthood/branches/master/builds/314) passed: * **Commit**: [a490b8d508e: Create user account for Rocinante](https://github.com/donquixote/knighthood/commit/a490b8d508ebbdab1d77a5c2aefa35ceb2d62daf) @@ -24,13 +24,13 @@ class SemaphoreHookTests(WebhookTestCase): """.strip() self.check_webhook( "build", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_semaphore_deploy(self) -> None: - expected_topic = "knighthood/master" + expected_topic_name = "knighthood/master" expected_message = """ [Deploy 17](https://semaphoreci.com/donquixote/knighthood/servers/lamancha-271/deploys/17) of [build 314](https://semaphoreci.com/donquixote/knighthood/branches/master/builds/314) passed: * **Commit**: [a490b8d508e: Create user account for Rocinante](https://github.com/donquixote/knighthood/commit/a490b8d508ebbdab1d77a5c2aefa35ceb2d62daf) @@ -39,7 +39,7 @@ class SemaphoreHookTests(WebhookTestCase): """.strip() self.check_webhook( "deploy", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -47,7 +47,7 @@ class SemaphoreHookTests(WebhookTestCase): # Tests for Semaphore 2.0 def test_semaphore2_push(self) -> None: - expected_topic = "notifications/rw/webhook_impl" # repo/branch + expected_topic_name = "notifications/rw/webhook_impl" # repo/branch expected_message = """ [Notifications](https://semaphore.semaphoreci.com/workflows/acabe58e-4bcc-4d39-be06-e98d71917703) pipeline **stopped**: * **Commit**: [(2d9f5fcec1c)](https://github.com/renderedtext/notifications/commit/2d9f5fcec1ca7c68fa7bd44dd58ec4ff65814563) Implement webhooks for SemaphoreCI @@ -55,11 +55,11 @@ class SemaphoreHookTests(WebhookTestCase): * **Author**: [radwo](https://github.com/radwo) """.strip() self.check_webhook( - "push", expected_topic, expected_message, content_type="application/json" + "push", expected_topic_name, expected_message, content_type="application/json" ) def test_semaphore2_push_non_gh_repo(self) -> None: - expected_topic = "notifications/rw/webhook_impl" # repo/branch + expected_topic_name = "notifications/rw/webhook_impl" # repo/branch expected_message = """ [Notifications](https://semaphore.semaphoreci.com/workflows/acabe58e-4bcc-4d39-be06-e98d71917703) pipeline **stopped**: * **Commit**: (2d9f5fcec1c) Implement webhooks for SemaphoreCI @@ -68,11 +68,11 @@ class SemaphoreHookTests(WebhookTestCase): """.strip() with patch("zerver.webhooks.semaphore.view.is_github_repo", return_value=False): self.check_webhook( - "push", expected_topic, expected_message, content_type="application/json" + "push", expected_topic_name, expected_message, content_type="application/json" ) def test_semaphore_pull_request(self) -> None: - expected_topic = "notifications/test-notifications" + expected_topic_name = "notifications/test-notifications" expected_message = """ [Notifications](https://semaphore.semaphoreci.com/workflows/84383f37-d025-4811-b719-61c6acc92a1e) pipeline **failed**: * **Pull request**: [Testing PR notifications](https://github.com/renderedtext/notifications/pull/3) @@ -80,11 +80,11 @@ class SemaphoreHookTests(WebhookTestCase): * **Author**: [radwo](https://github.com/radwo) """.strip() self.check_webhook( - "pull_request", expected_topic, expected_message, content_type="application/json" + "pull_request", expected_topic_name, expected_message, content_type="application/json" ) def test_semaphore_pull_request_non_gh_repo(self) -> None: - expected_topic = "notifications/test-notifications" + expected_topic_name = "notifications/test-notifications" expected_message = """ [Notifications](https://semaphore.semaphoreci.com/workflows/84383f37-d025-4811-b719-61c6acc92a1e) pipeline **failed**: * **Pull request**: Testing PR notifications (#3) @@ -93,20 +93,25 @@ class SemaphoreHookTests(WebhookTestCase): """.strip() with patch("zerver.webhooks.semaphore.view.is_github_repo", return_value=False): self.check_webhook( - "pull_request", expected_topic, expected_message, content_type="application/json" + "pull_request", + expected_topic_name, + expected_message, + content_type="application/json", ) def test_semaphore_tag(self) -> None: - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = """ [Notifications](https://semaphore.semaphoreci.com/workflows/a8704319-2422-4828-9b11-6b2afa3554e6) pipeline **stopped**: * **Tag**: [v1.0.1](https://github.com/renderedtext/notifications/tree/v1.0.1) * **Author**: [radwo](https://github.com/radwo) """.strip() - self.check_webhook("tag", expected_topic, expected_message, content_type="application/json") + self.check_webhook( + "tag", expected_topic_name, expected_message, content_type="application/json" + ) def test_semaphore_tag_non_gh_repo(self) -> None: - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = """ [Notifications](https://semaphore.semaphoreci.com/workflows/a8704319-2422-4828-9b11-6b2afa3554e6) pipeline **stopped**: * **Tag**: v1.0.1 @@ -114,21 +119,21 @@ class SemaphoreHookTests(WebhookTestCase): """.strip() with patch("zerver.webhooks.semaphore.view.is_github_repo", return_value=False): self.check_webhook( - "tag", expected_topic, expected_message, content_type="application/json" + "tag", expected_topic_name, expected_message, content_type="application/json" ) def test_semaphore_unknown(self) -> None: - expected_topic = "knighthood/master" + expected_topic_name = "knighthood/master" expected_message = "unknown: passed" self.check_webhook( "unknown", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_semaphore_unknown_event(self) -> None: - expected_topic = "notifications" + expected_topic_name = "notifications" expected_message = """ [Notifications](https://semaphore.semaphoreci.com/workflows/a8704319-2422-4828-9b11-6b2afa3554e6) pipeline **stopped** for unknown event """.strip() @@ -136,7 +141,7 @@ class SemaphoreHookTests(WebhookTestCase): "zerver.webhooks.semaphore.tests.SemaphoreHookTests.get_body", self.get_unknown_event ): self.check_webhook( - "tag", expected_topic, expected_message, content_type="application/json" + "tag", expected_topic_name, expected_message, content_type="application/json" ) def get_unknown_event(self, fixture_name: str) -> str: diff --git a/zerver/webhooks/semaphore/view.py b/zerver/webhooks/semaphore/view.py index b9f2ce7ea9..8312c58823 100644 --- a/zerver/webhooks/semaphore/view.py +++ b/zerver/webhooks/semaphore/view.py @@ -102,12 +102,12 @@ def api_semaphore_webhook( content, project_name, branch_name, event = ( semaphore_classic(payload) if "event" in payload else semaphore_2(payload) ) - topic = ( + topic_name = ( TOPIC_TEMPLATE.format(project=project_name, branch=branch_name) if branch_name else project_name ) - check_send_webhook_message(request, user_profile, topic, content, event) + check_send_webhook_message(request, user_profile, topic_name, content, event) return json_success(request) diff --git a/zerver/webhooks/sentry/tests.py b/zerver/webhooks/sentry/tests.py index 793306c047..95d832ed6b 100644 --- a/zerver/webhooks/sentry/tests.py +++ b/zerver/webhooks/sentry/tests.py @@ -7,7 +7,7 @@ class SentryHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "sentry" def test_event_for_exception_golang(self) -> None: - expected_topic = '*url.Error: Get "bad_url": unsupported protocol scheme ""' + expected_topic_name = '*url.Error: Get "bad_url": unsupported protocol scheme ""' expected_message = """\ **New exception:** [*url.Error: Get "bad_url": unsupported protocol scheme ""](https://sentry.io/organizations/hypro999-personal-organization/issues/1637164584/events/80777a9cc30e4d0eb8904333d5c298b0/) ```quote @@ -30,10 +30,10 @@ Traceback: defer resp.Body.Close() ```""" - self.check_webhook("event_for_exception_golang", expected_topic, expected_message) + self.check_webhook("event_for_exception_golang", expected_topic_name, expected_message) def test_event_for_exception_node(self) -> None: - expected_topic = "Error: Sample error from node." + expected_topic_name = "Error: Sample error from node." expected_message = """\ **New exception:** [Error: Sample error from node.](https://sentry.io/organizations/hypro999-personal-organization/issues/1638852747/events/f9cb0f2afff74a5aa92e766fb7ac3fe3/) ```quote @@ -56,10 +56,10 @@ Traceback: ```""" - self.check_webhook("event_for_exception_node", expected_topic, expected_message) + self.check_webhook("event_for_exception_node", expected_topic_name, expected_message) def test_event_for_exception_python(self) -> None: - expected_topic = "Exception: Custom exception!" + expected_topic_name = "Exception: Custom exception!" expected_message = """\ **New exception:** [Exception: Custom exception!](https://sentry.io/organizations/hypro999-personal-organization/issues/1635244907/events/599349254a1447a99774b5310711c1a8/) ```quote @@ -80,10 +80,10 @@ Traceback: sentry_sdk.capture_exception(e) ```""" - self.check_webhook("event_for_exception_python", expected_topic, expected_message) + self.check_webhook("event_for_exception_python", expected_topic_name, expected_message) def test_event_for_exception_rails(self) -> None: - expected_topic = "ZeroDivisionError: divided by 0" + expected_topic_name = "ZeroDivisionError: divided by 0" expected_message = """\ **New exception:** [ZeroDivisionError: divided by 0](https://sentry.io/organizations/nitk-46/issues/4213933362/events/49b528e13e45497ab9adc3173fd2ed34/) ```quote @@ -109,10 +109,10 @@ Traceback: end ```""" - self.check_webhook("event_for_exception_rails", expected_topic, expected_message) + self.check_webhook("event_for_exception_rails", expected_topic_name, expected_message) def test_event_for_exception_vue(self) -> None: - expected_topic = "TypeError: Cannot read properties of null (reading 'inser..." + expected_topic_name = "TypeError: Cannot read properties of null (reading 'inser..." expected_message = """\ **New exception:** [TypeError: Cannot read properties of null (reading 'insertBefore')](https://sentry.io/organizations/nitk-46/issues/4214010673/events/292f78454e774e62999506f759ad791d/) ```quote @@ -120,10 +120,10 @@ Traceback: **timestamp:** 2023-05-29 11:08:30 **filename:** /node_modules/.vite/deps/chunk-G4DFXOZZ.js ```""" - self.check_webhook("event_for_exception_vue", expected_topic, expected_message) + self.check_webhook("event_for_exception_vue", expected_topic_name, expected_message) def test_webhook_event_for_exception_python(self) -> None: - expected_topic = "ValueError: new sentry error." + expected_topic_name = "ValueError: new sentry error." expected_message = """\ **New exception:** [ValueError: new sentry error.](https://sentry.io/organizations/bar-foundation/issues/1972208801/events/c916dccfd58e41dcabaebef0091f0736/) ```quote @@ -143,10 +143,12 @@ Traceback: except Exception as e: sentry_sdk.capture_exception(e) ```""" - self.check_webhook("webhook_event_for_exception_python", expected_topic, expected_message) + self.check_webhook( + "webhook_event_for_exception_python", expected_topic_name, expected_message + ) def test_webhook_event_for_exception_javascript(self) -> None: - expected_topic = 'TypeError: can\'t access property "bar", x.foo is undefined' + expected_topic_name = 'TypeError: can\'t access property "bar", x.foo is undefined' expected_message = """\ **New exception:** [TypeError: can't access property "bar", x.foo is undefined](https://sentry.io/organizations/foo-bar-org/issues/1982047746/events/f3bf5fc4e354451db9e885a69b2a2b51/) ```quote @@ -155,11 +157,11 @@ Traceback: **filename:** None ```""" self.check_webhook( - "webhook_event_for_exception_javascript", expected_topic, expected_message + "webhook_event_for_exception_javascript", expected_topic_name, expected_message ) def test_event_for_exception_js(self) -> None: - expected_topic = "Error: Something external broke." + expected_topic_name = "Error: Something external broke." expected_message = """\ **New exception:** [Error: Something external broke.](https://sentry.io/organizations/hypro999-personal-organization/issues/1731239773/events/355c3b2a142046629dd410db2fdda003/) ```quote @@ -167,50 +169,50 @@ Traceback: **timestamp:** 2020-06-17 14:42:54 **filename:** /mnt/data/Documents/Stuff%20for%20Zulip/Repos/sentry/js/external.js ```""" - self.check_webhook("event_for_exception_js", expected_topic, expected_message) + self.check_webhook("event_for_exception_js", expected_topic_name, expected_message) def test_event_for_message_golang(self) -> None: - expected_topic = "A test message event from golang." + expected_topic_name = "A test message event from golang." expected_message = """\ **New message event:** [A test message event from golang.](https://sentry.io/organizations/hypro999-personal-organization/issues/1638844654/events/01ecb45633bc4f5ca940ada671124c8f/) ```quote **level:** info **timestamp:** 2020-04-30 06:14:13 ```""" - self.check_webhook("event_for_message_golang", expected_topic, expected_message) + self.check_webhook("event_for_message_golang", expected_topic_name, expected_message) def test_event_for_message_node(self) -> None: - expected_topic = "Test event from node." + expected_topic_name = "Test event from node." expected_message = """\ **New message event:** [Test event from node.](https://sentry.io/organizations/hypro999-personal-organization/issues/1638840427/events/6886bb1fe7ce4497b7836f6083d5fd34/) ```quote **level:** info **timestamp:** 2020-04-30 06:09:56 ```""" - self.check_webhook("event_for_message_node", expected_topic, expected_message) + self.check_webhook("event_for_message_node", expected_topic_name, expected_message) def test_event_for_message_python(self) -> None: - expected_topic = "A simple message-based issue." + expected_topic_name = "A simple message-based issue." expected_message = """\ **New message event:** [A simple message-based issue.](https://sentry.io/organizations/hypro999-personal-organization/issues/1635261062/events/8da63b42375e4d3b803c377fefb062f8/) ```quote **level:** info **timestamp:** 2020-04-28 14:05:04 ```""" - self.check_webhook("event_for_message_python", expected_topic, expected_message) + self.check_webhook("event_for_message_python", expected_topic_name, expected_message) def test_issue_assigned_to_individual(self) -> None: - expected_topic = "A test message event from golang." + expected_topic_name = "A test message event from golang." expected_message = """Issue **A test message event from golang.** has now been assigned to **Hemanth V. Alluri** by **Hemanth V. Alluri**.""" - self.check_webhook("issue_assigned_to_individual", expected_topic, expected_message) + self.check_webhook("issue_assigned_to_individual", expected_topic_name, expected_message) def test_issue_assigned_to_team(self) -> None: - expected_topic = "Exception: program has entered an invalid state." + expected_topic_name = "Exception: program has entered an invalid state." expected_message = """Issue **Exception: program has entered an invalid state.** has now been assigned to **team lone-wolf** by **Hemanth V. Alluri**.""" - self.check_webhook("issue_assigned_to_team", expected_topic, expected_message) + self.check_webhook("issue_assigned_to_team", expected_topic_name, expected_message) def test_issue_created_for_exception(self) -> None: - expected_topic = "Exception: Custom exception!" + expected_topic_name = "Exception: Custom exception!" expected_message = """\ **New issue created:** Exception: Custom exception! ```quote @@ -218,10 +220,10 @@ Traceback: **timestamp:** 2020-04-28 13:56:05 **assignee:** No one ```""" - self.check_webhook("issue_created_for_exception", expected_topic, expected_message) + self.check_webhook("issue_created_for_exception", expected_topic_name, expected_message) def test_issue_created_for_message(self) -> None: - expected_topic = "A simple message-based issue." + expected_topic_name = "A simple message-based issue." expected_message = """\ **New issue created:** A simple message-based issue. ```quote @@ -229,47 +231,47 @@ Traceback: **timestamp:** 2020-04-28 14:05:04 **assignee:** No one ```""" - self.check_webhook("issue_created_for_message", expected_topic, expected_message) + self.check_webhook("issue_created_for_message", expected_topic_name, expected_message) def test_issue_ignored(self) -> None: - expected_topic = "Exception: program has entered an invalid state." + expected_topic_name = "Exception: program has entered an invalid state." expected_message = """Issue **Exception: program has entered an invalid state.** was ignored by **Hemanth V. Alluri**.""" - self.check_webhook("issue_ignored", expected_topic, expected_message) + self.check_webhook("issue_ignored", expected_topic_name, expected_message) def test_issue_resolved(self) -> None: - expected_topic = "Exception: program has entered an invalid state." + expected_topic_name = "Exception: program has entered an invalid state." expected_message = """Issue **Exception: program has entered an invalid state.** was marked as resolved by **Hemanth V. Alluri**.""" - self.check_webhook("issue_resolved", expected_topic, expected_message) + self.check_webhook("issue_resolved", expected_topic_name, expected_message) def test_deprecated_exception_message(self) -> None: - expected_topic = "zulip" + expected_topic_name = "zulip" expected_message = """\ New [issue](https://sentry.io/zulip/zulip/issues/156699934/) (level: ERROR): ``` quote This is an example python exception ```""" - self.check_webhook("deprecated_exception_message", expected_topic, expected_message) + self.check_webhook("deprecated_exception_message", expected_topic_name, expected_message) def test_sample_event_through_alert(self) -> None: - expected_topic = "This is an example Python exception" + expected_topic_name = "This is an example Python exception" expected_message = """\ **New message event:** [This is an example Python exception](https://sentry.io/organizations/nitk-46/issues/4218258981/events/b6eff1a49b1f4132850b1238d968da70/) ```quote **level:** error **timestamp:** 2023-05-31 11:06:16 ```""" - self.check_webhook("sample_event_through_alert", expected_topic, expected_message) + self.check_webhook("sample_event_through_alert", expected_topic_name, expected_message) def test_sample_event_through_plugin(self) -> None: - expected_topic = "This is an example Python exception" + expected_topic_name = "This is an example Python exception" expected_message = """\ **New message event:** [This is an example Python exception](https://nitk-46.sentry.io/issues/4218258981/events/4dc4fc2858aa450eb658be9e5b8ad149/) ```quote **level:** error **timestamp:** 2023-07-09 20:41:24 ```""" - self.check_webhook("sample_event_through_plugin", expected_topic, expected_message) + self.check_webhook("sample_event_through_plugin", expected_topic_name, expected_message) def test_raven_sdk_python_event(self) -> None: payload = self.get_body("raven_sdk_python_event") diff --git a/zerver/webhooks/sentry/view.py b/zerver/webhooks/sentry/view.py index 3d5c3e4e28..453e309d79 100644 --- a/zerver/webhooks/sentry/view.py +++ b/zerver/webhooks/sentry/view.py @@ -104,7 +104,7 @@ def convert_lines_to_traceback_string(lines: Optional[List[str]]) -> str: def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]: """Handle either an exception type event or a message type event payload.""" - topic = event["title"] + topic_name = event["title"] platform_name = event["platform"] syntax_highlight_as = syntax_highlight_as_map.get(platform_name, "") if syntax_highlight_as == "": # nocoverage @@ -117,7 +117,7 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]: # though we don't accept events from the old Python SDK. raise UnsupportedWebhookEventTypeError("Raven SDK") context = { - "title": topic, + "title": topic_name, "level": event["level"], "web_link": event["web_url"], "datetime": event["datetime"].split(".")[0].replace("T", " "), @@ -164,11 +164,11 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]: ) body = EXCEPTION_EVENT_TEMPLATE_WITH_TRACEBACK.format(**context) - return (topic, body) + return (topic_name, body) context.update(filename=filename) # nocoverage body = EXCEPTION_EVENT_TEMPLATE.format(**context) # nocoverage - return (topic, body) # nocoverage + return (topic_name, body) # nocoverage elif "logentry" in event: # The event was triggered by a sentry.capture_message() call @@ -178,14 +178,14 @@ def handle_event_payload(event: Dict[str, Any]) -> Tuple[str, str]: else: raise UnsupportedWebhookEventTypeError("unknown-event type") - return (topic, body) + return (topic_name, body) def handle_issue_payload( action: str, issue: Dict[str, Any], actor: Dict[str, Any] ) -> Tuple[str, str]: """Handle either an issue type event.""" - topic = issue["title"] + topic_name = issue["title"] datetime = issue["lastSeen"].split(".")[0].replace("T", " ") if issue["assignedTo"]: @@ -198,7 +198,7 @@ def handle_issue_payload( if action == "created": context = { - "title": topic, + "title": topic_name, "level": issue["level"], "datetime": datetime, "assignee": assignee, @@ -207,14 +207,14 @@ def handle_issue_payload( elif action == "resolved": context = { - "title": topic, + "title": topic_name, "actor": actor["name"], } body = ISSUE_RESOLVED_MESSAGE_TEMPLATE.format(**context) elif action == "assigned": context = { - "title": topic, + "title": topic_name, "assignee": assignee, "actor": actor["name"], } @@ -222,7 +222,7 @@ def handle_issue_payload( elif action == "ignored": context = { - "title": topic, + "title": topic_name, "actor": actor["name"], } body = ISSUE_IGNORED_MESSAGE_TEMPLATE.format(**context) @@ -230,17 +230,17 @@ def handle_issue_payload( else: raise UnsupportedWebhookEventTypeError(f"{action} action") - return (topic, body) + return (topic_name, body) def handle_deprecated_payload(payload: Dict[str, Any]) -> Tuple[str, str]: - topic = "{}".format(payload.get("project_name")) + topic_name = "{}".format(payload.get("project_name")) body = DEPRECATED_EXCEPTION_MESSAGE_TEMPLATE.format( level=payload["level"].upper(), url=payload.get("url"), message=payload.get("message"), ) - return (topic, body) + return (topic_name, body) def transform_webhook_payload(payload: Dict[str, Any]) -> Optional[Dict[str, Any]]: @@ -282,13 +282,15 @@ def api_sentry_webhook( # We currently support two types of payloads: events and issues. if data: if "event" in data: - topic, body = handle_event_payload(data["event"]) + topic_name, body = handle_event_payload(data["event"]) elif "issue" in data: - topic, body = handle_issue_payload(payload["action"], data["issue"], payload["actor"]) + topic_name, body = handle_issue_payload( + payload["action"], data["issue"], payload["actor"] + ) else: raise UnsupportedWebhookEventTypeError(str(list(data.keys()))) else: - topic, body = handle_deprecated_payload(payload) + topic_name, body = handle_deprecated_payload(payload) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/slack/tests.py b/zerver/webhooks/slack/tests.py index 396f5db592..40b61de981 100644 --- a/zerver/webhooks/slack/tests.py +++ b/zerver/webhooks/slack/tests.py @@ -9,11 +9,11 @@ class SlackWebhookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "slack" def test_slack_channel_to_topic(self) -> None: - expected_topic = "channel: general" + expected_topic_name = "channel: general" expected_message = "**slack_user**: test" self.check_webhook( "message_info", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -21,11 +21,11 @@ class SlackWebhookTests(WebhookTestCase): def test_slack_channel_to_stream(self) -> None: self.STREAM_NAME = "general" self.url = "{}{}".format(self.url, "&channels_map_to_topics=0") - expected_topic = "Message from Slack" + expected_topic_name = "Message from Slack" expected_message = "**slack_user**: test" self.check_webhook( "message_info", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/slack/view.py b/zerver/webhooks/slack/view.py index da39daed62..4cf130d799 100644 --- a/zerver/webhooks/slack/view.py +++ b/zerver/webhooks/slack/view.py @@ -30,13 +30,13 @@ def api_slack_webhook( raise JsonableError(_("Error: channels_map_to_topics parameter other than 0 or 1")) if channels_map_to_topics == VALID_OPTIONS["SHOULD_BE_MAPPED"]: - topic = f"channel: {channel_name}" + topic_name = f"channel: {channel_name}" else: stream = channel_name - topic = _("Message from Slack") + topic_name = _("Message from Slack") content = ZULIP_MESSAGE_TEMPLATE.format(message_sender=user_name, text=text) client = RequestNotes.get_notes(request).client assert client is not None - check_send_stream_message(user_profile, client, stream, topic, content) + check_send_stream_message(user_profile, client, stream, topic_name, content) return json_success(request) diff --git a/zerver/webhooks/slack_incoming/tests.py b/zerver/webhooks/slack_incoming/tests.py index c6f7696060..9373f9d886 100644 --- a/zerver/webhooks/slack_incoming/tests.py +++ b/zerver/webhooks/slack_incoming/tests.py @@ -9,14 +9,14 @@ class SlackIncomingHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "slack_incoming" def test_message(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ Hello, world. """.strip() self.check_webhook( "text", - expected_topic, + expected_topic_name, expected_message, ) @@ -51,14 +51,14 @@ Hello, world. ) def test_message_as_www_urlencoded(self) -> None: - expected_topic = "devops" + expected_topic_name = "devops" expected_message = """ :zap: chris has started deploying project tag v0.0.2rc10 to staging """.strip() self.check_webhook( "urlencoded_text", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -69,7 +69,7 @@ Hello, world. self.assert_json_error(result, "Missing 'payload' argument") def test_message_with_actions(self) -> None: - expected_topic = "C1H9RESGL" + expected_topic_name = "C1H9RESGL" expected_message = """ Danny Torrence left the following *review* for your property: @@ -83,12 +83,12 @@ Danny Torrence left the following *review* for your property: self.check_webhook( "actions", - expected_topic, + expected_topic_name, expected_message, ) def test_message_with_blocks(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ Danny Torrence left the following review for your property: @@ -102,12 +102,12 @@ Danny Torrence left the following review for your property: self.check_webhook( "blocks", - expected_topic, + expected_topic_name, expected_message, ) def test_message_with_attachment(self) -> None: - expected_topic = "prometheus-alerts" + expected_topic_name = "prometheus-alerts" expected_message = """ ## [[FIRING:2] InstanceDown for api-server (env="prod", severity="critical")](https://alertmanager.local//#/alerts?receiver=default) @@ -133,7 +133,7 @@ Danny Torrence left the following review for your property: self.check_webhook( "attachment", - expected_topic, + expected_topic_name, expected_message, ) @@ -141,7 +141,7 @@ Danny Torrence left the following review for your property: # Paste the JSON into # https://api.slack.com/tools/block-kit-builder to see how it # is rendered in Slack - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ ## Hello from TaskBot @@ -169,14 +169,14 @@ There are two ways to quickly create tasks: self.check_webhook( "complicated", - expected_topic, + expected_topic_name, expected_message, ) def test_attachment_blocks(self) -> None: # On https://api.slack.com/tools/block-kit-builder choose # "Attachment preview" and paste the JSON in. - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ This is a section block with an accessory image. @@ -193,12 +193,12 @@ This is a section block with a button. self.check_webhook( "attachment_blocks", - expected_topic, + expected_topic_name, expected_message, ) def test_attachment_fields(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ Build bla bla succeeded @@ -213,12 +213,12 @@ Value without title self.check_webhook( "attachment_fields", - expected_topic, + expected_topic_name, expected_message, ) def test_attachment_pieces(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ ## Test @@ -229,7 +229,7 @@ Value without title self.check_webhook( "attachment_pieces", - expected_topic, + expected_topic_name, expected_message, ) @@ -242,7 +242,7 @@ Value without title return self.webhook_fixture_data("slack_incoming", fixture_name, file_type=file_type) def test_attachment_pieces_title_null(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ Sample pretext. @@ -257,12 +257,12 @@ Sample footer. self.check_webhook( "attachment_pieces_title_null", - expected_topic, + expected_topic_name, expected_message, ) def test_attachment_pieces_image_url_null(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ ## [Sample title.](https://www.google.com) @@ -277,12 +277,12 @@ Sample footer. self.check_webhook( "attachment_pieces_image_url_null", - expected_topic, + expected_topic_name, expected_message, ) def test_attachment_pieces_ts_null(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ ## [Sample title.](https://www.google.com) @@ -297,12 +297,12 @@ Sample footer. self.check_webhook( "attachment_pieces_ts_null", - expected_topic, + expected_topic_name, expected_message, ) def test_attachment_pieces_text_null(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ ## [Sample title.](https://www.google.com) @@ -317,12 +317,12 @@ Sample footer. self.check_webhook( "attachment_pieces_text_null", - expected_topic, + expected_topic_name, expected_message, ) def test_attachment_pieces_pretext_null(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ ## [Sample title.](https://www.google.com) @@ -337,12 +337,12 @@ Sample footer. self.check_webhook( "attachment_pieces_pretext_null", - expected_topic, + expected_topic_name, expected_message, ) def test_attachment_pieces_footer_null(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ ## [Sample title.](https://www.google.com) @@ -357,12 +357,12 @@ Sample text. self.check_webhook( "attachment_pieces_footer_null", - expected_topic, + expected_topic_name, expected_message, ) def test_attachment_pieces_title_link_null(self) -> None: - expected_topic = "(no topic)" + expected_topic_name = "(no topic)" expected_message = """ ## Sample title. @@ -379,7 +379,7 @@ Sample footer. self.check_webhook( "attachment_pieces_title_link_null", - expected_topic, + expected_topic_name, expected_message, ) diff --git a/zerver/webhooks/solano/tests.py b/zerver/webhooks/solano/tests.py index ffa2850686..4f3bbf3261 100644 --- a/zerver/webhooks/solano/tests.py +++ b/zerver/webhooks/solano/tests.py @@ -10,7 +10,7 @@ class SolanoHookTests(WebhookTestCase): """ Build notifications are generated by Solano Labs after build completes. """ - expected_topic = "build update" + expected_topic_name = "build update" expected_message = """ Build update (see [build log](https://ci.solanolabs.com:443/reports/3316175)): * **Author**: solano-ci[bot]@users.noreply.github.com @@ -20,7 +20,7 @@ Build update (see [build log](https://ci.solanolabs.com:443/reports/3316175)): self.check_webhook( "build_001", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -29,7 +29,7 @@ Build update (see [build log](https://ci.solanolabs.com:443/reports/3316175)): """ Build notifications are generated by Solano Labs after build completes. """ - expected_topic = "build update" + expected_topic_name = "build update" expected_message = """ Build update (see [build log](https://ci.solanolabs.com:443/reports/3316723)): * **Author**: Unknown @@ -39,7 +39,7 @@ Build update (see [build log](https://ci.solanolabs.com:443/reports/3316723)): self.check_webhook( "build_002", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -48,7 +48,7 @@ Build update (see [build log](https://ci.solanolabs.com:443/reports/3316723)): """ Build notifications are generated by Solano Labs after build completes. """ - expected_topic = "build update" + expected_topic_name = "build update" expected_message = """ Build update (see [build log](https://ci.solanolabs.com:443/reports/3317799)): * **Author**: solano-ci[bot]@users.noreply.github.com @@ -58,18 +58,18 @@ Build update (see [build log](https://ci.solanolabs.com:443/reports/3317799)): self.check_webhook( "received", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_solano_test_message(self) -> None: - expected_topic = "build update" + expected_topic_name = "build update" expected_message = "Solano webhook set up correctly." self.check_webhook( "test", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/solano/view.py b/zerver/webhooks/solano/view.py index a7be19e45b..65c9750bdf 100644 --- a/zerver/webhooks/solano/view.py +++ b/zerver/webhooks/solano/view.py @@ -29,9 +29,9 @@ def api_solano_webhook( payload: JsonBodyPayload[WildValue], ) -> HttpResponse: event = payload["event"].tame(check_string) - topic = "build update" + topic_name = "build update" if event == "test": - return handle_test_event(request, user_profile, topic) + return handle_test_event(request, user_profile, topic_name) try: author = payload["committers"][0].tame(check_string) except ValidationError: @@ -71,7 +71,7 @@ def api_solano_webhook( emoji=emoji, ) - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/sonarqube/tests.py b/zerver/webhooks/sonarqube/tests.py index 195b6b78a7..b6ec667554 100644 --- a/zerver/webhooks/sonarqube/tests.py +++ b/zerver/webhooks/sonarqube/tests.py @@ -7,7 +7,7 @@ class SonarqubeHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "sonarqube" def test_analysis_success(self) -> None: - expected_topic = "test-sonar / master" + expected_topic_name = "test-sonar / master" expected_message = """ Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis of branch master resulted in success. @@ -15,13 +15,13 @@ Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis of self.check_webhook( "success", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_analysis_error(self) -> None: - expected_topic = "test-sonar / master" + expected_topic_name = "test-sonar / master" expected_message = """ Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis of branch master resulted in error: @@ -31,13 +31,13 @@ Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis of self.check_webhook( "error", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_analysis_error_no_value(self) -> None: - expected_topic = "test-sonar / master" + expected_topic_name = "test-sonar / master" expected_message = """ Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis of branch master resulted in error: @@ -47,13 +47,13 @@ Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis of self.check_webhook( "error_no_value", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_analysis_success_no_branch(self) -> None: - expected_topic = "test-sonar" + expected_topic_name = "test-sonar" expected_message = """ Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis resulted in success. @@ -61,13 +61,13 @@ Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis res self.check_webhook( "success_no_branch", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_analysis_error_no_branch(self) -> None: - expected_topic = "test-sonar" + expected_topic_name = "test-sonar" expected_message = """ Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis resulted in error: @@ -77,7 +77,7 @@ Project [test-sonar](http://localhost:9000/dashboard?id=test-sonar) analysis res self.check_webhook( "error_no_branch", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/sonarqube/view.py b/zerver/webhooks/sonarqube/view.py index 3d42bfab8c..a6ab679c6d 100644 --- a/zerver/webhooks/sonarqube/view.py +++ b/zerver/webhooks/sonarqube/view.py @@ -121,10 +121,10 @@ def api_sonarqube_webhook( if "branch" in payload: branch = payload["branch"].get("name").tame(check_none_or(check_string)) if branch: - topic = TOPIC_WITH_BRANCH.format(project, branch) + topic_name = TOPIC_WITH_BRANCH.format(project, branch) message = render_body_with_branch(payload) else: - topic = project + topic_name = project message = render_body_without_branch(payload) - check_send_webhook_message(request, user_profile, topic, message) + check_send_webhook_message(request, user_profile, topic_name, message) return json_success(request) diff --git a/zerver/webhooks/sonarr/tests.py b/zerver/webhooks/sonarr/tests.py index 2dc3c8d8a9..0e000c77e7 100644 --- a/zerver/webhooks/sonarr/tests.py +++ b/zerver/webhooks/sonarr/tests.py @@ -10,80 +10,80 @@ class SonarrHookTests(WebhookTestCase): """ Tests if sonarr test payload is handled correctly """ - expected_topic = "Sonarr - Test" + expected_topic_name = "Sonarr - Test" expected_message = "Sonarr webhook has been successfully configured." - self.check_webhook("sonarr_test", expected_topic, expected_message) + self.check_webhook("sonarr_test", expected_topic_name, expected_message) def test_sonarr_series_deleted(self) -> None: """ Tests if sonarr series deleted payload is handled correctly """ - expected_topic = "Breaking Bad" + expected_topic_name = "Breaking Bad" expected_message = "Breaking Bad has been deleted." - self.check_webhook("sonarr_series_deleted", expected_topic, expected_message) + self.check_webhook("sonarr_series_deleted", expected_topic_name, expected_message) def test_sonarr_health_check_warning(self) -> None: """ Tests if sonarr health check warning payload is handled correctly """ - expected_topic = "Health warning" + expected_topic_name = "Health warning" expected_message = "Indexers unavailable due to failures for more than 6 hours: Academic Torrents - Jackett, ACG - Jackett, KickAssTorrent - Jackett, EXT Torrents - Jackett, Extra Torrents - Jackett, SkyTorrents - Jackett, iDope - Jackett." - self.check_webhook("sonarr_health_check_warning", expected_topic, expected_message) + self.check_webhook("sonarr_health_check_warning", expected_topic_name, expected_message) def test_sonarr_health_check_error(self) -> None: """ Tests if sonarr health check error payload is handled correctly """ - expected_topic = "Health error" + expected_topic_name = "Health error" expected_message = "No indexers available with RSS sync enabled, Sonarr will not grab new releases automatically." - self.check_webhook("sonarr_health_check_error", expected_topic, expected_message) + self.check_webhook("sonarr_health_check_error", expected_topic_name, expected_message) def test_sonarr_episodes_renamed(self) -> None: """ Tests if sonarr episodes renamed payload is handled correctly """ - expected_topic = "The L Word" + expected_topic_name = "The L Word" expected_message = "The L Word episodes have been renamed." - self.check_webhook("sonarr_episodes_renamed", expected_topic, expected_message) + self.check_webhook("sonarr_episodes_renamed", expected_topic_name, expected_message) def test_sonarr_episode_imported(self) -> None: """ Tests if sonarr episode imported payload is handled correctly """ - expected_topic = "Grey's Anatomy" + expected_topic_name = "Grey's Anatomy" expected_message = "Grey's Anatomy - 17x9 - In My Life has been imported." - self.check_webhook("sonarr_episode_imported", expected_topic, expected_message) + self.check_webhook("sonarr_episode_imported", expected_topic_name, expected_message) def test_sonarr_episode_imported_upgrade(self) -> None: """ Tests if sonarr episode imported upgrade payload is handled correctly """ - expected_topic = "NCIS" + expected_topic_name = "NCIS" expected_message = "NCIS - 18x10 - Watchdog has been upgraded from SDTV to HDTV-720p." - self.check_webhook("sonarr_episode_imported_upgrade", expected_topic, expected_message) + self.check_webhook("sonarr_episode_imported_upgrade", expected_topic_name, expected_message) def test_sonarr_episode_grabbed(self) -> None: """ Tests if sonarr episode grabbed payload is handled correctly """ - expected_topic = "NCIS" + expected_topic_name = "NCIS" expected_message = "NCIS - 18x10 - Watchdog has been grabbed." - self.check_webhook("sonarr_episode_grabbed", expected_topic, expected_message) + self.check_webhook("sonarr_episode_grabbed", expected_topic_name, expected_message) def test_sonarr_episode_deleted(self) -> None: """ Tests if sonarr episode deleted payload is handled correctly """ - expected_topic = "Breaking Bad" + expected_topic_name = "Breaking Bad" expected_message = "Breaking Bad - 1x1 - Pilot has been deleted." - self.check_webhook("sonarr_episode_deleted", expected_topic, expected_message) + self.check_webhook("sonarr_episode_deleted", expected_topic_name, expected_message) def test_sonarr_episode_deleted_upgrade(self) -> None: """ Tests if sonarr episode deleted upgrade payload is handled correctly """ - expected_topic = "S.W.A.T. (2017)" + expected_topic_name = "S.W.A.T. (2017)" expected_message = ( "S.W.A.T. (2017) - 4x10 - Buried has been deleted due to quality upgrade." ) - self.check_webhook("sonarr_episode_deleted_upgrade", expected_topic, expected_message) + self.check_webhook("sonarr_episode_deleted_upgrade", expected_topic_name, expected_message) diff --git a/zerver/webhooks/sonarr/view.py b/zerver/webhooks/sonarr/view.py index c740475397..4eb1b047fe 100644 --- a/zerver/webhooks/sonarr/view.py +++ b/zerver/webhooks/sonarr/view.py @@ -47,10 +47,10 @@ def api_sonarr_webhook( payload: JsonBodyPayload[WildValue], ) -> HttpResponse: body = get_body_for_http_request(payload) - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) check_send_webhook_message( - request, user_profile, topic, body, payload["eventType"].tame(check_string) + request, user_profile, topic_name, body, payload["eventType"].tame(check_string) ) return json_success(request) @@ -58,15 +58,17 @@ def api_sonarr_webhook( def get_topic_for_http_request(payload: WildValue) -> str: event_type = payload["eventType"].tame(check_string) if event_type == "Test": - topic = SONARR_TOPIC_TEMPLATE_TEST + topic_name = SONARR_TOPIC_TEMPLATE_TEST elif event_type == "Health": - topic = SONARR_TOPIC_TEMPLATE_HEALTH_CHECK.format(level=payload["level"].tame(check_string)) + topic_name = SONARR_TOPIC_TEMPLATE_HEALTH_CHECK.format( + level=payload["level"].tame(check_string) + ) else: - topic = SONARR_TOPIC_TEMPLATE.format( + topic_name = SONARR_TOPIC_TEMPLATE.format( series_title=payload["series"]["title"].tame(check_string) ) - return topic + return topic_name def get_body_for_health_check_event(payload: WildValue) -> str: diff --git a/zerver/webhooks/splunk/tests.py b/zerver/webhooks/splunk/tests.py index f7c1c88dca..c03f138bf4 100644 --- a/zerver/webhooks/splunk/tests.py +++ b/zerver/webhooks/splunk/tests.py @@ -10,7 +10,7 @@ class SplunkHookTests(WebhookTestCase): self.url = self.build_webhook_url(topic="New Search Alert") # define the expected message contents - expected_topic = "New Search Alert" + expected_topic_name = "New Search Alert" expected_message = """ Splunk alert from saved search: * **Search**: [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) @@ -22,14 +22,14 @@ Splunk alert from saved search: # using fixture named splunk_search_one_result, execute this test self.check_webhook( "search_one_result", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_splunk_short_search_name(self) -> None: # don't provide a topic so the search name is used instead - expected_topic = "This search's name isn't that long" + expected_topic_name = "This search's name isn't that long" expected_message = """ Splunk alert from saved search: * **Search**: [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) @@ -40,14 +40,14 @@ Splunk alert from saved search: self.check_webhook( "short_search_name", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_splunk_long_search_name(self) -> None: # don't provide a topic so the search name is used instead - expected_topic = "this-search's-got-47-words-37-sentences-58-words-we-wanna..." + expected_topic_name = "this-search's-got-47-words-37-sentences-58-words-we-wanna..." expected_message = """ Splunk alert from saved search: * **Search**: [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) @@ -58,7 +58,7 @@ Splunk alert from saved search: self.check_webhook( "long_search_name", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -66,7 +66,7 @@ Splunk alert from saved search: def test_splunk_missing_results_link(self) -> None: self.url = self.build_webhook_url(topic="New Search Alert") - expected_topic = "New Search Alert" + expected_topic_name = "New Search Alert" expected_message = """ Splunk alert from saved search: * **Search**: [sudo](Missing results_link) @@ -77,7 +77,7 @@ Splunk alert from saved search: self.check_webhook( "missing_results_link", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -85,7 +85,7 @@ Splunk alert from saved search: def test_splunk_missing_search_name(self) -> None: self.url = self.build_webhook_url(topic="New Search Alert") - expected_topic = "New Search Alert" + expected_topic_name = "New Search Alert" expected_message = """ Splunk alert from saved search: * **Search**: [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) @@ -96,7 +96,7 @@ Splunk alert from saved search: self.check_webhook( "missing_search_name", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -104,7 +104,7 @@ Splunk alert from saved search: def test_splunk_missing_host(self) -> None: self.url = self.build_webhook_url(topic="New Search Alert") - expected_topic = "New Search Alert" + expected_topic_name = "New Search Alert" expected_message = """ Splunk alert from saved search: * **Search**: [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) @@ -115,7 +115,7 @@ Splunk alert from saved search: self.check_webhook( "missing_host", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -123,7 +123,7 @@ Splunk alert from saved search: def test_splunk_missing_source(self) -> None: self.url = self.build_webhook_url(topic="New Search Alert") - expected_topic = "New Search Alert" + expected_topic_name = "New Search Alert" expected_message = """ Splunk alert from saved search: * **Search**: [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) @@ -134,7 +134,7 @@ Splunk alert from saved search: self.check_webhook( "missing_source", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) @@ -142,7 +142,7 @@ Splunk alert from saved search: def test_splunk_missing_raw(self) -> None: self.url = self.build_webhook_url(topic="New Search Alert") - expected_topic = "New Search Alert" + expected_topic_name = "New Search Alert" expected_message = """ Splunk alert from saved search: * **Search**: [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) @@ -153,7 +153,7 @@ Splunk alert from saved search: self.check_webhook( "missing_raw", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/splunk/view.py b/zerver/webhooks/splunk/view.py index afe61492aa..b83ed7fac5 100644 --- a/zerver/webhooks/splunk/view.py +++ b/zerver/webhooks/splunk/view.py @@ -35,9 +35,9 @@ def api_splunk_webhook( # for the default topic, use search name but truncate if too long if len(search_name) >= MAX_TOPIC_NAME_LENGTH: - topic = f"{search_name[:(MAX_TOPIC_NAME_LENGTH - 3)]}..." + topic_name = f"{search_name[:(MAX_TOPIC_NAME_LENGTH - 3)]}..." else: - topic = search_name + topic_name = search_name # construct the message body body = MESSAGE_TEMPLATE.format( @@ -49,6 +49,6 @@ def api_splunk_webhook( ) # send the message - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/statuspage/tests.py b/zerver/webhooks/statuspage/tests.py index 550a4dfd8d..4351ec585e 100644 --- a/zerver/webhooks/statuspage/tests.py +++ b/zerver/webhooks/statuspage/tests.py @@ -7,7 +7,7 @@ class StatuspageHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "statuspage" def test_statuspage_incident(self) -> None: - expected_topic = "Database query delays: All Systems Operational" + expected_topic_name = "Database query delays: All Systems Operational" expected_message = """ **Database query delays**: * State: **identified** @@ -15,13 +15,13 @@ class StatuspageHookTests(WebhookTestCase): """.strip() self.check_webhook( "incident_created", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_statuspage_incident_update(self) -> None: - expected_topic = "Database query delays: All Systems Operational" + expected_topic_name = "Database query delays: All Systems Operational" expected_message = """ **Database query delays**: * State: **resolved** @@ -29,17 +29,17 @@ class StatuspageHookTests(WebhookTestCase): """.strip() self.check_webhook( "incident_update", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_statuspage_component(self) -> None: - expected_topic = "Database component: Service Under Maintenance" + expected_topic_name = "Database component: Service Under Maintenance" expected_message = "**Database component** has changed status from **operational** to **under_maintenance**." self.check_webhook( "component_status_update", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/statuspage/view.py b/zerver/webhooks/statuspage/view.py index 2e12f23659..1a8b1c65f6 100644 --- a/zerver/webhooks/statuspage/view.py +++ b/zerver/webhooks/statuspage/view.py @@ -62,14 +62,14 @@ def api_statuspage_webhook( ) -> HttpResponse: if "incident" in payload: event = "incident" - topic = get_incident_topic(payload) + topic_name = get_incident_topic(payload) body = get_incident_events_body(payload) elif "component" in payload: event = "component" - topic = get_component_topic(payload) + topic_name = get_component_topic(payload) body = get_components_update_body(payload) else: raise AnomalousWebhookPayloadError - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/stripe/tests.py b/zerver/webhooks/stripe/tests.py index 800f682666..062cbf7ed7 100644 --- a/zerver/webhooks/stripe/tests.py +++ b/zerver/webhooks/stripe/tests.py @@ -10,95 +10,95 @@ class StripeHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "stripe" def test_charge_dispute_closed(self) -> None: - expected_topic = "disputes" + expected_topic_name = "disputes" expected_message = "[Dispute](https://dashboard.stripe.com/disputes/dp_00000000000000) closed. Current status: won." self.check_webhook( "charge_dispute_closed", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_charge_dispute_created(self) -> None: - expected_topic = "disputes" + expected_topic_name = "disputes" expected_message = "[Dispute](https://dashboard.stripe.com/disputes/dp_00000000000000) created. Current status: needs response." self.check_webhook( "charge_dispute_created", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_charge_failed(self) -> None: - expected_topic = "charges" + expected_topic_name = "charges" expected_message = ( "[Charge](https://dashboard.stripe.com/charges/ch_00000000000000) for 1.00 AUD failed" ) self.check_webhook( "charge_failed", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) # Credit card charge def test_charge_succeeded__card(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = "[Charge](https://dashboard.stripe.com/charges/ch_000000000000000000000000) for 1.00 AUD succeeded" self.check_webhook( "charge_succeeded__card", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) # ACH payment (really a 'payment', rather than a 'charge') def test_charge_succeeded__invoice(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = "[Payment](https://dashboard.stripe.com/payments/py_000000000000000000000000) for $1.00 succeeded" self.check_webhook( "charge_succeeded__invoice", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customer_created(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = ( "[Customer](https://dashboard.stripe.com/customers/cus_00000000000000) created" ) self.check_webhook( "customer_created", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customer_created_email(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = "[Customer](https://dashboard.stripe.com/customers/cus_00000000000000) created\nEmail: example@abc.com" self.check_webhook( "customer_created_email", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customer_deleted(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = ( "[Customer](https://dashboard.stripe.com/customers/cus_00000000000000) deleted" ) self.check_webhook( "customer_deleted", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customer_subscription_created(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = """\ [Subscription](https://dashboard.stripe.com/subscriptions/sub_E6STM5w5EX3K28) created Plan: [flatrate](https://dashboard.stripe.com/plans/plan_E6SQ6RAtmLVtzg) @@ -106,13 +106,13 @@ Quantity: 800 Billing method: send invoice""" self.check_webhook( "customer_subscription_created", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customer_subscription_created_no_nickname(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = """\ [Subscription](https://dashboard.stripe.com/subscriptions/sub_E6STM5w5EX3K28) created Plan: https://dashboard.stripe.com/plans/plan_E6SQ6RAtmLVtzg @@ -120,25 +120,25 @@ Quantity: 800 Billing method: send invoice""" self.check_webhook( "customer_subscription_created_no_nickname", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customer_subscription_deleted(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = ( "[Subscription](https://dashboard.stripe.com/subscriptions/sub_00000000000000) deleted" ) self.check_webhook( "customer_subscription_deleted", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customer_subscription_updated(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = """\ [Subscription](https://dashboard.stripe.com/subscriptions/sub_E6STM5w5EX3K28) updated * Billing cycle anchor is now Nov 01, 2019, 12:00:00 UTC @@ -150,97 +150,97 @@ Billing method: send invoice""" * Trial start is now Dec 06, 2018, 05:53:55 UTC""" self.check_webhook( "customer_subscription_updated", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customer_subscription_trial_will_end(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = "[Subscription](https://dashboard.stripe.com/subscriptions/sub_00000000000000) trial will end in 3 days" # 3 days before the end of the trial, plus a little bit to make sure the rounding is working with mock.patch("time.time", return_value=1480892861 - 3 * 3600 * 24 + 100): # use fixture named stripe_customer_subscription_trial_will_end self.check_webhook( "customer_subscription_trial_will_end", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customer_updated__account_balance(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = ( "[Customer](https://dashboard.stripe.com/customers/cus_00000000000000) updated" "\n* Account balance is now 100" ) self.check_webhook( "customer_updated__account_balance", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_customer_discount_created(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = "Discount created ([25.5% off](https://dashboard.stripe.com/coupons/25_00000000000000))." self.check_webhook( "customer_discount_created", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_invoice_payment_failed(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = ( "[Invoice](https://dashboard.stripe.com/invoices/in_00000000000000) payment failed" ) self.check_webhook( "invoice_payment_failed", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_invoice_created(self) -> None: - expected_topic = "cus_HH97asvHvaYQYp" + expected_topic_name = "cus_HH97asvHvaYQYp" expected_message = """ [Invoice](https://dashboard.stripe.com/invoices/in_1GpmuuHLwdCOCoR7ghzQDQLW) created (manual) Total: 0.00 INR Amount due: 0.00 INR """.strip() - self.check_webhook("invoice_created", expected_topic, expected_message) + self.check_webhook("invoice_created", expected_topic_name, expected_message) def test_invoiceitem_created(self) -> None: - expected_topic = "cus_00000000000000" + expected_topic_name = "cus_00000000000000" expected_message = "[Invoice item](https://dashboard.stripe.com/invoiceitems/ii_00000000000000) created for 10.00 CAD" self.check_webhook( "invoiceitem_created", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_invoice_paid(self) -> None: - expected_topic = "cus_FDmrSwQt9Fck5M" + expected_topic_name = "cus_FDmrSwQt9Fck5M" expected_message = "[Invoice](https://dashboard.stripe.com/invoices/in_1EjLINHuGUuNWDDZjDf2WNqd) is now paid" self.check_webhook( "invoice_updated__paid", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_refund_event(self) -> None: - expected_topic = "refunds" + expected_topic_name = "refunds" expected_message = "A [refund](https://dashboard.stripe.com/refunds/re_1Gib6ZHLwdCOCoR7VrzCnXlj) for a [charge](https://dashboard.stripe.com/charges/ch_1Gib61HLwdCOCoR71rnkccye) of 300000.00 INR was updated." - self.check_webhook("refund_event", expected_topic, expected_message) + self.check_webhook("refund_event", expected_topic_name, expected_message) def test_pseudo_refund_event(self) -> None: - expected_topic = "refunds" + expected_topic_name = "refunds" expected_message = "A [refund](https://dashboard.stripe.com/refunds/pyr_abcde12345ABCDF) for a [payment](https://dashboard.stripe.com/payments/py_abcde12345ABCDG) of 12.34 EUR was updated." - self.check_webhook("pseudo_refund_event", expected_topic, expected_message) + self.check_webhook("pseudo_refund_event", expected_topic_name, expected_message) @patch("zerver.webhooks.stripe.view.check_send_webhook_message") def test_account_updated_without_previous_attributes_ignore( diff --git a/zerver/webhooks/stripe/view.py b/zerver/webhooks/stripe/view.py index 387dbd89cc..cb7a7a6605 100644 --- a/zerver/webhooks/stripe/view.py +++ b/zerver/webhooks/stripe/view.py @@ -56,11 +56,11 @@ def api_stripe_webhook( stream: str = "test", ) -> HttpResponse: try: - topic, body = topic_and_body(payload) + topic_name, body = topic_and_body(payload) except SuppressedEventError: # nocoverage return json_success(request) check_send_webhook_message( - request, user_profile, topic, body, payload["type"].tame(check_string) + request, user_profile, topic_name, body, payload["type"].tame(check_string) ) return json_success(request) @@ -78,12 +78,12 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]: object_ = payload["data"]["object"] # The full, updated Stripe object # Set the topic to the customer_id when we can - topic = "" + topic_name = "" customer_id = object_.get("customer").tame(check_none_or(check_string)) if customer_id is not None: # Running into the 60 character topic limit. # topic = '[{}](https://dashboard.stripe.com/customers/{})' % (customer_id, customer_id) - topic = customer_id + topic_name = customer_id body = None def update_string(blacklist: Sequence[str] = []) -> str: @@ -114,7 +114,7 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]: if event == "updated": if "previous_attributes" not in payload["data"]: raise SuppressedEventError - topic = "account updates" + topic_name = "account updates" body = update_string() else: # Part of Stripe Connect @@ -127,8 +127,8 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]: raise NotImplementedEventTypeError if category == "charge": if resource == "charge": - if not topic: # only in legacy fixtures - topic = "charges" + if not topic_name: # only in legacy fixtures + topic_name = "charges" body = "{resource} for {amount} {verbed}".format( resource=linkified_id(object_["id"].tame(check_string)), amount=amount_string( @@ -139,12 +139,12 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]: if object_["failure_code"]: # nocoverage body += ". Failure code: {}".format(object_["failure_code"].tame(check_string)) if resource == "dispute": - topic = "disputes" + topic_name = "disputes" body = default_body() + ". Current status: {status}.".format( status=object_["status"].tame(check_string).replace("_", " ") ) if resource == "refund": - topic = "refunds" + topic_name = "refunds" body = "A {resource} for a {charge} of {amount} was updated.".format( resource=linkified_id(object_["id"].tame(check_string), lower=True), charge=linkified_id(object_["charge"].tame(check_string), lower=True), @@ -162,7 +162,7 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]: if resource == "customer": # Running into the 60 character topic limit. # topic = '[{}](https://dashboard.stripe.com/customers/{})' % (object_['id'], object_['id']) - topic = object_["id"].tame(check_string) + topic_name = object_["id"].tame(check_string) body = default_body(update_blacklist=["delinquent", "currency", "default_source"]) if event == "created": if object_["email"]: @@ -207,7 +207,7 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]: object_["billing"].tame(check_string).replace("_", " ") ) if category == "file": # nocoverage - topic = "files" + topic_name = "files" body = default_body() + " ({purpose}). \nTitle: {title}".format( purpose=object_["purpose"].tame(check_string).replace("_", " "), title=object_["title"].tame(check_string), @@ -286,7 +286,7 @@ def topic_and_body(payload: WildValue) -> Tuple[str, str]: if body is None: raise UnsupportedWebhookEventTypeError(event_type) - return (topic, body) + return (topic_name, body) def amount_string(amount: int, currency: str) -> str: diff --git a/zerver/webhooks/taiga/tests.py b/zerver/webhooks/taiga/tests.py index 936e4f5baf..04929bcaa0 100644 --- a/zerver/webhooks/taiga/tests.py +++ b/zerver/webhooks/taiga/tests.py @@ -5,82 +5,82 @@ from zerver.lib.test_classes import WebhookTestCase class TaigaHookTests(WebhookTestCase): STREAM_NAME = "taiga" - TOPIC = "subject" + TOPIC_NAME = "subject" URL_TEMPLATE = "/api/v1/external/taiga?stream={stream}&api_key={api_key}" WEBHOOK_DIR_NAME = "taiga" @override def setUp(self) -> None: super().setUp() - self.url = self.build_webhook_url(topic=self.TOPIC) + self.url = self.build_webhook_url(topic=self.TOPIC_NAME) def test_taiga_userstory_deleted(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) deleted user story **New userstory**." - self.check_webhook("userstory_deleted", self.TOPIC, message) + self.check_webhook("userstory_deleted", self.TOPIC_NAME, message) def test_taiga_userstory_created(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) created user story **New userstory**." - self.check_webhook("userstory_created", self.TOPIC, message) + self.check_webhook("userstory_created", self.TOPIC_NAME, message) def test_taiga_userstory_changed_unblocked(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) unblocked user story **UserStory**." - self.check_webhook("userstory_changed_unblocked", self.TOPIC, message) + self.check_webhook("userstory_changed_unblocked", self.TOPIC_NAME, message) def test_taiga_userstory_changed_subject(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) renamed user story from UserStory to **UserStoryNewSubject**." - self.check_webhook("userstory_changed_subject", self.TOPIC, message) + self.check_webhook("userstory_changed_subject", self.TOPIC_NAME, message) def test_taiga_userstory_changed_status(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed status of user story **UserStory** from Ready to In progress." - self.check_webhook("userstory_changed_status", self.TOPIC, message) + self.check_webhook("userstory_changed_status", self.TOPIC_NAME, message) def test_taiga_userstory_changed_reassigned(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) reassigned user story **UserStory** from TomaszKolek to HanSolo." - self.check_webhook("userstory_changed_reassigned", self.TOPIC, message) + self.check_webhook("userstory_changed_reassigned", self.TOPIC_NAME, message) def test_taiga_userstory_changed_unassigned(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) unassigned user story **UserStory**." - self.check_webhook("userstory_changed_unassigned", self.TOPIC, message) + self.check_webhook("userstory_changed_unassigned", self.TOPIC_NAME, message) def test_taiga_userstory_changed_points(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed estimation of user story **UserStory**." - self.check_webhook("userstory_changed_points", self.TOPIC, message) + self.check_webhook("userstory_changed_points", self.TOPIC_NAME, message) def test_taiga_userstory_changed_new_sprint(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) added user story **UserStory** to sprint Sprint1." - self.check_webhook("userstory_changed_new_sprint", self.TOPIC, message) + self.check_webhook("userstory_changed_new_sprint", self.TOPIC_NAME, message) def test_taiga_userstory_changed_sprint(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed sprint of user story **UserStory** from Sprint1 to Sprint2." - self.check_webhook("userstory_changed_sprint", self.TOPIC, message) + self.check_webhook("userstory_changed_sprint", self.TOPIC_NAME, message) def test_taiga_userstory_changed_remove_sprint(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) removed user story **UserStory** from sprint Sprint2." - self.check_webhook("userstory_changed_remove_sprint", self.TOPIC, message) + self.check_webhook("userstory_changed_remove_sprint", self.TOPIC_NAME, message) def test_taiga_userstory_changed_description(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) updated description of user story **UserStory**." - self.check_webhook("userstory_changed_description", self.TOPIC, message) + self.check_webhook("userstory_changed_description", self.TOPIC_NAME, message) def test_taiga_userstory_changed_closed(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed status of user story **UserStory** from New to Done.\n[TomaszKolek](https://tree.taiga.io/profile/kolaszek) closed user story **UserStory**." - self.check_webhook("userstory_changed_closed", self.TOPIC, message) + self.check_webhook("userstory_changed_closed", self.TOPIC_NAME, message) def test_taiga_userstory_changed_reopened(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed status of user story **UserStory** from Done to Ready.\n[TomaszKolek](https://tree.taiga.io/profile/kolaszek) reopened user story **UserStory**." - self.check_webhook("userstory_changed_reopened", self.TOPIC, message) + self.check_webhook("userstory_changed_reopened", self.TOPIC_NAME, message) def test_taiga_userstory_changed_blocked(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) blocked user story **UserStory**." - self.check_webhook("userstory_changed_blocked", self.TOPIC, message) + self.check_webhook("userstory_changed_blocked", self.TOPIC_NAME, message) def test_taiga_userstory_changed_assigned(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) assigned user story **UserStory** to TomaszKolek." - self.check_webhook("userstory_changed_assigned", self.TOPIC, message) + self.check_webhook("userstory_changed_assigned", self.TOPIC_NAME, message) def test_taiga_userstory_comment_added(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) commented on user story **UserStory**." - self.check_webhook("userstory_changed_comment_added", self.TOPIC, message) + self.check_webhook("userstory_changed_comment_added", self.TOPIC_NAME, message) def test_taiga_userstory_changed_due_date(self) -> None: message = ( @@ -88,63 +88,63 @@ class TaigaHookTests(WebhookTestCase): " [Nice Issue](https://tree.taiga.io/project/orientor-sd/us/54) from 2020-02-15 to" " 2020-02-22." ) - self.check_webhook("userstory_changed_due_date", self.TOPIC, message) + self.check_webhook("userstory_changed_due_date", self.TOPIC_NAME, message) def test_taiga_userstory_changed_new_due_date(self) -> None: message = "[Aditya Verma](https://tree.taiga.io/profile/orientor) set due date of user story [random](https://tree.taiga.io/project/orientor-sd/us/58) to 2020-02-15." - self.check_webhook("userstory_changed_new_due_date", self.TOPIC, message) + self.check_webhook("userstory_changed_new_due_date", self.TOPIC_NAME, message) def test_taiga_task_created(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) created task **New Task**." - self.check_webhook("task_created", self.TOPIC, message) + self.check_webhook("task_created", self.TOPIC_NAME, message) def test_taiga_task_changed_user_stories(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) added task **Get this task done** to sprint Another one.\n[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) moved task **Get this task done** from user story #7 Yaar ne scirra! to #8 A related user story, which is epic." - self.check_webhook("task_changed_user_stories", self.TOPIC, message) + self.check_webhook("task_changed_user_stories", self.TOPIC_NAME, message) def test_taiga_task_changed_status(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed status of task **New Task** from New to In progress." - self.check_webhook("task_changed_status", self.TOPIC, message) + self.check_webhook("task_changed_status", self.TOPIC_NAME, message) def test_taiga_task_changed_blocked(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) blocked task **New Task**." - self.check_webhook("task_changed_blocked", self.TOPIC, message) + self.check_webhook("task_changed_blocked", self.TOPIC_NAME, message) def test_taiga_task_changed_blocked_link(self) -> None: message = "[Aditya Verma](https://tree.taiga.io/profile/orientor) blocked task [nice task](https://tree.taiga.io/project/orientor-sd/task/56)." - self.check_webhook("task_changed_blocked_link", self.TOPIC, message) + self.check_webhook("task_changed_blocked_link", self.TOPIC_NAME, message) def test_taiga_task_changed_unblocked(self) -> None: message = ( "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) unblocked task **New Task**." ) - self.check_webhook("task_changed_unblocked", self.TOPIC, message) + self.check_webhook("task_changed_unblocked", self.TOPIC_NAME, message) def test_taiga_task_changed_assigned(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) assigned task **New Task** to TomaszKolek." - self.check_webhook("task_changed_assigned", self.TOPIC, message) + self.check_webhook("task_changed_assigned", self.TOPIC_NAME, message) def test_taiga_task_changed_reassigned(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) reassigned task **New Task** from HanSolo to TomaszKolek." - self.check_webhook("task_changed_reassigned", self.TOPIC, message) + self.check_webhook("task_changed_reassigned", self.TOPIC_NAME, message) def test_taiga_task_changed_subject(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) renamed task New Task to **New Task Subject**." - self.check_webhook("task_changed_subject", self.TOPIC, message) + self.check_webhook("task_changed_subject", self.TOPIC_NAME, message) def test_taiga_task_changed_description(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) updated description of task **New Task**." - self.check_webhook("task_changed_description", self.TOPIC, message) + self.check_webhook("task_changed_description", self.TOPIC_NAME, message) def test_taiga_task_deleted(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) deleted task **New Task**." - self.check_webhook("task_deleted", self.TOPIC, message) + self.check_webhook("task_deleted", self.TOPIC_NAME, message) def test_taiga_task_changed_comment_added(self) -> None: message = ( "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) commented on task **New Task**." ) - self.check_webhook("task_changed_comment_added", self.TOPIC, message) + self.check_webhook("task_changed_comment_added", self.TOPIC_NAME, message) def test_taiga_task_changed_due_date(self) -> None: message = ( @@ -152,91 +152,91 @@ class TaigaHookTests(WebhookTestCase): " [nice task](https://tree.taiga.io/project/orientor-sd/task/56) from 2020-02-22 to" " 2020-02-15." ) - self.check_webhook("task_changed_due_date", self.TOPIC, message) + self.check_webhook("task_changed_due_date", self.TOPIC_NAME, message) def test_taiga_task_changed_new_due_date(self) -> None: message = "[Aditya Verma](https://tree.taiga.io/profile/orientor) set due date of task [nice task](https://tree.taiga.io/project/orientor-sd/task/56) to 2020-02-22." - self.check_webhook("task_changed_new_due_date", self.TOPIC, message) + self.check_webhook("task_changed_new_due_date", self.TOPIC_NAME, message) def test_taiga_sprint_created(self) -> None: message = ( "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) created sprint **New sprint**." ) - self.check_webhook("sprint_created", self.TOPIC, message) + self.check_webhook("sprint_created", self.TOPIC_NAME, message) def test_taiga_sprint_deleted(self) -> None: message = ( "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) deleted sprint **New name**." ) - self.check_webhook("sprint_deleted", self.TOPIC, message) + self.check_webhook("sprint_deleted", self.TOPIC_NAME, message) def test_taiga_sprint_changed_time(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed estimated finish of sprint **New sprint** from 2017-01-24 to 2017-01-25." - self.check_webhook("sprint_changed_time", self.TOPIC, message) + self.check_webhook("sprint_changed_time", self.TOPIC_NAME, message) def test_taiga_sprint_changed_name(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) renamed sprint from New sprint to **New name**." - self.check_webhook("sprint_changed_name", self.TOPIC, message) + self.check_webhook("sprint_changed_name", self.TOPIC_NAME, message) def test_taiga_issue_created(self) -> None: message = ( "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) created issue **New issue**." ) - self.check_webhook("issue_created", self.TOPIC, message) + self.check_webhook("issue_created", self.TOPIC_NAME, message) def test_taiga_issue_created_link(self) -> None: message = "[Aditya Verma](https://tree.taiga.io/profile/orientor) created issue [Issues](https://tree.taiga.io/project/orientor-sd/issue/49)." - self.check_webhook("issue_created_link", self.TOPIC, message) + self.check_webhook("issue_created_link", self.TOPIC_NAME, message) def test_taiga_issue_deleted(self) -> None: message = ( "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) deleted issue **New issue**." ) - self.check_webhook("issue_deleted", self.TOPIC, message) + self.check_webhook("issue_deleted", self.TOPIC_NAME, message) def test_taiga_issue_changed_assigned(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) assigned issue **New issue** to TomaszKolek." - self.check_webhook("issue_changed_assigned", self.TOPIC, message) + self.check_webhook("issue_changed_assigned", self.TOPIC_NAME, message) def test_taiga_issue_changed_reassigned(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) reassigned issue **New issue** from TomaszKolek to HanSolo." - self.check_webhook("issue_changed_reassigned", self.TOPIC, message) + self.check_webhook("issue_changed_reassigned", self.TOPIC_NAME, message) def test_taiga_issue_changed_subject(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) renamed issue New issue to **New issueNewSubject**." - self.check_webhook("issue_changed_subject", self.TOPIC, message) + self.check_webhook("issue_changed_subject", self.TOPIC_NAME, message) def test_taiga_issue_changed_description(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) updated description of issue **New issue**." - self.check_webhook("issue_changed_description", self.TOPIC, message) + self.check_webhook("issue_changed_description", self.TOPIC_NAME, message) def test_taiga_issue_changed_type(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed type of issue **New issue** from Bug to Question." - self.check_webhook("issue_changed_type", self.TOPIC, message) + self.check_webhook("issue_changed_type", self.TOPIC_NAME, message) def test_taiga_issue_changed_status(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed status of issue **New issue** from New to In progress." - self.check_webhook("issue_changed_status", self.TOPIC, message) + self.check_webhook("issue_changed_status", self.TOPIC_NAME, message) def test_taiga_issue_changed_severity(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed severity of issue **New issue** from Normal to Minor." - self.check_webhook("issue_changed_severity", self.TOPIC, message) + self.check_webhook("issue_changed_severity", self.TOPIC_NAME, message) def test_taiga_issue_changed_priority(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) changed priority of issue **New issue** from Normal to Low." - self.check_webhook("issue_changed_priority", self.TOPIC, message) + self.check_webhook("issue_changed_priority", self.TOPIC_NAME, message) def test_taiga_issue_changed_comment_added(self) -> None: message = "[TomaszKolek](https://tree.taiga.io/profile/kolaszek) commented on issue **New issue**." - self.check_webhook("issue_changed_comment_added", self.TOPIC, message) + self.check_webhook("issue_changed_comment_added", self.TOPIC_NAME, message) def test_taiga_issue_changed_blocked(self) -> None: message = "[Aditya Verma](https://tree.taiga.io/profile/orientor) blocked issue [Issues](https://tree.taiga.io/project/orientor-sd/issue/49)." - self.check_webhook("issue_changed_blocked", self.TOPIC, message) + self.check_webhook("issue_changed_blocked", self.TOPIC_NAME, message) def test_taiga_issue_changed_unblocked(self) -> None: message = "[Aditya Verma](https://tree.taiga.io/profile/orientor) unblocked issue [Issues](https://tree.taiga.io/project/orientor-sd/issue/49)." - self.check_webhook("issue_changed_unblocked", self.TOPIC, message) + self.check_webhook("issue_changed_unblocked", self.TOPIC_NAME, message) def test_taiga_issue_changed_due_date(self) -> None: message = ( @@ -244,67 +244,67 @@ class TaigaHookTests(WebhookTestCase): " [Issues](https://tree.taiga.io/project/orientor-sd/issue/49) from 2020-03-08 to" " 2020-02-22." ) - self.check_webhook("issue_changed_due_date", self.TOPIC, message) + self.check_webhook("issue_changed_due_date", self.TOPIC_NAME, message) def test_taiga_issue_changed_new_due_date(self) -> None: message = "[Aditya Verma](https://tree.taiga.io/profile/orientor) set due date of issue [Nice Issue](https://tree.taiga.io/project/orientor-sd/issue/53) to 2020-02-22." - self.check_webhook("issue_changed_new_due_date", self.TOPIC, message) + self.check_webhook("issue_changed_new_due_date", self.TOPIC_NAME, message) def test_taiga_issue_changed_new_sprint(self) -> None: message = "[Aditya Verma](https://tree.taiga.io/profile/orientor) added issue [Nice Issue](https://tree.taiga.io/project/orientor-sd/issue/53) to sprint eres." - self.check_webhook("issue_changed_new_sprint", self.TOPIC, message) + self.check_webhook("issue_changed_new_sprint", self.TOPIC_NAME, message) def test_taiga_issue_changed_remove_sprint(self) -> None: message = "[Aditya Verma](https://tree.taiga.io/profile/orientor) detached issue [Nice Issue](https://tree.taiga.io/project/orientor-sd/issue/53) from sprint eres." - self.check_webhook("issue_changed_remove_sprint", self.TOPIC, message) + self.check_webhook("issue_changed_remove_sprint", self.TOPIC_NAME, message) def test_taiga_epic_created(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) created epic **Zulip is awesome!**." - self.check_webhook("epic_created", self.TOPIC, message) + self.check_webhook("epic_created", self.TOPIC_NAME, message) def test_taiga_epic_changed_assigned(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) assigned epic **Zulip is awesome!** to Eeshan Garg." - self.check_webhook("epic_changed_assigned", self.TOPIC, message) + self.check_webhook("epic_changed_assigned", self.TOPIC_NAME, message) def test_taiga_epic_changed_unassigned(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) unassigned epic **Zulip is awesome!**." - self.check_webhook("epic_changed_unassigned", self.TOPIC, message) + self.check_webhook("epic_changed_unassigned", self.TOPIC_NAME, message) def test_taiga_epic_changed_reassigned(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) reassigned epic **Zulip is awesome!** from Eeshan Garg to Angela Johnson." - self.check_webhook("epic_changed_reassigned", self.TOPIC, message) + self.check_webhook("epic_changed_reassigned", self.TOPIC_NAME, message) def test_taiga_epic_changed_blocked(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) blocked epic **Zulip is awesome!**." - self.check_webhook("epic_changed_blocked", self.TOPIC, message) + self.check_webhook("epic_changed_blocked", self.TOPIC_NAME, message) def test_taiga_epic_changed_unblocked(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) unblocked epic **Zulip is awesome!**." - self.check_webhook("epic_changed_unblocked", self.TOPIC, message) + self.check_webhook("epic_changed_unblocked", self.TOPIC_NAME, message) def test_taiga_epic_changed_status(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) changed status of epic **Zulip is awesome!** from New to In progress." - self.check_webhook("epic_changed_status", self.TOPIC, message) + self.check_webhook("epic_changed_status", self.TOPIC_NAME, message) def test_taiga_epic_changed_renamed(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) renamed epic from **Zulip is awesome!** to **Zulip is great!**." - self.check_webhook("epic_changed_renamed", self.TOPIC, message) + self.check_webhook("epic_changed_renamed", self.TOPIC_NAME, message) def test_taiga_epic_changed_description(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) updated description of epic **Zulip is great!**." - self.check_webhook("epic_changed_description", self.TOPIC, message) + self.check_webhook("epic_changed_description", self.TOPIC_NAME, message) def test_taiga_epic_changed_commented(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) commented on epic **Zulip is great!**." - self.check_webhook("epic_changed_commented", self.TOPIC, message) + self.check_webhook("epic_changed_commented", self.TOPIC_NAME, message) def test_taiga_epic_deleted(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) deleted epic **Zulip is great!**." - self.check_webhook("epic_deleted", self.TOPIC, message) + self.check_webhook("epic_deleted", self.TOPIC_NAME, message) def test_taiga_relateduserstory_created(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) added a related user story **A related user story** to the epic **This is Epic!**." - self.check_webhook("relateduserstory_created", self.TOPIC, message) + self.check_webhook("relateduserstory_created", self.TOPIC_NAME, message) def test_taiga_relateduserstory_created_link(self) -> None: message = ( @@ -312,14 +312,14 @@ class TaigaHookTests(WebhookTestCase): " [Nice Issue](https://tree.taiga.io/project/orientor-sd/us/54) to the epic" " [ASAS](https://tree.taiga.io/project/orientor-sd/epic/42)." ) - self.check_webhook("relateduserstory_created_link", self.TOPIC, message) + self.check_webhook("relateduserstory_created_link", self.TOPIC_NAME, message) def test_taiga_relateduserstory_deleted(self) -> None: message = "[Eeshan Garg](https://tree.taiga.io/profile/eeshangarg) removed a related user story **A related user story, which is epic** from the epic **This is Epic!**." - self.check_webhook("relateduserstory_deleted", self.TOPIC, message) + self.check_webhook("relateduserstory_deleted", self.TOPIC_NAME, message) def test_taiga_webhook_test(self) -> None: message = ( "[Jan](https://tree.taiga.io/profile/kostek) triggered a test of the Taiga integration." ) - self.check_webhook("webhook_test", self.TOPIC, message) + self.check_webhook("webhook_test", self.TOPIC_NAME, message) diff --git a/zerver/webhooks/taiga/view.py b/zerver/webhooks/taiga/view.py index d61f01e06d..ab41d8f229 100644 --- a/zerver/webhooks/taiga/view.py +++ b/zerver/webhooks/taiga/view.py @@ -32,10 +32,10 @@ def api_taiga_webhook( ) -> HttpResponse: parsed_events = parse_message(message) content = "".join(sorted(generate_content(event) + "\n" for event in parsed_events)) - topic = "General" + topic_name = "General" if message["data"].get("milestone") and "name" in message["data"]["milestone"]: - topic = message["data"]["milestone"]["name"].tame(check_string) - check_send_webhook_message(request, user_profile, topic, content) + topic_name = message["data"]["milestone"]["name"].tame(check_string) + check_send_webhook_message(request, user_profile, topic_name, content) return json_success(request) diff --git a/zerver/webhooks/teamcity/tests.py b/zerver/webhooks/teamcity/tests.py index 39a11b4d80..980442d8b0 100644 --- a/zerver/webhooks/teamcity/tests.py +++ b/zerver/webhooks/teamcity/tests.py @@ -11,29 +11,29 @@ from zerver.webhooks.teamcity.view import MISCONFIGURED_PAYLOAD_TYPE_ERROR_MESSA class TeamCityHookTests(WebhookTestCase): STREAM_NAME = "teamcity" URL_TEMPLATE = "/api/v1/external/teamcity?stream={stream}&api_key={api_key}" - TOPIC = "Project :: Compile" + TOPIC_NAME = "Project :: Compile" WEBHOOK_DIR_NAME = "teamcity" def test_teamcity_success(self) -> None: expected_message = "Project :: Compile build 5535 - CL 123456 was successful! :thumbs_up: See [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv) and [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952)." - self.check_webhook("success", self.TOPIC, expected_message) + self.check_webhook("success", self.TOPIC_NAME, expected_message) def test_teamcity_success_branch(self) -> None: expected_message = "Project :: Compile build 5535 - CL 123456 was successful! :thumbs_up: See [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv) and [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952)." - expected_topic = "Project :: Compile (MyBranch)" - self.check_webhook("success_branch", expected_topic, expected_message) + expected_topic_name = "Project :: Compile (MyBranch)" + self.check_webhook("success_branch", expected_topic_name, expected_message) def test_teamcity_broken(self) -> None: expected_message = "Project :: Compile build 5535 - CL 123456 is broken with status Exit code 1 (new)! :thumbs_down: See [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv) and [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952)." - self.check_webhook("broken", self.TOPIC, expected_message) + self.check_webhook("broken", self.TOPIC_NAME, expected_message) def test_teamcity_failure(self) -> None: expected_message = "Project :: Compile build 5535 - CL 123456 is still broken with status Exit code 1! :thumbs_down: See [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv) and [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952)." - self.check_webhook("failure", self.TOPIC, expected_message) + self.check_webhook("failure", self.TOPIC_NAME, expected_message) def test_teamcity_fixed(self) -> None: expected_message = "Project :: Compile build 5535 - CL 123456 has been fixed! :thumbs_up: See [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv) and [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952)." - self.check_webhook("fixed", self.TOPIC, expected_message) + self.check_webhook("fixed", self.TOPIC_NAME, expected_message) def test_teamcity_personal(self) -> None: expected_message = "Your personal build for Project :: Compile build 5535 - CL 123456 is broken with status Exit code 1 (new)! :thumbs_down: See [changes](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952&tab=buildChangesDiv) and [build log](http://teamcity/viewLog.html?buildTypeId=Project_Compile&buildId=19952)." diff --git a/zerver/webhooks/teamcity/view.py b/zerver/webhooks/teamcity/view.py index 59f71301d5..aea56f2fc0 100644 --- a/zerver/webhooks/teamcity/view.py +++ b/zerver/webhooks/teamcity/view.py @@ -107,9 +107,9 @@ def api_teamcity_webhook( ) if "branchDisplayName" in message: - topic = "{} ({})".format(build_name, message["branchDisplayName"].tame(check_string)) + topic_name = "{} ({})".format(build_name, message["branchDisplayName"].tame(check_string)) else: - topic = build_name + topic_name = build_name # Check if this is a personal build, and if so try to direct message the user who triggered it. if ( @@ -148,5 +148,5 @@ def api_teamcity_webhook( return json_success(request) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/thinkst/view.py b/zerver/webhooks/thinkst/view.py index e2f3bb4890..87ee961f82 100644 --- a/zerver/webhooks/thinkst/view.py +++ b/zerver/webhooks/thinkst/view.py @@ -131,14 +131,14 @@ def api_thinkst_webhook( response = body(message) - topic = None + topic_name = None if user_specified_topic: - topic = user_specified_topic + topic_name = user_specified_topic else: name = canary_name(message) kind = canary_kind(message) - topic = f"{kind} alert - {name}" + topic_name = f"{kind} alert - {name}" - check_send_webhook_message(request, user_profile, topic, response) + check_send_webhook_message(request, user_profile, topic_name, response) return json_success(request) diff --git a/zerver/webhooks/transifex/tests.py b/zerver/webhooks/transifex/tests.py index 5c43fad235..e691b53870 100644 --- a/zerver/webhooks/transifex/tests.py +++ b/zerver/webhooks/transifex/tests.py @@ -15,7 +15,7 @@ class TransifexHookTests(WebhookTestCase): RESOURCE = "file" def test_transifex_reviewed_message(self) -> None: - expected_topic = f"{self.PROJECT} in {self.LANGUAGE}" + expected_topic_name = f"{self.PROJECT} in {self.LANGUAGE}" expected_message = f"Resource {self.RESOURCE} fully reviewed." self.url = self.build_webhook_url( event="review_completed", @@ -24,10 +24,10 @@ class TransifexHookTests(WebhookTestCase): language=self.LANGUAGE, resource=self.RESOURCE, ) - self.check_webhook("", expected_topic, expected_message) + self.check_webhook("", expected_topic_name, expected_message) def test_transifex_translated_message(self) -> None: - expected_topic = f"{self.PROJECT} in {self.LANGUAGE}" + expected_topic_name = f"{self.PROJECT} in {self.LANGUAGE}" expected_message = f"Resource {self.RESOURCE} fully translated." self.url = self.build_webhook_url( event="translation_completed", @@ -36,7 +36,7 @@ class TransifexHookTests(WebhookTestCase): language=self.LANGUAGE, resource=self.RESOURCE, ) - self.check_webhook("", expected_topic, expected_message) + self.check_webhook("", expected_topic_name, expected_message) @override def get_payload(self, fixture_name: str) -> Dict[str, str]: diff --git a/zerver/webhooks/transifex/view.py b/zerver/webhooks/transifex/view.py index 6e1b5066f1..7f1aaae497 100644 --- a/zerver/webhooks/transifex/view.py +++ b/zerver/webhooks/transifex/view.py @@ -27,7 +27,7 @@ def api_transifex_webhook( translated: Optional[Json[int]] = None, reviewed: Optional[Json[int]] = None, ) -> HttpResponse: - topic = f"{project} in {language}" + topic_name = f"{project} in {language}" if event == "translation_completed": event = "translated" body = f"Resource {resource} fully translated." @@ -36,5 +36,5 @@ def api_transifex_webhook( body = f"Resource {resource} fully reviewed." else: raise UnsupportedWebhookEventTypeError(event) - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/travis/tests.py b/zerver/webhooks/travis/tests.py index 4602fc2fb5..aa6b13feaf 100644 --- a/zerver/webhooks/travis/tests.py +++ b/zerver/webhooks/travis/tests.py @@ -9,7 +9,7 @@ class TravisHookTests(WebhookTestCase): STREAM_NAME = "travis" URL_TEMPLATE = "/api/v1/external/travis?stream={stream}&api_key={api_key}" WEBHOOK_DIR_NAME = "travis" - TOPIC = "builds" + TOPIC_NAME = "builds" EXPECTED_MESSAGE = """ Author: josh_mandel Build status: Passed :thumbs_up: @@ -26,7 +26,7 @@ Details: [changes](https://github.com/hl7-fhir/fhir-svn/compare/6dccb98bcfd9...6 self.check_webhook( "build", - self.TOPIC, + self.TOPIC_NAME, self.EXPECTED_MESSAGE, content_type="application/x-www-form-urlencoded", ) @@ -41,7 +41,7 @@ Details: [changes](https://github.com/hl7-fhir/fhir-svn/compare/6dccb98bcfd9...6 self.check_webhook( "pull_request", - self.TOPIC, + self.TOPIC_NAME, self.EXPECTED_MESSAGE, content_type="application/x-www-form-urlencoded", ) @@ -51,7 +51,7 @@ Details: [changes](https://github.com/hl7-fhir/fhir-svn/compare/6dccb98bcfd9...6 self.check_webhook( "build", - self.TOPIC, + self.TOPIC_NAME, self.EXPECTED_MESSAGE, content_type="application/x-www-form-urlencoded", ) @@ -79,7 +79,7 @@ Details: [changes](https://github.com/hl7-fhir/fhir-svn/compare/6dccb98bcfd9...6 self.check_webhook( "pull_request", - self.TOPIC, + self.TOPIC_NAME, self.EXPECTED_MESSAGE, content_type="application/x-www-form-urlencoded", ) @@ -89,14 +89,14 @@ Details: [changes](https://github.com/hl7-fhir/fhir-svn/compare/6dccb98bcfd9...6 self.check_webhook( "pull_request", - self.TOPIC, + self.TOPIC_NAME, self.EXPECTED_MESSAGE, content_type="application/x-www-form-urlencoded", ) self.check_webhook( "build", - self.TOPIC, + self.TOPIC_NAME, self.EXPECTED_MESSAGE, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/travis/view.py b/zerver/webhooks/travis/view.py index 75ba7c5a85..cb2f4844e9 100644 --- a/zerver/webhooks/travis/view.py +++ b/zerver/webhooks/travis/view.py @@ -62,7 +62,7 @@ def api_travis_webhook( message.compare_url, message.build_url, ) - topic = "builds" + topic_name = "builds" - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/updown/tests.py b/zerver/webhooks/updown/tests.py index a5abbfc8a5..8502dde5c9 100644 --- a/zerver/webhooks/updown/tests.py +++ b/zerver/webhooks/updown/tests.py @@ -7,19 +7,19 @@ class UpdownHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "updown" def test_updown_check_down_event(self) -> None: - expected_topic = "https://updown.io" + expected_topic_name = "https://updown.io" expected_message = "Service is `down`. It returned a 500 error at 2016-02-07 13:11:43 UTC." - self.check_webhook("check_down_one_event", expected_topic, expected_message) + self.check_webhook("check_down_one_event", expected_topic_name, expected_message) def test_updown_check_up_again_event(self) -> None: - expected_topic = "https://updown.io" + expected_topic_name = "https://updown.io" expected_message = "Service is `up` again after 4 minutes 25 seconds." - self.check_webhook("check_up_again_one_event", expected_topic, expected_message) + self.check_webhook("check_up_again_one_event", expected_topic_name, expected_message) def test_updown_check_up_event(self) -> None: - expected_topic = "https://updown.io" + expected_topic_name = "https://updown.io" expected_message = "Service is `up`." - self.check_webhook("check_up_first_time", expected_topic, expected_message) + self.check_webhook("check_up_first_time", expected_topic_name, expected_message) def test_updown_check_up_multiple_events(self) -> None: topic_name = "https://updown.io" diff --git a/zerver/webhooks/updown/view.py b/zerver/webhooks/updown/view.py index 061f3eb815..367c75ad63 100644 --- a/zerver/webhooks/updown/view.py +++ b/zerver/webhooks/updown/view.py @@ -18,9 +18,9 @@ def send_message_for_event( request: HttpRequest, user_profile: UserProfile, event: WildValue ) -> None: event_type = get_event_type(event) - topic = TOPIC_TEMPLATE.format(service_url=event["check"]["url"].tame(check_string)) + topic_name = TOPIC_TEMPLATE.format(service_url=event["check"]["url"].tame(check_string)) body = EVENT_TYPE_BODY_MAPPER[event_type](event) - check_send_webhook_message(request, user_profile, topic, body, event_type) + check_send_webhook_message(request, user_profile, topic_name, body, event_type) def get_body_for_up_event(event: WildValue) -> str: diff --git a/zerver/webhooks/uptimerobot/tests.py b/zerver/webhooks/uptimerobot/tests.py index 8ded8911a4..8da89435b0 100644 --- a/zerver/webhooks/uptimerobot/tests.py +++ b/zerver/webhooks/uptimerobot/tests.py @@ -13,20 +13,20 @@ class UptimeRobotHookTests(WebhookTestCase): """ Tests if uptimerobot monitor down is handled correctly """ - expected_topic = "Web Server" + expected_topic_name = "Web Server" expected_message = "Web Server (server1.example.com) is DOWN (Host Is Unreachable)." - self.check_webhook("uptimerobot_monitor_down", expected_topic, expected_message) + self.check_webhook("uptimerobot_monitor_down", expected_topic_name, expected_message) def test_uptimerobot_monitor_up(self) -> None: """ Tests if uptimerobot monitor up is handled correctly """ - expected_topic = "Mail Server" + expected_topic_name = "Mail Server" expected_message = """ Mail Server (server2.example.com) is back UP (Host Is Reachable). It was down for 44 minutes and 37 seconds. """.strip() - self.check_webhook("uptimerobot_monitor_up", expected_topic, expected_message) + self.check_webhook("uptimerobot_monitor_up", expected_topic_name, expected_message) def test_uptimerobot_invalid_payload_with_missing_data(self) -> None: """ diff --git a/zerver/webhooks/uptimerobot/view.py b/zerver/webhooks/uptimerobot/view.py index 862c2ed862..7ad27f7134 100644 --- a/zerver/webhooks/uptimerobot/view.py +++ b/zerver/webhooks/uptimerobot/view.py @@ -47,7 +47,7 @@ def api_uptimerobot_webhook( try: body = get_body_for_http_request(payload, event_type) - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) except ValidationError: message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format( bot_name=user_profile.full_name, @@ -57,7 +57,7 @@ def api_uptimerobot_webhook( raise JsonableError(_("Invalid payload")) - check_send_webhook_message(request, user_profile, topic, body, event) + check_send_webhook_message(request, user_profile, topic_name, body, event) return json_success(request) diff --git a/zerver/webhooks/wekan/view.py b/zerver/webhooks/wekan/view.py index 69c64bc205..8346205f2e 100644 --- a/zerver/webhooks/wekan/view.py +++ b/zerver/webhooks/wekan/view.py @@ -44,7 +44,7 @@ def api_wekan_webhook( *, payload: JsonBodyPayload[WildValue], ) -> HttpResponse: - topic = "Wekan Notification" + topic_name = "Wekan Notification" body = get_message_body(payload) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/wordpress/tests.py b/zerver/webhooks/wordpress/tests.py index 95230a9c01..ed99aeb3b6 100644 --- a/zerver/webhooks/wordpress/tests.py +++ b/zerver/webhooks/wordpress/tests.py @@ -9,70 +9,70 @@ class WordPressHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "wordpress" def test_publish_post(self) -> None: - expected_topic = "WordPress Post" + expected_topic_name = "WordPress Post" expected_message = "New post published:\n* [New Blog Post](http://example.com\n)" self.check_webhook( "publish_post", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_publish_post_type_not_provided(self) -> None: - expected_topic = "WordPress Post" + expected_topic_name = "WordPress Post" expected_message = "New post published:\n* [New Blog Post](http://example.com\n)" self.check_webhook( "publish_post_type_not_provided", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_publish_post_no_data_provided(self) -> None: # Note: the fixture includes 'hook=publish_post' because it's always added by HookPress - expected_topic = "WordPress notification" + expected_topic_name = "WordPress notification" expected_message = "New post published:\n* [New WordPress post](WordPress post URL)" self.check_webhook( "publish_post_no_data_provided", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_publish_page(self) -> None: - expected_topic = "WordPress Page" + expected_topic_name = "WordPress Page" expected_message = "New page published:\n* [New Blog Page](http://example.com\n)" self.check_webhook( "publish_page", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_user_register(self) -> None: - expected_topic = "New Blog Users" + expected_topic_name = "New Blog Users" expected_message = ( "New blog user registered:\n* **Name**: test_user\n* **Email**: test_user@example.com" ) self.check_webhook( "user_register", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) def test_wp_login(self) -> None: - expected_topic = "New Login" + expected_topic_name = "New Login" expected_message = "User testuser logged in." self.check_webhook( "wp_login", - expected_topic, + expected_topic_name, expected_message, content_type="application/x-www-form-urlencoded", ) diff --git a/zerver/webhooks/wordpress/view.py b/zerver/webhooks/wordpress/view.py index 2c0390eccc..e3f7011c99 100644 --- a/zerver/webhooks/wordpress/view.py +++ b/zerver/webhooks/wordpress/view.py @@ -56,7 +56,7 @@ def api_wordpress_webhook( else: raise JsonableError(_("Unknown WordPress webhook action: {hook}").format(hook=hook)) - topic = "WordPress notification" + topic_name = "WordPress notification" - check_send_webhook_message(request, user_profile, topic, data, hook) + check_send_webhook_message(request, user_profile, topic_name, data, hook) return json_success(request) diff --git a/zerver/webhooks/zabbix/tests.py b/zerver/webhooks/zabbix/tests.py index 9911e3d143..218f028c42 100644 --- a/zerver/webhooks/zabbix/tests.py +++ b/zerver/webhooks/zabbix/tests.py @@ -13,9 +13,9 @@ class ZabbixHookTests(WebhookTestCase): """ Tests if zabbix alert is handled correctly """ - expected_topic = "www.example.com" + expected_topic_name = "www.example.com" expected_message = "PROBLEM (Average) alert on [www.example.com](https://zabbix.example.com/tr_events.php?triggerid=14032&eventid=10528):\n* Zabbix agent on www.example.com is unreachable for 5 minutes\n* Agent ping is Up (1)" - self.check_webhook("zabbix_alert", expected_topic, expected_message) + self.check_webhook("zabbix_alert", expected_topic_name, expected_message) def test_zabbix_invalid_payload_with_missing_data(self) -> None: """ diff --git a/zerver/webhooks/zabbix/view.py b/zerver/webhooks/zabbix/view.py index d4c0298432..eea6d667d8 100644 --- a/zerver/webhooks/zabbix/view.py +++ b/zerver/webhooks/zabbix/view.py @@ -39,7 +39,7 @@ def api_zabbix_webhook( ) -> HttpResponse: try: body = get_body_for_http_request(payload) - topic = get_topic_for_http_request(payload) + topic_name = get_topic_for_http_request(payload) except ValidationError: message = MISCONFIGURED_PAYLOAD_ERROR_MESSAGE.format( bot_name=user_profile.full_name, @@ -49,7 +49,7 @@ def api_zabbix_webhook( raise JsonableError(_("Invalid payload")) - check_send_webhook_message(request, user_profile, topic, body) + check_send_webhook_message(request, user_profile, topic_name, body) return json_success(request) diff --git a/zerver/webhooks/zapier/tests.py b/zerver/webhooks/zapier/tests.py index f442e4d908..2a72deba5d 100644 --- a/zerver/webhooks/zapier/tests.py +++ b/zerver/webhooks/zapier/tests.py @@ -7,21 +7,21 @@ class ZapierHookTests(WebhookTestCase): WEBHOOK_DIR_NAME = "zapier" def test_zapier_when_subject_and_body_are_correct(self) -> None: - expected_topic = "New email from zulip@zulip.com" + expected_topic_name = "New email from zulip@zulip.com" expected_message = "Your email content is: \nMy Email content." - self.check_webhook("correct_subject_and_body", expected_topic, expected_message) + self.check_webhook("correct_subject_and_body", expected_topic_name, expected_message) def test_zapier_when_topic_and_body_are_correct(self) -> None: - expected_topic = "New email from zulip@zulip.com" + expected_topic_name = "New email from zulip@zulip.com" expected_message = "Your email content is: \nMy Email content." - self.check_webhook("correct_topic_and_body", expected_topic, expected_message) + self.check_webhook("correct_topic_and_body", expected_topic_name, expected_message) def test_zapier_weather_update(self) -> None: - expected_topic = "Here is your weather update for the day:" + expected_topic_name = "Here is your weather update for the day:" expected_message = ( "Foggy in the morning.\nMaximum temperature to be 24.\nMinimum temperature to be 12" ) - self.check_webhook("weather_update", expected_topic, expected_message) + self.check_webhook("weather_update", expected_topic_name, expected_message) class ZapierZulipAppTests(WebhookTestCase): diff --git a/zerver/webhooks/zapier/view.py b/zerver/webhooks/zapier/view.py index a961b3fe50..2e93afc5de 100644 --- a/zerver/webhooks/zapier/view.py +++ b/zerver/webhooks/zapier/view.py @@ -31,16 +31,18 @@ def api_zapier_webhook( }, ) - topic = payload.get("topic").tame(check_none_or(check_string)) + topic_name = payload.get("topic").tame(check_none_or(check_string)) content = payload.get("content").tame(check_none_or(check_string)) - if topic is None: - topic = payload.get("subject").tame(check_none_or(check_string)) # Backwards-compatibility - if topic is None: + if topic_name is None: + topic_name = payload.get("subject").tame( + check_none_or(check_string) + ) # Backwards-compatibility + if topic_name is None: raise JsonableError(_("Topic can't be empty")) if content is None: raise JsonableError(_("Content can't be empty")) - check_send_webhook_message(request, user_profile, topic, content) + check_send_webhook_message(request, user_profile, topic_name, content) return json_success(request) diff --git a/zerver/webhooks/zendesk/view.py b/zerver/webhooks/zendesk/view.py index 896e3d16b8..e168dfa7fa 100644 --- a/zerver/webhooks/zendesk/view.py +++ b/zerver/webhooks/zendesk/view.py @@ -29,6 +29,6 @@ def api_zendesk_webhook( ticket_id and ticket_title to create a topic. And passes with zendesk user's configured message to zulip. """ - topic = truncate(f"#{ticket_id}: {ticket_title}", 60) - check_send_webhook_message(request, user_profile, topic, message) + topic_name = truncate(f"#{ticket_id}: {ticket_title}", 60) + check_send_webhook_message(request, user_profile, topic_name, message) return json_success(request)