2020-05-26 07:16:25 +02:00
from unittest . mock import MagicMock , patch
2017-11-16 00:43:10 +01:00
2016-11-10 19:30:09 +01:00
from zerver . lib . test_classes import WebhookTestCase
2016-09-20 22:51:11 +02:00
2020-08-22 17:16:32 +02:00
TOPIC = " Repository name "
TOPIC_PR_EVENTS = " Repository name / PR #1 new commit "
TOPIC_ISSUE_EVENTS = " Repository name / Issue #1 Bug "
TOPIC_BRANCH_EVENTS = " Repository name / master "
2020-01-14 22:06:24 +01:00
2016-09-20 22:51:11 +02:00
class Bitbucket2HookTests ( WebhookTestCase ) :
STREAM_NAME = ' bitbucket2 '
URL_TEMPLATE = " /api/v1/external/bitbucket2?stream= {stream} &api_key= {api_key} "
2017-04-27 21:19:05 +02:00
FIXTURE_DIR_NAME = ' bitbucket2 '
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
commit_info = ' * first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed)) '
2020-06-09 00:25:09 +02:00
expected_message = f " kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 1 commit to branch master. \n \n { commit_info } "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " push " , TOPIC_BRANCH_EVENTS , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_commits_multiple_committers ( self ) - > None :
2020-04-09 21:51:58 +02:00
commit_info = ' * first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed)) \n '
2020-06-09 00:25:09 +02:00
expected_message = f """ kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 3 commits to branch master. Commits by zbenjamin (2) and kolaszek (1). \n \n { commit_info * 2 } * first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed)) """
2020-08-23 15:49:24 +02:00
self . check_webhook ( " push_multiple_committers " , TOPIC_BRANCH_EVENTS , expected_message )
2017-04-05 09:12:19 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_commits_multiple_committers_with_others ( self ) - > None :
2020-04-09 21:51:58 +02:00
commit_info = ' * first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed)) \n '
2020-06-09 00:25:09 +02:00
expected_message = f """ 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 { commit_info * 9 } * first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed)) """
2020-08-23 15:49:24 +02:00
self . check_webhook (
" push_multiple_committers_with_others " , TOPIC_BRANCH_EVENTS , expected_message
)
2017-04-05 09:12:19 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_commits_multiple_committers_filtered_by_branches ( self ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' master,development ' )
2020-04-09 21:51:58 +02:00
commit_info = ' * first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed)) \n '
2020-06-09 00:25:09 +02:00
expected_message = f """ kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 3 commits to branch master. Commits by zbenjamin (2) and kolaszek (1). \n \n { commit_info * 2 } * first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed)) """
2020-08-23 15:49:24 +02:00
self . check_webhook ( " push_multiple_committers " , TOPIC_BRANCH_EVENTS , expected_message )
2017-04-05 02:52:31 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_commits_multiple_committers_with_others_filtered_by_branches ( self ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' master,development ' )
2020-04-09 21:51:58 +02:00
commit_info = ' * first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed)) \n '
2020-06-09 00:25:09 +02:00
expected_message = f """ 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 { commit_info * 9 } * first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed)) """
2020-08-23 15:49:24 +02:00
self . check_webhook (
" push_multiple_committers_with_others " , TOPIC_BRANCH_EVENTS , expected_message
)
2017-04-05 02:52:31 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_event_filtered_by_branches ( self ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' master,development ' )
2020-04-09 21:51:58 +02:00
commit_info = ' * first commit ([84b96ad](https://bitbucket.org/kolaszek/repository-name/commits/84b96adc644a30fd6465b3d196369d880762afed)) '
2020-06-09 00:25:09 +02:00
expected_message = f " kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) 1 commit to branch master. \n \n { commit_info } "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " push " , TOPIC_BRANCH_EVENTS , expected_message )
2017-04-05 02:52:31 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_commits_above_limit_event ( self ) - > None :
2017-03-15 10:15:03 +01:00
commit_info = ' * a ([6f161a7](https://bitbucket.org/kolaszek/repository-name/commits/6f161a7bced94430ac8947d87dbf45c6deee3fb0)) \n '
2020-06-10 06:40:53 +02:00
expected_message = f " kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branches/compare/6f161a7bced94430ac8947d87dbf45c6deee3fb0..1221f2fda6f1e3654b09f1f3a08390e4cb25bb48) 5 commits to branch master. Commits by Tomasz (5). \n \n { ( commit_info * 5 ) } [and more commit(s)] "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " push_commits_above_limit " , TOPIC_BRANCH_EVENTS , expected_message )
2016-10-07 15:12:51 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_commits_above_limit_filtered_by_branches ( self ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' master,development ' )
commit_info = ' * a ([6f161a7](https://bitbucket.org/kolaszek/repository-name/commits/6f161a7bced94430ac8947d87dbf45c6deee3fb0)) \n '
2020-06-10 06:40:53 +02:00
expected_message = f " kolaszek [pushed](https://bitbucket.org/kolaszek/repository-name/branches/compare/6f161a7bced94430ac8947d87dbf45c6deee3fb0..1221f2fda6f1e3654b09f1f3a08390e4cb25bb48) 5 commits to branch master. Commits by Tomasz (5). \n \n { ( commit_info * 5 ) } [and more commit(s)] "
2019-04-19 22:02:41 +02:00
2020-08-23 15:49:24 +02:00
self . check_webhook ( " push_commits_above_limit " , TOPIC_BRANCH_EVENTS , expected_message )
2017-04-05 02:52:31 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_force_push_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) to branch master. Head is now 25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " force_push " , TOPIC_BRANCH_EVENTS , expected_message )
2016-10-06 15:32:10 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_force_push_event_filtered_by_branches ( self ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' master,development ' )
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek [force pushed](https://bitbucket.org/kolaszek/repository-name/branch/master) to branch master. Head is now 25f93d22b719e2d678a7ad5ee0ef0d1fcdf39c12. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " force_push " , TOPIC_BRANCH_EVENTS , expected_message )
2017-04-05 02:52:31 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_remove_branch_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek deleted branch master. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " remove_branch " , TOPIC_BRANCH_EVENTS , expected_message )
2016-10-06 16:14:51 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_fork_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " User Tomasz(login: kolaszek) forked the repository into [kolaszek/repository-name2](https://bitbucket.org/kolaszek/repository-name2). "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " fork " , TOPIC , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_commit_comment_created_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74#comment-3354963) on [32c4ea1](https://bitbucket.org/kolaszek/repository-name/commits/32c4ea19aa3af10acd08e419e2c354941a365d74): \n ~~~ quote \n Nice fix! \n ~~~ "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " commit_comment_created " , TOPIC , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_commit_status_changed_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " [System mybuildtool](https://my-build-tool.com/builds/MY-PROJECT/BUILD-777) changed status of [9fec847](https://bitbucket.org/kolaszek/repository-name/commits/9fec847784abb10b2fa567ee63b85bd238955d0e) to SUCCESSFUL. "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " commit_status_changed " , TOPIC , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_issue_created_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek created [Issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug) (assigned to kolaszek): \n \n ~~~ quote \n Such a bug \n ~~~ "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " issue_created " , TOPIC_ISSUE_EVENTS , expected_message )
2016-09-20 22:51:11 +02:00
2018-07-25 00:57:45 +02:00
def test_bitbucket2_on_issue_created_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = " notifications " )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
expected_message = " kolaszek created [Issue #1 Bug](https://bitbucket.org/kolaszek/repository-name/issues/2/bug) (assigned to kolaszek): \n \n ~~~ quote \n Such a bug \n ~~~ "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " issue_created " , expected_topic , expected_message )
2018-07-25 00:57:45 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_issue_updated_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek updated [Issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug). "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " issue_updated " , TOPIC_ISSUE_EVENTS , expected_message )
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_issue_commented_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/issues/2#comment-28973596) on [Issue #1](https://bitbucket.org/kolaszek/repository-name/issues/2/bug). "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " issue_commented " , TOPIC_ISSUE_EVENTS , expected_message )
2016-09-20 22:51:11 +02:00
2018-07-25 00:57:45 +02:00
def test_bitbucket2_on_issue_commented_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = " notifications " )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
expected_message = " kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/issues/2#comment-28973596) on [Issue #1 Bug](https://bitbucket.org/kolaszek/repository-name/issues/2/bug). "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " issue_commented " , expected_topic , expected_message )
2018-07-25 00:57:45 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_pull_request_created_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to tkolek) from `new-branch` to `master`: \n \n ~~~ quote \n description \n ~~~ "
2016-09-20 22:51:11 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:created ' ,
2016-09-20 22:51:11 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_created_or_updated " , TOPIC_PR_EVENTS , expected_message , * * kwargs
)
2016-09-20 22:51:11 +02:00
2019-06-22 21:45:15 +02:00
def test_bitbucket2_on_pull_request_created_without_reviewer_username_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek created [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to Tomasz Kolek) from `new-branch` to `master`: \n \n ~~~ quote \n description \n ~~~ "
2019-06-22 21:45:15 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:created ' ,
2019-06-22 21:45:15 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_created_or_updated_without_username " ,
TOPIC_PR_EVENTS ,
expected_message ,
* * kwargs
)
2019-06-22 21:45:15 +02:00
2018-07-25 00:57:45 +02:00
def test_bitbucket2_on_pull_request_created_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = " notifications " )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
expected_message = " kolaszek created [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to tkolek) from `new-branch` to `master`: \n \n ~~~ quote \n description \n ~~~ "
2018-07-25 00:57:45 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:created ' ,
2018-07-25 00:57:45 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_created_or_updated " , expected_topic , expected_message , * * kwargs
)
2018-07-25 00:57:45 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_pull_request_updated_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek updated [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1) (assigned to tkolek) from `new-branch` to `master`: \n \n ~~~ quote \n description \n ~~~ "
2016-09-20 22:51:11 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:updated ' ,
2016-09-20 22:51:11 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_created_or_updated " , TOPIC_PR_EVENTS , expected_message , * * kwargs
)
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_pull_request_approved_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek approved [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1). "
2016-09-20 22:51:11 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:approved ' ,
2016-09-20 22:51:11 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_approved_or_unapproved " , TOPIC_PR_EVENTS , expected_message , * * kwargs
)
2016-09-20 22:51:11 +02:00
2018-07-25 00:57:45 +02:00
def test_bitbucket2_on_pull_request_approved_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = " notifications " )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
expected_message = " kolaszek approved [PR #1 new commit](https://bitbucket.org/kolaszek/repository-name/pull-requests/1). "
2018-07-25 00:57:45 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:approved ' ,
2018-07-25 00:57:45 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_approved_or_unapproved " , expected_topic , expected_message , * * kwargs
)
2018-07-25 00:57:45 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_pull_request_unapproved_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek unapproved [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1). "
2016-09-20 22:51:11 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:unapproved ' ,
2016-09-20 22:51:11 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_approved_or_unapproved " , TOPIC_PR_EVENTS , expected_message , * * kwargs
)
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_pull_request_declined_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek rejected [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1). "
2016-09-20 22:51:11 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:rejected ' ,
2016-09-20 22:51:11 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_fulfilled_or_rejected " , TOPIC_PR_EVENTS , expected_message , * * kwargs
)
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_pull_request_fulfilled_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek merged [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/1). "
2016-09-20 22:51:11 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:fulfilled ' ,
2016-09-20 22:51:11 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_fulfilled_or_rejected " , TOPIC_PR_EVENTS , expected_message , * * kwargs
)
2016-09-20 22:51:11 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_pull_request_comment_created_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek [commented](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3): \n \n ~~~ quote \n Comment1 \n ~~~ "
2016-09-20 22:51:11 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:comment_created ' ,
2016-09-20 22:51:11 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_comment_action " , TOPIC_PR_EVENTS , expected_message , * * kwargs
)
2016-09-20 22:51:11 +02:00
2018-07-25 00:57:45 +02:00
def test_bitbucket2_on_pull_request_comment_created_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = " notifications " )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
expected_message = " kolaszek [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 \n Comment1 \n ~~~ "
2018-07-25 00:57:45 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:comment_created ' ,
2018-07-25 00:57:45 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_comment_action " , expected_topic , expected_message , * * kwargs
)
2018-07-25 00:57:45 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_pull_request_comment_updated_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek updated a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3): \n \n ~~~ quote \n Comment1 \n ~~~ "
2016-09-20 22:51:11 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:comment_updated ' ,
2016-09-20 22:51:11 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_comment_action " , TOPIC_PR_EVENTS , expected_message , * * kwargs
)
2016-09-20 22:51:11 +02:00
2018-07-25 00:57:45 +02:00
def test_bitbucket2_on_pull_request_comment_updated_with_custom_topic_in_url ( self ) - > None :
self . url = self . build_webhook_url ( topic = " notifications " )
2020-04-09 21:51:58 +02:00
expected_topic = " notifications "
expected_message = " kolaszek 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 \n Comment1 \n ~~~ "
2018-07-25 00:57:45 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:comment_updated ' ,
2018-07-25 00:57:45 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_comment_action " , expected_topic , expected_message , * * kwargs
)
2018-07-25 00:57:45 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_pull_request_comment_deleted_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek deleted a [comment](https://bitbucket.org/kolaszek/repository-name/pull-requests/3/_/diff#comment-20576503) on [PR #1](https://bitbucket.org/kolaszek/repository-name/pull-requests/3): \n \n ~~~ quote \n Comment1 \n ~~~ "
2016-09-20 22:51:11 +02:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:comment_deleted ' ,
2016-09-20 22:51:11 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook (
" pull_request_comment_action " , TOPIC_PR_EVENTS , expected_message , * * kwargs
)
2016-10-07 17:53:27 +02:00
2018-04-25 01:36:03 +02:00
def test_bitbucket2_on_repo_updated_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " eeshangarg changed the website of the **new-name** repo to **http://zulipchat.com**. \n eeshangarg changed the name of the **new-name** repo from **test-repo** to **new-name**. \n eeshangarg changed the language of the **new-name** repo to **python**. \n eeshangarg changed the full name of the **new-name** repo from **webhooktest/test-repo** to **webhooktest/new-name**. \n eeshangarg changed the description of the **new-name** repo to **Random description.** "
expected_topic = " new-name "
2018-04-25 01:36:03 +02:00
kwargs = { " HTTP_X_EVENT_KEY " : ' repo:updated ' }
2020-08-23 15:49:24 +02:00
self . check_webhook ( " repo_updated " , expected_topic , expected_message , * * kwargs )
2018-04-25 01:36:03 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_one_tag_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a). "
2016-11-09 16:05:45 +01:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:push ' ,
2016-11-09 16:05:45 +01:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook ( " push_one_tag " , TOPIC , expected_message , * * kwargs )
2016-11-09 16:05:45 +01:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_remove_tag_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek removed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a). "
2016-11-09 16:05:45 +01:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:push ' ,
2016-11-09 16:05:45 +01:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook ( " push_remove_tag " , TOPIC , expected_message , * * kwargs )
2016-11-09 16:05:45 +01:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_push_more_than_one_tag_event ( self ) - > None :
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek pushed tag [ {name} ](https://bitbucket.org/kolaszek/repository-name/commits/tag/ {name} ). "
2016-11-09 16:05:45 +01:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:push ' ,
2016-11-09 16:05:45 +01:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook ( " push_more_than_one_tag " , * * kwargs )
2020-08-24 14:21:58 +02:00
2016-11-09 16:05:45 +01:00
msg = self . get_second_to_last_message ( )
2020-08-24 14:21:58 +02:00
self . assert_stream_message (
message = msg ,
stream_name = self . STREAM_NAME ,
topic_name = TOPIC ,
content = expected_message . format ( name = " a " ) ,
)
msg = self . get_last_message ( )
self . assert_stream_message (
message = msg ,
stream_name = self . STREAM_NAME ,
topic_name = TOPIC ,
content = expected_message . format ( name = " b " ) ,
)
2016-11-09 16:05:45 +01:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_more_than_one_push_event ( self ) - > None :
2016-11-11 13:32:41 +01:00
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:push ' ,
2016-11-11 13:32:41 +01:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook ( " more_than_one_push_event " , * * kwargs )
2020-08-24 14:21:58 +02:00
2016-11-11 13:32:41 +01:00
msg = self . get_second_to_last_message ( )
2020-08-24 14:21:58 +02:00
self . assert_stream_message (
message = msg ,
stream_name = self . STREAM_NAME ,
topic_name = TOPIC_BRANCH_EVENTS ,
content = " 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)) "
)
2016-11-11 13:32:41 +01:00
msg = self . get_last_message ( )
2020-08-24 14:21:58 +02:00
self . assert_stream_message (
message = msg ,
stream_name = self . STREAM_NAME ,
topic_name = TOPIC ,
content = " kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a). " ,
)
2017-04-05 02:52:31 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_more_than_one_push_event_filtered_by_branches ( self ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' master,development ' )
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:push ' ,
2017-04-05 02:52:31 +02:00
}
2020-08-23 15:49:24 +02:00
self . check_webhook ( " more_than_one_push_event " , * * kwargs )
2020-08-24 14:21:58 +02:00
2017-04-05 02:52:31 +02:00
msg = self . get_second_to_last_message ( )
2020-08-24 14:21:58 +02:00
self . assert_stream_message (
message = msg ,
stream_name = self . STREAM_NAME ,
topic_name = TOPIC_BRANCH_EVENTS ,
content = " 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)) " ,
)
2017-04-05 02:52:31 +02:00
msg = self . get_last_message ( )
2020-08-24 14:21:58 +02:00
self . assert_stream_message (
message = msg ,
stream_name = self . STREAM_NAME ,
topic_name = TOPIC ,
content = " kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a). " ,
)
2017-04-05 02:52:31 +02:00
2017-11-04 07:47:46 +01:00
def test_bitbucket2_on_more_than_one_push_event_filtered_by_branches_ignore ( self ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' changes,development ' )
kwargs = {
python: Use trailing commas consistently.
Automatically generated by the following script, based on the output
of lint with flake8-comma:
import re
import sys
last_filename = None
last_row = None
lines = []
for msg in sys.stdin:
m = re.match(
r"\x1b\[35mflake8 \|\x1b\[0m \x1b\[1;31m(.+):(\d+):(\d+): (\w+)", msg
)
if m:
filename, row_str, col_str, err = m.groups()
row, col = int(row_str), int(col_str)
if filename == last_filename:
assert last_row != row
else:
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
with open(filename) as f:
lines = f.readlines()
last_filename = filename
last_row = row
line = lines[row - 1]
if err in ["C812", "C815"]:
lines[row - 1] = line[: col - 1] + "," + line[col - 1 :]
elif err in ["C819"]:
assert line[col - 2] == ","
lines[row - 1] = line[: col - 2] + line[col - 1 :].lstrip(" ")
if last_filename is not None:
with open(last_filename, "w") as f:
f.writelines(lines)
Signed-off-by: Anders Kaseorg <anders@zulipchat.com>
2020-04-10 05:23:40 +02:00
" HTTP_X_EVENT_KEY " : ' pullrequest:push ' ,
2017-04-05 02:52:31 +02:00
}
2020-04-09 21:51:58 +02:00
expected_message = " kolaszek pushed tag [a](https://bitbucket.org/kolaszek/repository-name/commits/tag/a). "
2020-08-23 15:49:24 +02:00
self . check_webhook ( " more_than_one_push_event " , TOPIC , expected_message , * * kwargs )
2017-04-05 02:52:31 +02:00
2018-03-13 23:43:02 +01:00
@patch ( ' zerver.webhooks.bitbucket2.view.check_send_webhook_message ' )
2017-04-05 02:52:31 +02:00
def test_bitbucket2_on_push_event_filtered_by_branches_ignore (
2018-03-13 23:43:02 +01:00
self , check_send_webhook_message_mock : MagicMock ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' changes,devlopment ' )
2017-04-27 21:19:05 +02:00
payload = self . get_body ( ' push ' )
2017-04-05 02:52:31 +02:00
result = self . client_post ( self . url , payload , content_type = " application/json " )
2018-03-13 23:43:02 +01:00
self . assertFalse ( check_send_webhook_message_mock . called )
2017-04-05 02:52:31 +02:00
self . assert_json_success ( result )
2018-03-13 23:43:02 +01:00
@patch ( ' zerver.webhooks.bitbucket2.view.check_send_webhook_message ' )
2017-04-05 02:52:31 +02:00
def test_bitbucket2_on_push_commits_above_limit_filtered_by_branches_ignore (
2018-03-13 23:43:02 +01:00
self , check_send_webhook_message_mock : MagicMock ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' changes,devlopment ' )
2017-04-27 21:19:05 +02:00
payload = self . get_body ( ' push_commits_above_limit ' )
2017-04-05 02:52:31 +02:00
result = self . client_post ( self . url , payload , content_type = " application/json " )
2018-03-13 23:43:02 +01:00
self . assertFalse ( check_send_webhook_message_mock . called )
2017-04-05 02:52:31 +02:00
self . assert_json_success ( result )
2018-03-13 23:43:02 +01:00
@patch ( ' zerver.webhooks.bitbucket2.view.check_send_webhook_message ' )
2017-04-05 02:52:31 +02:00
def test_bitbucket2_on_force_push_event_filtered_by_branches_ignore (
2018-03-13 23:43:02 +01:00
self , check_send_webhook_message_mock : MagicMock ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' changes,devlopment ' )
2017-04-27 21:19:05 +02:00
payload = self . get_body ( ' force_push ' )
2017-04-05 02:52:31 +02:00
result = self . client_post ( self . url , payload , content_type = " application/json " )
2018-03-13 23:43:02 +01:00
self . assertFalse ( check_send_webhook_message_mock . called )
2017-04-05 02:52:31 +02:00
self . assert_json_success ( result )
2018-03-13 23:43:02 +01:00
@patch ( ' zerver.webhooks.bitbucket2.view.check_send_webhook_message ' )
2017-04-05 02:52:31 +02:00
def test_bitbucket2_on_push_multiple_committers_filtered_by_branches_ignore (
2018-03-13 23:43:02 +01:00
self , check_send_webhook_message_mock : MagicMock ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' changes,devlopment ' )
2017-04-27 21:19:05 +02:00
payload = self . get_body ( ' push_multiple_committers ' )
2017-04-05 02:52:31 +02:00
result = self . client_post ( self . url , payload , content_type = " application/json " )
2018-03-13 23:43:02 +01:00
self . assertFalse ( check_send_webhook_message_mock . called )
2017-04-05 02:52:31 +02:00
self . assert_json_success ( result )
2018-03-13 23:43:02 +01:00
@patch ( ' zerver.webhooks.bitbucket2.view.check_send_webhook_message ' )
2017-04-05 02:52:31 +02:00
def test_bitbucket2_on_push_multiple_committers_with_others_filtered_by_branches_ignore (
2018-03-13 23:43:02 +01:00
self , check_send_webhook_message_mock : MagicMock ) - > None :
2017-04-05 02:52:31 +02:00
self . url = self . build_webhook_url ( branches = ' changes,devlopment ' )
2017-04-27 21:19:05 +02:00
payload = self . get_body ( ' push_multiple_committers_with_others ' )
2017-04-05 02:52:31 +02:00
result = self . client_post ( self . url , payload , content_type = " application/json " )
2018-03-13 23:43:02 +01:00
self . assertFalse ( check_send_webhook_message_mock . called )
2017-04-05 02:52:31 +02:00
self . assert_json_success ( result )
2017-11-27 01:03:52 +01:00
2018-03-13 23:43:02 +01:00
@patch ( ' zerver.webhooks.bitbucket2.view.check_send_webhook_message ' )
2018-03-12 02:47:49 +01:00
def test_bitbucket2_on_push_without_changes_ignore (
2018-03-13 23:43:02 +01:00
self , check_send_webhook_message_mock : MagicMock ) - > None :
2017-11-27 01:03:52 +01:00
payload = self . get_body ( ' push_without_changes ' )
result = self . client_post ( self . url , payload , content_type = " application/json " )
2018-03-13 23:43:02 +01:00
self . assertFalse ( check_send_webhook_message_mock . called )
2017-11-27 01:03:52 +01:00
self . assert_json_success ( result )