2017-11-05 05:30:31 +01:00
|
|
|
import urllib
|
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-01-14 22:06:24 +01:00
|
|
|
|
2016-09-20 22:51:11 +02:00
|
|
|
class TravisHookTests(WebhookTestCase):
|
|
|
|
STREAM_NAME = 'travis'
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/travis?stream={stream}&api_key={api_key}"
|
2016-09-20 22:51:11 +02:00
|
|
|
FIXTURE_DIR_NAME = 'travis'
|
2017-03-06 07:12:40 +01:00
|
|
|
TOPIC = 'builds'
|
2016-09-20 22:51:11 +02:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_travis_message(self) -> None:
|
2016-09-20 22:51:11 +02:00
|
|
|
"""
|
|
|
|
Build notifications are generated by Travis after build completes.
|
|
|
|
|
|
|
|
The subject describes the repo and Stash "project". The
|
|
|
|
content describes the commits pushed.
|
|
|
|
"""
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = ("Author: josh_mandel\nBuild status: Passed :thumbs_up:\n"
|
|
|
|
"Details: [changes](https://github.com/hl7-fhir/fhir-sv"
|
|
|
|
"n/compare/6dccb98bcfd9...6c457d366a31), [build log](ht"
|
|
|
|
"tps://travis-ci.org/hl7-fhir/fhir-svn/builds/92495257)")
|
2016-09-20 22:51:11 +02:00
|
|
|
|
|
|
|
self.send_and_test_stream_message(
|
|
|
|
'build',
|
2017-03-06 07:12:40 +01:00
|
|
|
self.TOPIC,
|
|
|
|
expected_message,
|
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
|
|
|
content_type="application/x-www-form-urlencoded",
|
2017-03-06 07:12:40 +01:00
|
|
|
)
|
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_ignore_travis_pull_request_by_default(self) -> None:
|
2017-08-25 06:37:47 +02:00
|
|
|
self.subscribe(self.test_user, self.STREAM_NAME)
|
2017-03-06 07:12:40 +01:00
|
|
|
result = self.client_post(
|
|
|
|
self.url,
|
|
|
|
self.get_body('pull_request'),
|
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
|
|
|
content_type="application/x-www-form-urlencoded",
|
2017-03-06 07:12:40 +01:00
|
|
|
)
|
|
|
|
self.assert_json_success(result)
|
|
|
|
msg = self.get_last_message()
|
2020-06-04 03:04:07 +02:00
|
|
|
self.assertNotEqual(msg.topic_name(), self.TOPIC)
|
2017-03-06 07:12:40 +01:00
|
|
|
|
2017-11-04 07:47:46 +01:00
|
|
|
def test_travis_pull_requests_are_not_ignored_when_applicable(self) -> None:
|
2020-06-09 00:25:09 +02:00
|
|
|
self.url = f"{self.build_webhook_url()}&ignore_pull_requests=false"
|
2020-04-09 21:51:58 +02:00
|
|
|
expected_message = ("Author: josh_mandel\nBuild status: Passed :thumbs_up:\n"
|
|
|
|
"Details: [changes](https://github.com/hl7-fhir/fhir-sv"
|
|
|
|
"n/compare/6dccb98bcfd9...6c457d366a31), [build log](ht"
|
|
|
|
"tps://travis-ci.org/hl7-fhir/fhir-svn/builds/92495257)")
|
2017-03-06 07:12:40 +01:00
|
|
|
|
|
|
|
self.send_and_test_stream_message(
|
|
|
|
'pull_request',
|
|
|
|
self.TOPIC,
|
2016-09-20 22:51:11 +02:00
|
|
|
expected_message,
|
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
|
|
|
content_type="application/x-www-form-urlencoded",
|
2016-09-20 22:51:11 +02:00
|
|
|
)
|
|
|
|
|
2018-05-10 19:34:01 +02:00
|
|
|
def get_body(self, fixture_name: str) -> str:
|
2018-04-20 03:57:21 +02:00
|
|
|
return urllib.parse.urlencode({'payload': self.webhook_fixture_data("travis", fixture_name, file_type="json")})
|