2018-12-18 00:29:08 +01:00
import json
2021-04-11 03:23:50 +02:00
from unittest . mock import MagicMock , call , patch
2018-06-19 01:54:57 +02:00
from zerver . lib . test_classes import WebhookTestCase
2020-01-14 22:06:24 +01:00
2018-06-19 01:54:57 +02:00
class ClubhouseWebhookTest ( WebhookTestCase ) :
2021-02-12 08:20:45 +01:00
STREAM_NAME = " clubhouse "
2018-06-19 01:54:57 +02:00
URL_TEMPLATE = " /api/v1/external/clubhouse?stream= {stream} &api_key= {api_key} "
2021-06-26 09:18:33 +02:00
WEBHOOK_DIR_NAME = " clubhouse "
2018-06-19 01:54:57 +02:00
def test_story_create ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " New story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) of type **feature** was created. "
2020-08-23 15:49:24 +02:00
self . check_webhook (
2021-02-12 08:19:30 +01:00
" story_create " ,
" Add cool feature! " ,
expected_message ,
2018-06-19 01:54:57 +02:00
)
2018-12-18 00:00:25 +01:00
def test_story_delete ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The story **New random story** was deleted. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_delete " , " New random story " , expected_message )
2018-12-18 00:00:25 +01:00
2018-06-19 01:54:57 +02:00
def test_epic_story_create ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " New story [An epic story!](https://app.clubhouse.io/zulip/story/23) was created and added to the epic **New Cool Epic!**. "
2020-08-23 15:49:24 +02:00
self . check_webhook (
2021-02-12 08:19:30 +01:00
" epic_create_story " ,
" An epic story! " ,
expected_message ,
2018-06-19 01:54:57 +02:00
)
2018-12-18 00:00:25 +01:00
def test_epic_delete ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The epic **Clubhouse Fork** was deleted. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " epic_delete " , " Clubhouse Fork " , expected_message )
2018-12-18 00:00:25 +01:00
2018-06-19 01:54:57 +02:00
def test_story_archive ( self ) - > None :
2021-02-12 08:19:30 +01:00
expected_message = (
" The story [Story 2](https://app.clubhouse.io/zulip/story/9) was archived. "
)
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_archive " , " Story 2 " , expected_message )
2018-06-19 01:54:57 +02:00
2019-02-20 23:44:42 +01:00
def test_epic_archive ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The epic **Zulip is epic!** was archived. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " epic_archive " , " Zulip is epic! " , expected_message )
2019-02-20 23:44:42 +01:00
2018-06-19 01:54:57 +02:00
def test_story_unarchive ( self ) - > None :
2021-02-12 08:19:30 +01:00
expected_message = (
" The story [Story 2](https://app.clubhouse.io/zulip/story/9) was unarchived. "
)
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_unarchive " , " Story 2 " , expected_message )
2018-06-19 01:54:57 +02:00
def test_epic_create ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " New epic **New Epic!**(to do) was created. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " epic_create " , " New Epic! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_epic_update_add_comment ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " New comment added to the epic **New Cool Epic!**: \n ``` quote \n Added a comment on this Epic! \n ``` "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " epic_update_add_comment " , " New Cool Epic! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_update_add_comment ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " New comment added to the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11): \n ``` quote \n Just leaving a comment here! \n ``` "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_add_comment " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_epic_update_add_description ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " New description added to the epic **New Cool Epic!**: \n ``` quote \n Added a description! \n ``` "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " epic_update_add_description " , " New Cool Epic! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_epic_update_remove_description ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " Description for the epic **New Cool Epic!** was removed. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " epic_update_remove_description " , " New Cool Epic! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_epic_update_change_description ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " Description for the epic **New Cool Epic!** was changed from: \n ``` quote \n Added a description! \n ``` \n to \n ``` quote \n Changed a description! \n ``` "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " epic_update_change_description " , " New Cool Epic! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_update_add_description ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " New description added to the story [Story 2](https://app.clubhouse.io/zulip/story/9): \n ``` quote \n Added a description. \n ``` "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_add_description " , " Story 2 " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_update_remove_description ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " Description for the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was removed. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_remove_description " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_update_change_description ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " Description for the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was changed from: \n ``` quote \n We should probably add this cool feature! \n ``` \n to \n ``` quote \n We should probably add this cool feature! Just edited this. :) \n ``` "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_description " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_epic_update_change_state ( self ) - > None :
2021-02-12 08:19:30 +01:00
expected_message = (
" State of the epic **New Cool Epic!** was changed from **to do** to **in progress**. "
)
2020-08-23 15:49:24 +02:00
self . check_webhook ( " epic_update_change_state " , " New Cool Epic! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_update_change_state ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " State of the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was changed from **Unscheduled** to **Ready for Review**. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_change_state " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_epic_update_change_name ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The name of the epic **New Cool Epic!** was changed from: \n ``` quote \n New Epic! \n ``` \n to \n ``` quote \n New Cool Epic! \n ``` "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " epic_update_change_title " , " New Cool Epic! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_update_change_name ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The name of the story [Add super cool feature!](https://app.clubhouse.io/zulip/story/11) was changed from: \n ``` quote \n Add cool feature! \n ``` \n to \n ``` quote \n Add super cool feature! \n ``` "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_change_title " , " Add super cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
2019-01-04 23:10:07 +01:00
def test_story_update_add_owner ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " New owner added to the story [A new story by Shakespeare!](https://app.clubhouse.io/zulip/story/26). "
2020-08-23 15:49:24 +02:00
self . check_webhook (
" story_update_add_owner " , " A new story by Shakespeare! " , expected_message
)
2019-01-04 23:10:07 +01:00
2018-06-19 01:54:57 +02:00
def test_story_task_created ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " Task **Added a new task** was added to the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11). "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_task_create " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_task_deleted ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " Task **Added a new task** was removed from the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11). "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_task_delete " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_task_completed ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " Task **A new task for this story** ([Add cool feature!](https://app.clubhouse.io/zulip/story/11)) was completed. :tada: "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_task_complete " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
2021-04-11 01:26:00 +02:00
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
2021-02-12 08:19:30 +01:00
def test_story_task_incomplete_ignore ( self , check_send_webhook_message_mock : MagicMock ) - > None :
2021-02-12 08:20:45 +01:00
payload = self . get_body ( " story_task_not_complete " )
2018-06-19 01:54:57 +02:00
result = self . client_post ( self . url , payload , content_type = " application/json " )
self . assertFalse ( check_send_webhook_message_mock . called )
self . assert_json_success ( result )
def test_story_epic_changed ( self ) - > None :
2021-02-12 08:19:30 +01:00
expected_message = (
" The story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was moved from **Release 1.9** "
" to **Clubhouse Fork**. "
)
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_change_epic " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_epic_added ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was added to the epic **Release 1.9**. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_add_epic " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_epic_removed ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was removed from the epic **Release 1.9**. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_remove_epic " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_estimate_changed ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The estimate for the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was set to 4 points. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_change_estimate " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_estimate_added ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The estimate for the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was set to 4 points. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_add_estimate " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_estimate_removed ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The estimate for the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was set to *Unestimated*. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_remove_estimate " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_file_attachment_added ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " A file attachment `zuliprc` was added to the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11). "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_add_attachment " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
2021-04-11 01:26:00 +02:00
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
2018-06-19 01:54:57 +02:00
def test_story_file_attachment_removed_ignore (
2021-02-12 08:19:30 +01:00
self , check_send_webhook_message_mock : MagicMock
) - > None :
2021-02-12 08:20:45 +01:00
payload = self . get_body ( " story_update_remove_attachment " )
2018-06-19 01:54:57 +02:00
result = self . client_post ( self . url , payload , content_type = " application/json " )
self . assertFalse ( check_send_webhook_message_mock . called )
self . assert_json_success ( result )
def test_story_label_added ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The label **mockup** was added to the story [An epic story!](https://app.clubhouse.io/zulip/story/23). "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_add_label " , " An epic story! " , expected_message )
2018-06-19 01:54:57 +02:00
2021-04-11 19:44:35 +02:00
def test_story_label_multiple_added ( self ) - > None :
expected_message = " The labels **mockup**, **label** were added to the story [An epic story!](https://app.clubhouse.io/zulip/story/23). "
self . check_webhook ( " story_update_add_multiple_labels " , " An epic story! " , expected_message )
2019-01-25 00:04:21 +01:00
def test_story_label_added_label_name_in_actions ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The label **sad** was added to the story [An emotional story!](https://app.clubhouse.io/zulip/story/28). "
2020-08-23 15:49:24 +02:00
self . check_webhook (
" story_update_add_label_name_in_action " , " An emotional story! " , expected_message
)
2019-01-25 00:04:21 +01:00
2021-04-11 01:26:00 +02:00
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
2021-02-12 08:19:30 +01:00
def test_story_label_removed_ignore ( self , check_send_webhook_message_mock : MagicMock ) - > None :
2021-02-12 08:20:45 +01:00
payload = self . get_body ( " story_update_remove_label " )
2018-06-19 01:54:57 +02:00
result = self . client_post ( self . url , payload , content_type = " application/json " )
self . assertFalse ( check_send_webhook_message_mock . called )
self . assert_json_success ( result )
def test_story_update_project ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was moved from the **Backend** project to **Devops**. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_change_project " , " Add cool feature! " , expected_message )
2018-06-19 01:54:57 +02:00
def test_story_update_type ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " The type of the story [Add cool feature!](https://app.clubhouse.io/zulip/story/11) was changed from **feature** to **bug**. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " story_update_change_type " , " Add cool feature! " , expected_message )
2018-12-18 00:29:08 +01:00
2019-01-24 04:28:54 +01:00
def test_story_update_add_github_pull_request ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " New GitHub PR [#10](https://github.com/eeshangarg/Scheduler/pull/10) opened for story [Testing pull requests with Story](https://app.clubhouse.io/zulip/story/28) (Unscheduled -> Ready for Review). "
2020-08-23 15:49:24 +02:00
self . check_webhook (
" story_update_add_github_pull_request " ,
" Testing pull requests with Story " ,
expected_message ,
)
2019-01-24 04:28:54 +01:00
2021-04-11 03:23:50 +02:00
def test_story_update_add_github_pull_request_without_workflow_state ( self ) - > None :
expected_message = " New GitHub PR [#10](https://github.com/eeshangarg/Scheduler/pull/10) opened for story [Testing pull requests with Story](https://app.clubhouse.io/zulip/story/28). "
self . check_webhook (
" story_update_add_github_pull_request_without_workflow_state " ,
" Testing pull requests with Story " ,
expected_message ,
)
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
def test_story_update_add_github_multiple_pull_requests (
self , check_send_webhook_message_mock : MagicMock
) - > None :
payload = self . get_body ( " story_update_add_github_multiple_pull_requests " )
self . client_post ( self . url , payload , content_type = " application/json " )
expected_message = " New GitHub PR [#2](https://github.com/PIG208/test-clubhouse/pull/2) opened for story [ {name} ]( {url} ) (Unscheduled -> In Development). "
request , user_profile = (
check_send_webhook_message_mock . call_args_list [ 0 ] [ 0 ] [ 0 ] ,
check_send_webhook_message_mock . call_args_list [ 0 ] [ 0 ] [ 1 ] ,
)
expected_list = [
call (
request ,
user_profile ,
" Story1 " ,
expected_message . format (
name = " Story1 " , url = " https://app.clubhouse.io/pig208/story/17 "
) ,
2021-07-16 11:40:46 +02:00
" pull-request_create " ,
2021-04-11 03:23:50 +02:00
) ,
call (
request ,
user_profile ,
" Story2 " ,
expected_message . format (
name = " Story2 " , url = " https://app.clubhouse.io/pig208/story/18 "
) ,
2021-07-16 11:40:46 +02:00
" pull-request_create " ,
2021-04-11 03:23:50 +02:00
) ,
]
self . assertEqual ( check_send_webhook_message_mock . call_args_list , expected_list )
def test_story_update_add_github_pull_request_with_comment ( self ) - > None :
expected_message = " Existing GitHub PR [#2](https://github.com/PIG208/test-clubhouse/pull/2) associated with story [asd2](https://app.clubhouse.io/pig208/story/15). "
self . check_webhook (
" story_update_add_github_pull_request_with_comment " ,
" asd2 " ,
expected_message ,
)
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
def test_story_update_add_github_multiple_pull_requests_with_comment (
self , check_send_webhook_message_mock : MagicMock
) - > None :
payload = self . get_body ( " story_update_add_github_multiple_pull_requests_with_comment " )
self . client_post ( self . url , payload , content_type = " application/json " )
expected_message = " Existing GitHub PR [#1](https://github.com/PIG208/test-clubhouse/pull/1) associated with story [ {name} ]( {url} ) (Unscheduled -> In Development). "
request , user_profile = (
check_send_webhook_message_mock . call_args_list [ 0 ] [ 0 ] [ 0 ] ,
check_send_webhook_message_mock . call_args_list [ 0 ] [ 0 ] [ 1 ] ,
)
expected_list = [
call (
request ,
user_profile ,
" new1 " ,
expected_message . format (
name = " new1 " , url = " https://app.clubhouse.io/pig208/story/26 "
) ,
2021-07-16 11:40:46 +02:00
" pull-request_comment " ,
2021-04-11 03:23:50 +02:00
) ,
call (
request ,
user_profile ,
" new2 " ,
expected_message . format (
name = " new2 " , url = " https://app.clubhouse.io/pig208/story/27 "
) ,
2021-07-16 11:40:46 +02:00
" pull-request_comment " ,
2021-04-11 03:23:50 +02:00
) ,
]
self . assertEqual ( check_send_webhook_message_mock . call_args_list , expected_list )
2019-01-24 04:28:54 +01:00
def test_story_update_add_github_branch ( self ) - > None :
expected_message = " New GitHub branch [eeshangarg/ch27/testing-pull-requests-with-story](https://github.com/eeshangarg/scheduler/tree/eeshangarg/ch27/testing-pull-requests-with-story) associated with story [Testing pull requests with Story](https://app.clubhouse.io/zulip/story/27) (Unscheduled -> In Development). "
2020-08-23 15:49:24 +02:00
self . check_webhook (
" story_update_add_github_branch " , " Testing pull requests with Story " , expected_message
)
2019-01-24 04:28:54 +01:00
2021-04-11 19:47:20 +02:00
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
def test_story_update_batch ( self , check_send_webhook_message_mock : MagicMock ) - > None :
payload = self . get_body ( " story_update_everything_at_once " )
self . client_post ( self . url , payload , content_type = " application/json " )
expected_message = " The story [ {name} ]( {url} ) was moved from Epic **epic** to **testeipc**, Project **Product Development** to **test2**, and changed from type **feature** to **bug**, and added with the new label **low priority** (In Development -> Ready for Review). "
request , user_profile = (
check_send_webhook_message_mock . call_args_list [ 0 ] [ 0 ] [ 0 ] ,
check_send_webhook_message_mock . call_args_list [ 0 ] [ 0 ] [ 1 ] ,
)
expected_list = [
call (
request ,
2021-08-20 20:43:15 +02:00
user_profile ,
" asd4 " ,
expected_message . format (
name = " asd4 " , url = " https://app.clubhouse.io/pig208/story/17 "
) ,
" story_update_batch " ,
) ,
call (
request ,
user_profile ,
" new1 " ,
expected_message . format (
name = " new1 " , url = " https://app.clubhouse.io/pig208/story/26 "
) ,
" story_update_batch " ,
) ,
call (
request ,
user_profile ,
" new2 " ,
expected_message . format (
name = " new2 " , url = " https://app.clubhouse.io/pig208/story/27 "
) ,
" story_update_batch " ,
) ,
]
self . assertEqual ( check_send_webhook_message_mock . call_args_list , expected_list )
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
def test_story_update_batch_skip_removed_labels (
self , check_send_webhook_message_mock : MagicMock
) - > None :
payload = self . get_body ( " story_update_everything_at_once_skip_removed_labels " )
self . client_post ( self . url , payload , content_type = " application/json " )
expected_message = " The story [ {name} ]( {url} ) was moved from Epic **epic** to **testeipc**, Project **Product Development** to **test2**, and changed from type **feature** to **bug** (In Development -> Ready for Review). "
request , user_profile = (
check_send_webhook_message_mock . call_args_list [ 0 ] [ 0 ] [ 0 ] ,
check_send_webhook_message_mock . call_args_list [ 0 ] [ 0 ] [ 1 ] ,
)
expected_list = [
call (
request ,
2021-04-11 19:47:20 +02:00
user_profile ,
" asd4 " ,
expected_message . format (
name = " asd4 " , url = " https://app.clubhouse.io/pig208/story/17 "
) ,
2021-07-16 11:40:46 +02:00
" story_update_batch " ,
2021-04-11 19:47:20 +02:00
) ,
call (
request ,
user_profile ,
" new1 " ,
expected_message . format (
name = " new1 " , url = " https://app.clubhouse.io/pig208/story/26 "
) ,
2021-07-16 11:40:46 +02:00
" story_update_batch " ,
2021-04-11 19:47:20 +02:00
) ,
call (
request ,
user_profile ,
" new2 " ,
expected_message . format (
name = " new2 " , url = " https://app.clubhouse.io/pig208/story/27 "
) ,
2021-07-16 11:40:46 +02:00
" story_update_batch " ,
2021-04-11 19:47:20 +02:00
) ,
]
self . assertEqual ( check_send_webhook_message_mock . call_args_list , expected_list )
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
def test_story_update_batch_each_with_one_change (
self , check_send_webhook_message_mock : MagicMock
) - > None :
payload = self . get_body ( " story_update_multiple_at_once " )
self . client_post ( self . url , payload , content_type = " application/json " )
expected_messages = [
(
" asd4 " ,
" The type of the story [asd4](https://app.clubhouse.io/pig208/story/17) was changed from **feature** to **bug**. " ,
) ,
(
" new1 " ,
" The story [new1](https://app.clubhouse.io/pig208/story/26) was moved from **epic** to **testeipc**. " ,
) ,
(
" new2 " ,
" The label **low priority** was added to the story [new2](https://app.clubhouse.io/pig208/story/27). " ,
) ,
(
" new3 " ,
" State of the story [new3](https://app.clubhouse.io/pig208/story/28) was changed from **In Development** to **Ready for Review**. " ,
) ,
(
" new4 " ,
" The story [new4](https://app.clubhouse.io/pig208/story/29) was moved from the **Product Development** project to **test2**. " ,
) ,
]
request , user_profile = (
check_send_webhook_message_mock . call_args_list [ 0 ] [ 0 ] [ 0 ] ,
check_send_webhook_message_mock . call_args_list [ 0 ] [ 0 ] [ 1 ] ,
)
expected_list = [
call (
request ,
user_profile ,
expected_message [ 0 ] ,
expected_message [ 1 ] ,
2021-07-16 11:40:46 +02:00
" story_update_batch " ,
2021-04-11 19:47:20 +02:00
)
for expected_message in expected_messages
]
self . assertEqual ( check_send_webhook_message_mock . call_args_list , expected_list )
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
def test_story_update_batch_not_supported_ignore (
self , check_send_webhook_message_mock : MagicMock
) - > None :
payload = self . get_body ( " story_update_multiple_not_supported " )
result = self . client_post ( self . url , payload , content_type = " application/json " )
self . assertFalse ( check_send_webhook_message_mock . called )
self . assert_json_success ( result )
2021-04-11 01:26:00 +02:00
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
2021-02-12 08:19:30 +01:00
def test_empty_post_request_body_ignore (
self , check_send_webhook_message_mock : MagicMock
) - > None :
2018-12-18 00:29:08 +01:00
payload = json . dumps ( None )
result = self . client_post ( self . url , payload , content_type = " application/json " )
self . assertFalse ( check_send_webhook_message_mock . called )
self . assert_json_success ( result )
2019-02-20 23:21:14 +01:00
2021-04-11 01:26:00 +02:00
@patch ( " zerver.webhooks.clubhouse.view.check_send_webhook_message " )
2019-02-20 23:21:14 +01:00
def test_story_comment_updated_ignore ( self , check_send_webhook_message_mock : MagicMock ) - > None :
2021-02-12 08:20:45 +01:00
payload = self . get_body ( " story_comment_updated " )
2019-02-20 23:21:14 +01:00
result = self . client_post ( self . url , payload , content_type = " application/json " )
self . assertFalse ( check_send_webhook_message_mock . called )
self . assert_json_success ( result )