webhook tests: Rename main helper to check_webhook.

Almost all webhook tests use this helper, except a few
webhooks that write to private streams.

Being concise is important here, and the name
`self.send_and_test_stream_message` always confused
me, since it sounds you're sending a stream message,
and it leaves out the webhook piece.

We should consider renaming `send_and_test_private_message`
to something like `check_webhook_private`, but I couldn't
decide on a great name, and it's very rarely used.  So
for now I just made sure the docstrings of the two
sibling functions reference each other.
This commit is contained in:
Steve Howell
2020-08-23 13:49:24 +00:00
committed by Tim Abbott
parent 00001a396b
commit 388053db6b
71 changed files with 1726 additions and 1467 deletions

View File

@@ -17,83 +17,83 @@ class GiteaHookTests(WebhookTestCase):
* commit ([6773eab](https://try.gitea.io/kostekIV/test/commit/6773eabc0778a3e38997c06a13f5f0c48b67e5dc))
* commit ([337402c](https://try.gitea.io/kostekIV/test/commit/337402cf675ce7082ddcd23d06a116c85241825a))
* commit ([0a38cad](https://try.gitea.io/kostekIV/test/commit/0a38cad3fac3a13bb78b738d13f15ce9cc3343fa))"""
self.send_and_test_stream_message('push__5_commits', expected_topic, expected_message)
self.check_webhook("push__5_commits", expected_topic, expected_message)
def test_new_branch(self) -> None:
expected_topic = "test / test-branch"
expected_message = "kostekIV created [test-branch](https://try.gitea.io/kostekIV/test/src/test-branch) branch."
self.send_and_test_stream_message('create__branch', expected_topic, expected_message)
self.check_webhook("create__branch", expected_topic, expected_message)
def test_pull_request_opened(self) -> None:
expected_topic = "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.send_and_test_stream_message('pull_request__opened', expected_topic, expected_message)
self.check_webhook("pull_request__opened", expected_topic, expected_message)
def test_pull_request_merged(self) -> None:
expected_topic = "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.send_and_test_stream_message('pull_request__merged', expected_topic, expected_message)
self.check_webhook("pull_request__merged", expected_topic, expected_message)
def test_pull_request_edited(self) -> None:
expected_topic = "test / PR #1906 test 2"
expected_message = """kostekIV edited [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) from `d` to `master`."""
self.send_and_test_stream_message('pull_request__edited', expected_topic, expected_message)
self.check_webhook("pull_request__edited", expected_topic, expected_message)
def test_pull_request_reopened(self) -> None:
expected_topic = "test / PR #1906 test 2"
expected_message = """kostekIV reopened [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) from `d` to `master`."""
self.send_and_test_stream_message('pull_request__reopened', expected_topic, expected_message)
self.check_webhook("pull_request__reopened", expected_topic, expected_message)
def test_pull_request_closed(self) -> None:
expected_topic = "test / PR #1906 test 2"
expected_message = """kostekIV closed [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) from `d` to `master`."""
self.send_and_test_stream_message('pull_request__closed', expected_topic, expected_message)
self.check_webhook("pull_request__closed", expected_topic, expected_message)
def test_pull_request_assigned(self) -> None:
expected_topic = "test / PR #1906 test 2"
expected_message = """kostekIV assigned [PR #5](https://try.gitea.io/kostekIV/test/pulls/5) (assigned to kostekIV) from `d` to `master`."""
self.send_and_test_stream_message('pull_request__assigned', expected_topic, expected_message)
self.check_webhook("pull_request__assigned", expected_topic, expected_message)
def test_issues_opened(self) -> None:
expected_topic = "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.send_and_test_stream_message('issues__opened', expected_topic, expected_message)
self.check_webhook("issues__opened", expected_topic, expected_message)
def test_issues_edited(self) -> None:
expected_topic = "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.send_and_test_stream_message('issues__edited', expected_topic, expected_message)
self.check_webhook("issues__edited", expected_topic, expected_message)
def test_issues_closed(self) -> None:
expected_topic = "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.send_and_test_stream_message('issues__closed', expected_topic, expected_message)
self.check_webhook("issues__closed", expected_topic, expected_message)
def test_issues_assigned(self) -> None:
expected_topic = "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.send_and_test_stream_message('issues__assigned', expected_topic, expected_message)
self.check_webhook("issues__assigned", expected_topic, expected_message)
def test_issues_reopened(self) -> None:
expected_topic = "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.send_and_test_stream_message('issues__reopened', expected_topic, expected_message)
self.check_webhook("issues__reopened", expected_topic, expected_message)
def test_issue_comment_new(self) -> None:
expected_topic = "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.send_and_test_stream_message('issue_comment__new', expected_topic, expected_message)
self.check_webhook("issue_comment__new", expected_topic, expected_message)
def test_issue_comment_in_pr(self) -> None:
expected_topic = "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.send_and_test_stream_message('issue_comment__in_pr', expected_topic, expected_message)
self.check_webhook("issue_comment__in_pr", expected_topic, expected_message)
def test_issue_comment_edited(self) -> None:
expected_topic = "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.send_and_test_stream_message('issue_comment__edited', expected_topic, expected_message)
self.check_webhook("issue_comment__edited", expected_topic, expected_message)
@patch('zerver.webhooks.gogs.view.check_send_webhook_message')
def test_push_filtered_by_branches_ignore(self, check_send_webhook_message_mock: MagicMock) -> None: