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):
|
2021-02-12 08:20:45 +01:00
|
|
|
STREAM_NAME = "travis"
|
2020-04-09 21:51:58 +02:00
|
|
|
URL_TEMPLATE = "/api/v1/external/travis?stream={stream}&api_key={api_key}"
|
2021-06-26 09:18:33 +02:00
|
|
|
WEBHOOK_DIR_NAME = "travis"
|
2021-02-12 08:20:45 +01:00
|
|
|
TOPIC = "builds"
|
2021-06-07 21:01:06 +02:00
|
|
|
EXPECTED_MESSAGE = """
|
|
|
|
Author: josh_mandel
|
|
|
|
Build status: Passed :thumbs_up:
|
|
|
|
Details: [changes](https://github.com/hl7-fhir/fhir-svn/compare/6dccb98bcfd9...6c457d366a31), [build log](https://travis-ci.org/hl7-fhir/fhir-svn/builds/92495257)
|
|
|
|
""".strip()
|
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-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
2021-02-12 08:19:30 +01:00
|
|
|
"build",
|
|
|
|
self.TOPIC,
|
2021-06-07 21:01:06 +02:00
|
|
|
self.EXPECTED_MESSAGE,
|
2021-02-12 08:19:30 +01: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:
|
2021-06-30 09:46:14 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"pull_request", content_type="application/x-www-form-urlencoded", expect_noop=True
|
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"
|
2017-03-06 07:12:40 +01:00
|
|
|
|
2020-08-23 15:49:24 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"pull_request",
|
2017-03-06 07:12:40 +01:00
|
|
|
self.TOPIC,
|
2021-06-07 21:01:06 +02:00
|
|
|
self.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
|
|
|
)
|
|
|
|
|
2021-05-17 20:26:48 +02:00
|
|
|
def test_travis_only_push_event(self) -> None:
|
|
|
|
self.url = f'{self.build_webhook_url()}&only_events=["push"]'
|
|
|
|
|
|
|
|
self.check_webhook(
|
|
|
|
"build",
|
|
|
|
self.TOPIC,
|
|
|
|
self.EXPECTED_MESSAGE,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_travis_only_push_event_not_sent(self) -> None:
|
|
|
|
self.url = f'{self.build_webhook_url()}&only_events=["push"]&ignore_pull_requests=false'
|
|
|
|
|
2021-06-30 09:46:14 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"pull_request",
|
2021-05-17 20:26:48 +02:00
|
|
|
content_type="application/x-www-form-urlencoded",
|
2021-06-30 09:46:14 +02:00
|
|
|
expect_noop=True,
|
2021-05-17 20:26:48 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
def test_travis_exclude_push_event(self) -> None:
|
|
|
|
self.url = f'{self.build_webhook_url()}&exclude_events=["push"]'
|
|
|
|
|
2021-06-30 09:46:14 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"build",
|
2021-05-17 20:26:48 +02:00
|
|
|
content_type="application/x-www-form-urlencoded",
|
2021-06-30 09:46:14 +02:00
|
|
|
expect_noop=True,
|
2021-05-17 20:26:48 +02:00
|
|
|
)
|
|
|
|
|
2022-02-08 00:13:33 +01:00
|
|
|
def test_travis_exclude_push_event_sent(self) -> None:
|
2021-05-17 20:26:48 +02:00
|
|
|
self.url = f'{self.build_webhook_url()}&exclude_events=["push"]&ignore_pull_requests=false'
|
|
|
|
|
|
|
|
self.check_webhook(
|
|
|
|
"pull_request",
|
|
|
|
self.TOPIC,
|
|
|
|
self.EXPECTED_MESSAGE,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_travis_include_glob_events(self) -> None:
|
|
|
|
self.url = f'{self.build_webhook_url()}&include_events=["*"]&ignore_pull_requests=false'
|
|
|
|
|
|
|
|
self.check_webhook(
|
|
|
|
"pull_request",
|
|
|
|
self.TOPIC,
|
|
|
|
self.EXPECTED_MESSAGE,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
|
|
|
|
|
|
|
self.check_webhook(
|
|
|
|
"build",
|
|
|
|
self.TOPIC,
|
|
|
|
self.EXPECTED_MESSAGE,
|
|
|
|
content_type="application/x-www-form-urlencoded",
|
|
|
|
)
|
|
|
|
|
|
|
|
def test_travis_exclude_glob_events(self) -> None:
|
|
|
|
self.url = f'{self.build_webhook_url()}&exclude_events=["*"]&ignore_pull_requests=false'
|
|
|
|
|
2021-06-30 09:46:14 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"pull_request",
|
2021-05-17 20:26:48 +02:00
|
|
|
content_type="application/x-www-form-urlencoded",
|
2021-06-30 09:46:14 +02:00
|
|
|
expect_noop=True,
|
2021-05-17 20:26:48 +02:00
|
|
|
)
|
|
|
|
|
2021-06-30 09:46:14 +02:00
|
|
|
self.check_webhook(
|
|
|
|
"build",
|
2021-05-17 20:26:48 +02:00
|
|
|
content_type="application/x-www-form-urlencoded",
|
2021-06-30 09:46:14 +02:00
|
|
|
expect_noop=True,
|
2021-05-17 20:26:48 +02:00
|
|
|
)
|
|
|
|
|
2021-06-30 09:46:14 +02:00
|
|
|
def test_travis_noop(self) -> None:
|
|
|
|
expected_error_message = """
|
|
|
|
While no message is expected given expect_noop=True,
|
|
|
|
your test code triggered an endpoint that did write
|
|
|
|
one or more new messages.
|
|
|
|
""".strip()
|
|
|
|
|
|
|
|
with self.assertRaises(Exception) as exc:
|
|
|
|
self.check_webhook(
|
|
|
|
"build", content_type="application/x-www-form-urlencoded", expect_noop=True
|
|
|
|
)
|
|
|
|
self.assertEqual(str(exc.exception), expected_error_message)
|
|
|
|
|
2018-05-10 19:34:01 +02:00
|
|
|
def get_body(self, fixture_name: str) -> str:
|
2021-02-12 08:19:30 +01:00
|
|
|
return urllib.parse.urlencode(
|
2021-02-12 08:20:45 +01:00
|
|
|
{"payload": self.webhook_fixture_data("travis", fixture_name, file_type="json")}
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|