integrations: Add additional tests to the Clubhouse integration.

Fixes: #18022
This commit is contained in:
PIG208
2021-04-11 09:23:50 +08:00
committed by Tim Abbott
parent f5528c38c2
commit 191041f80f
5 changed files with 353 additions and 1 deletions

View File

@@ -0,0 +1,97 @@
{
"id": "60718721-b87c-4405-96aa-38db82c693de",
"changed_at": "2021-04-10T11:08:17.962Z",
"version": "v1",
"primary_id": 500000032,
"actions": [
{
"id": 500000032,
"entity_type": "pull-request",
"action": "create",
"number": 2,
"title": "Testing pull requests with Story",
"url": "https://github.com/PIG208/test-clubhouse/pull/2"
},
{
"id": 500000031,
"entity_type": "branch",
"action": "create",
"name": "two",
"url": "https://github.com/PIG208/test-clubhouse/tree/two"
},
{
"id": 17,
"entity_type": "story",
"action": "update",
"name": "Story1",
"story_type": "feature",
"app_url": "https://app.clubhouse.io/pig208/story/17",
"changes": {
"pull_request_ids": {
"adds": [
500000032
]
},
"started": {
"new": true,
"old": false
},
"position": {
"new": 32147680256,
"old": 12147614720
},
"workflow_state_id": {
"new": 500000006,
"old": 500000008
},
"started_at": {
"new": "2021-04-10T11:08:17Z"
}
}
},
{
"id": 18,
"entity_type": "story",
"action": "update",
"name": "Story2",
"story_type": "feature",
"app_url": "https://app.clubhouse.io/pig208/story/18",
"changes": {
"pull_request_ids": {
"adds": [
500000032
]
},
"started": {
"new": true,
"old": false
},
"position": {
"new": 32147745792,
"old": 12147680256
},
"workflow_state_id": {
"new": 500000006,
"old": 500000008
},
"started_at": {
"new": "2021-04-10T11:08:17Z"
}
}
}
],
"references": [
{
"id": 500000006,
"entity_type": "workflow-state",
"name": "In Development",
"type": "started"
},
{
"id": 500000008,
"entity_type": "workflow-state",
"name": "Unscheduled",
"type": "unstarted"
}
]
}

View File

@@ -0,0 +1,90 @@
{
"id": "60721a44-7d30-476b-ae19-514a47359c42",
"changed_at": "2021-04-10T21:36:04.138Z",
"version": "v1",
"primary_id": 500000029,
"actions": [
{
"id": 500000029,
"entity_type": "pull-request",
"action": "comment",
"number": 1,
"title": "readme: Update README.md.",
"url": "https://github.com/PIG208/test-clubhouse/pull/1"
},
{
"id": 26,
"entity_type": "story",
"action": "update",
"name": "new1",
"story_type": "feature",
"app_url": "https://app.clubhouse.io/pig208/story/26",
"changes": {
"pull_request_ids": {
"adds": [
500000029
]
},
"started": {
"new": true,
"old": false
},
"position": {
"new": 32147549184,
"old": 12147549184
},
"workflow_state_id": {
"new": 500000006,
"old": 500000008
},
"started_at": {
"new": "2021-04-10T21:36:03Z"
}
}
},
{
"id": 27,
"entity_type": "story",
"action": "update",
"name": "new2",
"story_type": "feature",
"app_url": "https://app.clubhouse.io/pig208/story/27",
"changes": {
"pull_request_ids": {
"adds": [
500000029
]
},
"started": {
"new": true,
"old": false
},
"position": {
"new": 32147614720,
"old": 12147614720
},
"workflow_state_id": {
"new": 500000006,
"old": 500000008
},
"started_at": {
"new": "2021-04-10T21:36:03Z"
}
}
}
],
"references": [
{
"id": 500000006,
"entity_type": "workflow-state",
"name": "In Development",
"type": "started"
},
{
"id": 500000008,
"entity_type": "workflow-state",
"name": "Unscheduled",
"type": "unstarted"
}
]
}

View File

@@ -0,0 +1,32 @@
{
"id": "6071f11a-1681-41f8-afa8-fd24ae747a5d",
"changed_at": "2021-04-10T18:40:26.876Z",
"version": "v1",
"primary_id": 500000032,
"actions": [
{
"id": 500000032,
"entity_type": "pull-request",
"action": "comment",
"number": 2,
"title": "Two",
"url": "https://github.com/PIG208/test-clubhouse/pull/2"
},
{
"id": 15,
"entity_type": "story",
"action": "update",
"name": "asd2",
"story_type": "bug",
"app_url": "https://app.clubhouse.io/pig208/story/15",
"changes":
{
"pull_request_ids": {
"adds": [
500000032
]
}
}
}
]
}

View File

@@ -0,0 +1,55 @@
{
"changed_at":"2019-01-24T02:18:20.031Z",
"primary_id":500000035,
"references":[
{
"id":500000010,
"entity_type":"workflow-state",
"name":"Ready for Review",
"type":"started"
},
{
"id":500000008,
"entity_type":"workflow-state",
"name":"Unscheduled",
"type":"unstarted"
}
],
"actions":[
{
"id":500000035,
"entity_type":"pull-request",
"action":"create",
"number":10,
"title":"Testing pull requests with Story",
"url":"https://github.com/eeshangarg/Scheduler/pull/10"
},
{
"id":28,
"entity_type":"story",
"action":"update",
"name":"Testing pull requests with Story",
"story_type":"feature",
"app_url":"https://app.clubhouse.io/zulip/story/28",
"changes":{
"started":{
"new":true,
"old":false
},
"pull_request_ids": {
"adds": [
500000035
]
},
"started_at":{
"new":"2019-01-24T02:18:20Z"
}
}
}
],
"member_id":"5b1fda16-626f-487f-9ecf-f3a4abf42b8b",
"external_id":"50e81c40-1f7e-11e9-8645-17f96d5e1138",
"id":"5c49206c-506f-4312-a1b1-b1b8bfccbc9b",
"version":"v1",
"webhook_id":"5c491814-1d65-44c4-92af-aece6fc41092"
}

View File

@@ -1,5 +1,5 @@
import json import json
from unittest.mock import MagicMock, patch from unittest.mock import MagicMock, call, patch
from zerver.lib.test_classes import WebhookTestCase from zerver.lib.test_classes import WebhookTestCase
@@ -201,6 +201,84 @@ class ClubhouseWebhookTest(WebhookTestCase):
expected_message, expected_message,
) )
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"
),
),
call(
request,
user_profile,
"Story2",
expected_message.format(
name="Story2", url="https://app.clubhouse.io/pig208/story/18"
),
),
]
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"
),
),
call(
request,
user_profile,
"new2",
expected_message.format(
name="new2", url="https://app.clubhouse.io/pig208/story/27"
),
),
]
self.assertEqual(check_send_webhook_message_mock.call_args_list, expected_list)
def test_story_update_add_github_branch(self) -> None: 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)." 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)."
self.check_webhook( self.check_webhook(