webhooks: Rename *topic local variables to *topic_name.

This is preparatory work towards adding a Topic model.
We plan to use the local variable name as 'topic' for
the Topic model objects.

Currently, we use *topic as the local variable name for
topic names.

We rename local variables of the form *topic to *topic_name
so that we don't need to think about type collisions in
individual code paths where we might want to talk about both
Topic objects and strings for the topic name.
This commit is contained in:
Prakhar Pratyush 2024-01-17 20:23:30 +05:30 committed by Tim Abbott
parent 030f899195
commit 3afc8ed7ae
163 changed files with 1725 additions and 1619 deletions

View File

@ -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)

View File

@ -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)

View File

@ -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",
)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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",
)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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)

View File

@ -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"
)

View File

@ -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)

View File

@ -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)

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -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):

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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),
)

View File

@ -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]]] = {

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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",
)

View File

@ -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)

View File

@ -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: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
@ -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: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
@ -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: <a href='https://deskdotcomtest.desk.com/web/agent/case/2'>"
@ -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",
)

View File

@ -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)

View File

@ -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",
)

View File

@ -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:

View File

@ -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)

View File

@ -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)

View File

@ -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"
)

View File

@ -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)

View File

@ -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 <requester-bob@example.com> 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 <requester-bob@example.com> updated [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11):
@ -49,7 +49,7 @@ Requester Bob <requester-bob@example.com> 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 <requester-bob@example.com> 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 <requester-bob@example.com> updated [ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11):
@ -68,7 +68,7 @@ Requester Bob <requester-bob@example.com> 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 <requester-bob@example.com> 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 <requester-bob@example.com> added a {} note to \
[ticket #11](http://test1234zzz.freshdesk.com/helpdesk/tickets/11).
@ -104,7 +104,7 @@ Requester Bob <requester-bob@example.com> 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 <requester-bob@example.com> 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 <requester-bob@example.com> 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",
)

View File

@ -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)

View File

@ -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)

View File

@ -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:

View File

@ -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:
"""

View File

@ -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)

View File

@ -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",
)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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(

View File

@ -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~~~"

View File

@ -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)

View File

@ -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
)

View File

@ -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)

View File

@ -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",
)

View File

@ -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)

View File

@ -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(

View File

@ -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)

View File

@ -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",
)

View File

@ -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")

View File

@ -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",
)

View File

@ -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)

View File

@ -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")

View File

@ -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)

View File

@ -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",
)

View File

@ -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)

View File

@ -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)

View File

@ -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)

View File

@ -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

View File

@ -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"})

View File

@ -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",
)

View File

@ -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)

View File

@ -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",
)

View File

@ -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",
)

View File

@ -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)

View File

@ -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()

View File

@ -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)

View File

@ -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",
)

View File

@ -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)

View File

@ -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,
)

View File

@ -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)

View File

@ -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 its pretty important. Ill 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 its pretty important. Ill 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! Im 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! Im 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:

View File

@ -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)

View File

@ -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)

View File

@ -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
)

View File

@ -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)

View File

@ -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",
)

View File

@ -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)

View File

@ -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
)

View File

@ -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:

View File

@ -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")

View File

@ -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)

View File

@ -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",
)

View File

@ -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)

View File

@ -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",
)

View File

@ -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)

Some files were not shown because too many files have changed in this diff Show More