webhooks: Move all fixtures to zerver/webhooks/<webhook_name>/fixtures.

All webhook fixtures in zerver/fixtures/<webhook_name> have now
been moved to dedicated webhook-specific directories under
zerver/webhooks/<webhook_name>/fixtures, where <webhook_name> is
the name of the webhook.
This commit is contained in:
Eeshan Garg
2017-04-27 16:49:05 -02:30
committed by Tim Abbott
parent dcc2b3a900
commit aa12002be7
381 changed files with 414 additions and 39 deletions

View File

@@ -410,7 +410,7 @@ class ZulipTestCase(TestCase):
def fixture_data(self, type, action, file_type='json'):
# type: (Text, Text, Text) -> Text
return force_text(open(os.path.join(os.path.dirname(__file__),
"../fixtures/%s/%s_%s.%s" % (type, type, action, file_type))).read())
"../webhooks/%s/fixtures/%s_%s.%s" % (type, type, action, file_type))).read())
def make_stream(self, stream_name, realm=None, invite_only=False):
# type: (Text, Optional[Realm], Optional[bool]) -> Stream

View File

@@ -7,7 +7,7 @@ from zerver.lib.test_classes import WebhookTestCase
class Bitbucket2HookTests(WebhookTestCase):
STREAM_NAME = 'bitbucket2'
URL_TEMPLATE = "/api/v1/external/bitbucket2?stream={stream}&api_key={api_key}"
FIXTURE_DIR_NAME = 'bitbucket'
FIXTURE_DIR_NAME = 'bitbucket2'
EXPECTED_SUBJECT = u"Repository name"
EXPECTED_SUBJECT_PR_EVENTS = u"Repository name / PR #1 new commit"
EXPECTED_SUBJECT_ISSUE_EVENTS = u"Repository name / Issue #1 Bug"
@@ -17,40 +17,40 @@ class Bitbucket2HookTests(WebhookTestCase):
# type: () -> None
commit_info = u'* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))'
expected_message = u"kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 1 commit to branch master.\n\n{}".format(commit_info)
self.send_and_test_stream_message('v2_push', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('push', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_push_commits_multiple_committers(self):
# type: () -> None
commit_info = u'* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))\n'
expected_message = u"""kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 3 commits to branch master. Commits by zbenjamin (2) and kolaszek (1).\n\n{}* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))""".format(commit_info*2)
self.send_and_test_stream_message('v2_push_multiple_committers', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('push_multiple_committers', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_push_commits_multiple_committers_with_others(self):
# type: () -> None
commit_info = u'* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))\n'
expected_message = u"""kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 10 commits to branch master. Commits by james (3), Brendon (2), Tomasz (2) and others (3).\n\n{}* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))""".format(commit_info*9)
self.send_and_test_stream_message('v2_push_multiple_committers_with_others', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('push_multiple_committers_with_others', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_push_commits_multiple_committers_filtered_by_branches(self):
# type: () -> None
self.url = self.build_webhook_url(branches='master,development')
commit_info = u'* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))\n'
expected_message = u"""kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 3 commits to branch master. Commits by zbenjamin (2) and kolaszek (1).\n\n{}* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))""".format(commit_info*2)
self.send_and_test_stream_message('v2_push_multiple_committers', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('push_multiple_committers', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_push_commits_multiple_committers_with_others_filtered_by_branches(self):
# type: () -> None
self.url = self.build_webhook_url(branches='master,development')
commit_info = u'* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))\n'
expected_message = u"""kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 10 commits to branch master. Commits by james (3), Brendon (2), Tomasz (2) and others (3).\n\n{}* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))""".format(commit_info*9)
self.send_and_test_stream_message('v2_push_multiple_committers_with_others', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('push_multiple_committers_with_others', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_push_event_filtered_by_branches(self):
# type: () -> None
self.url = self.build_webhook_url(branches='master,development')
commit_info = u'* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))'
expected_message = u"kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 1 commit to branch master.\n\n{}".format(commit_info)
self.send_and_test_stream_message('v2_push', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('push', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_push_commits_above_limit_event(self):
# type: () -> None
@@ -58,7 +58,7 @@ class Bitbucket2HookTests(WebhookTestCase):
expected_message = u"kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branches/compare/6f161a7bced94430ac8947d87dbf45c6deee3fb0..1221f2fda6f1e3654b09f1f3a08390e4cb25bb48) 5 commits to branch master. Commits by Tomasz (5).\n\n{}[and more commit(s)]".format(
(commit_info * 5),
)
self.send_and_test_stream_message('v2_push_commits_above_limit', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('push_commits_above_limit', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_push_commits_above_limit_filtered_by_branches(self):
# type: () -> None
@@ -67,53 +67,53 @@ class Bitbucket2HookTests(WebhookTestCase):
expected_message = u"kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branches/compare/6f161a7bced94430ac8947d87dbf45c6deee3fb0..1221f2fda6f1e3654b09f1f3a08390e4cb25bb48) 5 commits to branch master. Commits by Tomasz (5).\n\n{}[and more commit(s)]".format(
(commit_info * 5),
)
self.send_and_test_stream_message('v2_push_commits_above_limit', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('push_commits_above_limit', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_force_push_event(self):
# type: () -> None
expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) to branch master. Head is now 25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12"
self.send_and_test_stream_message('v2_force_push', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('force_push', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_force_push_event_filtered_by_branches(self):
# type: () -> None
self.url = self.build_webhook_url(branches='master,development')
expected_message = u"kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) to branch master. Head is now 25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12"
self.send_and_test_stream_message('v2_force_push', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('force_push', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_remove_branch_event(self):
# type: () -> None
expected_message = u"kolaszek deleted branch master"
self.send_and_test_stream_message('v2_remove_branch', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
self.send_and_test_stream_message('remove_branch', self.EXPECTED_SUBJECT_BRANCH_EVENTS, expected_message)
def test_bitbucket2_on_fork_event(self):
# type: () -> None
expected_message = u"User Tomasz(login: kolaszek) forked the repository into [kolaszek/repository-name2](https://bitbucket.org/kolaszek/repository-name2)."
self.send_and_test_stream_message('v2_fork', self.EXPECTED_SUBJECT, expected_message)
self.send_and_test_stream_message('fork', self.EXPECTED_SUBJECT, expected_message)
def test_bitbucket2_on_commit_comment_created_event(self):
# type: () -> None
expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74#comment-3354963) on [32c4ea1](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74)\n~~~ quote\nNice fix!\n~~~"
self.send_and_test_stream_message('v2_commit_comment_created', self.EXPECTED_SUBJECT, expected_message)
self.send_and_test_stream_message('commit_comment_created', self.EXPECTED_SUBJECT, expected_message)
def test_bitbucket2_on_commit_status_changed_event(self):
# type: () -> None
expected_message = u"[System mybuildtool](https://my-build-tool.com/builds/MY-PROJECT/BUILD-777) changed status of https://bitbucket.org/kolaszek/repository-name/9fec847784abb10b2fa567ee63b85bd238955d0e to SUCCESSFUL."
self.send_and_test_stream_message('v2_commit_status_changed', self.EXPECTED_SUBJECT, expected_message)
self.send_and_test_stream_message('commit_status_changed', self.EXPECTED_SUBJECT, expected_message)
def test_bitbucket2_on_issue_created_event(self):
# type: () -> None
expected_message = u"kolaszek created [Issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)(assigned to kolaszek)\n\n~~~ quote\nSuch a bug\n~~~"
self.send_and_test_stream_message('v2_issue_created', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message)
self.send_and_test_stream_message('issue_created', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message)
def test_bitbucket2_on_issue_updated_event(self):
# type: () -> None
expected_message = u"kolaszek updated [Issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)"
self.send_and_test_stream_message('v2_issue_updated', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message)
self.send_and_test_stream_message('issue_updated', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message)
def test_bitbucket2_on_issue_commented_event(self):
# type: () -> None
expected_message = u"kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/issues/2#comment-28973596) on [Issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug)"
self.send_and_test_stream_message('v2_issue_commented', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message)
self.send_and_test_stream_message('issue_commented', self.EXPECTED_SUBJECT_ISSUE_EVENTS, expected_message)
def test_bitbucket2_on_pull_request_created_event(self):
# type: () -> None
@@ -121,7 +121,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:created'
}
self.send_and_test_stream_message('v2_pull_request_created_or_updated', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
self.send_and_test_stream_message('pull_request_created_or_updated', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
def test_bitbucket2_on_pull_request_updated_event(self):
# type: () -> None
@@ -129,7 +129,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:updated'
}
self.send_and_test_stream_message('v2_pull_request_created_or_updated', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
self.send_and_test_stream_message('pull_request_created_or_updated', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
def test_bitbucket2_on_pull_request_approved_event(self):
# type: () -> None
@@ -137,7 +137,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:approved'
}
self.send_and_test_stream_message('v2_pull_request_approved_or_unapproved', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
self.send_and_test_stream_message('pull_request_approved_or_unapproved', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
def test_bitbucket2_on_pull_request_unapproved_event(self):
# type: () -> None
@@ -145,7 +145,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:unapproved'
}
self.send_and_test_stream_message('v2_pull_request_approved_or_unapproved', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
self.send_and_test_stream_message('pull_request_approved_or_unapproved', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
def test_bitbucket2_on_pull_request_declined_event(self):
# type: () -> None
@@ -153,7 +153,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:rejected'
}
self.send_and_test_stream_message('v2_pull_request_fulfilled_or_rejected', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
self.send_and_test_stream_message('pull_request_fulfilled_or_rejected', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
def test_bitbucket2_on_pull_request_fulfilled_event(self):
# type: () -> None
@@ -161,7 +161,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:fulfilled'
}
self.send_and_test_stream_message('v2_pull_request_fulfilled_or_rejected', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
self.send_and_test_stream_message('pull_request_fulfilled_or_rejected', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
def test_bitbucket2_on_pull_request_comment_created_event(self):
# type: () -> None
@@ -169,7 +169,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:comment_created'
}
self.send_and_test_stream_message('v2_pull_request_comment_action', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
self.send_and_test_stream_message('pull_request_comment_action', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
def test_bitbucket2_on_pull_request_comment_updated_event(self):
# type: () -> None
@@ -177,7 +177,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:comment_updated'
}
self.send_and_test_stream_message('v2_pull_request_comment_action', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
self.send_and_test_stream_message('pull_request_comment_action', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
def test_bitbucket2_on_pull_request_comment_deleted_event(self):
# type: () -> None
@@ -185,7 +185,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:comment_deleted'
}
self.send_and_test_stream_message('v2_pull_request_comment_action', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
self.send_and_test_stream_message('pull_request_comment_action', self.EXPECTED_SUBJECT_PR_EVENTS, expected_message, **kwargs)
def test_bitbucket2_on_push_one_tag_event(self):
# type: () -> None
@@ -193,7 +193,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:push'
}
self.send_and_test_stream_message('v2_push_one_tag', self.EXPECTED_SUBJECT, expected_message, **kwargs)
self.send_and_test_stream_message('push_one_tag', self.EXPECTED_SUBJECT, expected_message, **kwargs)
def test_bitbucket2_on_push_remove_tag_event(self):
# type: () -> None
@@ -201,7 +201,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:push'
}
self.send_and_test_stream_message('v2_push_remove_tag', self.EXPECTED_SUBJECT, expected_message, **kwargs)
self.send_and_test_stream_message('push_remove_tag', self.EXPECTED_SUBJECT, expected_message, **kwargs)
def test_bitbucket2_on_push_more_than_one_tag_event(self):
# type: () -> None
@@ -209,7 +209,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:push'
}
self.send_and_test_stream_message('v2_push_more_than_one_tag', **kwargs)
self.send_and_test_stream_message('push_more_than_one_tag', **kwargs)
msg = self.get_last_message()
self.do_test_subject(msg, self.EXPECTED_SUBJECT)
self.do_test_message(msg, expected_message.format(name='b'))
@@ -222,7 +222,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:push'
}
self.send_and_test_stream_message('v2_more_than_one_push_event', **kwargs)
self.send_and_test_stream_message('more_than_one_push_event', **kwargs)
msg = self.get_second_to_last_message()
self.do_test_message(msg, 'kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 1 commit to branch master.\n\n* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))')
self.do_test_subject(msg, self.EXPECTED_SUBJECT_BRANCH_EVENTS)
@@ -236,7 +236,7 @@ class Bitbucket2HookTests(WebhookTestCase):
kwargs = {
"HTTP_X_EVENT_KEY": 'pullrequest:push'
}
self.send_and_test_stream_message('v2_more_than_one_push_event', **kwargs)
self.send_and_test_stream_message('more_than_one_push_event', **kwargs)
msg = self.get_second_to_last_message()
self.do_test_message(msg, 'kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 1 commit to branch master.\n\n* first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed))')
self.do_test_subject(msg, self.EXPECTED_SUBJECT_BRANCH_EVENTS)
@@ -251,7 +251,7 @@ class Bitbucket2HookTests(WebhookTestCase):
"HTTP_X_EVENT_KEY": 'pullrequest:push'
}
expected_message = u"kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a)"
self.send_and_test_stream_message('v2_more_than_one_push_event',
self.send_and_test_stream_message('more_than_one_push_event',
self.EXPECTED_SUBJECT,
expected_message, **kwargs)
@@ -260,7 +260,7 @@ class Bitbucket2HookTests(WebhookTestCase):
self, check_send_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,devlopment')
payload = self.get_body('v2_push')
payload = self.get_body('push')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assert_json_success(result)
@@ -270,7 +270,7 @@ class Bitbucket2HookTests(WebhookTestCase):
self, check_send_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,devlopment')
payload = self.get_body('v2_push_commits_above_limit')
payload = self.get_body('push_commits_above_limit')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assert_json_success(result)
@@ -280,7 +280,7 @@ class Bitbucket2HookTests(WebhookTestCase):
self, check_send_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,devlopment')
payload = self.get_body('v2_force_push')
payload = self.get_body('force_push')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assert_json_success(result)
@@ -290,7 +290,7 @@ class Bitbucket2HookTests(WebhookTestCase):
self, check_send_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,devlopment')
payload = self.get_body('v2_push_multiple_committers')
payload = self.get_body('push_multiple_committers')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assert_json_success(result)
@@ -300,7 +300,7 @@ class Bitbucket2HookTests(WebhookTestCase):
self, check_send_message_mock):
# type: (MagicMock) -> None
self.url = self.build_webhook_url(branches='changes,devlopment')
payload = self.get_body('v2_push_multiple_committers_with_others')
payload = self.get_body('push_multiple_committers_with_others')
result = self.client_post(self.url, payload, content_type="application/json")
self.assertFalse(check_send_message_mock.called)
self.assert_json_success(result)

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