Some checks failed
Code scanning / CodeQL (push) Failing after 15s
Zulip production suite / Ubuntu 22.04 production build (push) Failing after 26s
Zulip production suite / Debian 12 production install with custom db name and user (push) Has been skipped
Zulip production suite / Ubuntu 22.04 production install and PostgreSQL upgrade with pgroonga (push) Has been skipped
Zulip production suite / Ubuntu 24.04 production install (push) Has been skipped
Zulip production suite / Ubuntu 26.04 production install (push) Has been skipped
Zulip production suite / Debian 13 production install (push) Has been skipped
Zulip production suite / 7.0 Version Upgrade (push) Has been skipped
Zulip production suite / 8.0 Version Upgrade (push) Has been skipped
Zulip production suite / 6.0 Version Upgrade (push) Has been skipped
Zulip production suite / 10.0 Version Upgrade (push) Has been skipped
Zulip production suite / 9.0 Version Upgrade (push) Has been skipped
Zulip production suite / 12.0 Version Upgrade (push) Has been skipped
Zulip production suite / 11.0 Version Upgrade (push) Has been skipped
GitHub Actions Security Analysis with zizmor / zizmor (push) Failing after 3s
Zulip CI / Debian 12 (Python 3.11, backend + documentation) (push) Failing after 26s
Zulip CI / Ubuntu 22.04 (Python 3.10, backend + frontend) (push) Failing after 3s
Zulip CI / Ubuntu 24.04 (Python 3.12, backend) (push) Failing after 25s
Zulip CI / Ubuntu 26.04 (Python 3.14, backend) (push) Failing after 25s
Zulip CI / Debian 13 (Python 3.13, backend) (push) Failing after 28s
Zulip production suite / Required jobs (push) Has been cancelled
Zulip CI / Required jobs (push) Has been cancelled
API Documentation Update Check / check-feature-level-updated (push) Has been cancelled
API Documentation Update Check / notify-if-api-docs-changed (push) Has been cancelled
177 lines
5.8 KiB
Python
177 lines
5.8 KiB
Python
from urllib.parse import urlencode
|
|
|
|
import orjson
|
|
from typing_extensions import override
|
|
|
|
from zerver.lib.test_classes import WebhookTestCase
|
|
|
|
|
|
class TravisHookTests(WebhookTestCase):
|
|
NON_PR_TOPIC = "travis-test / main"
|
|
PR_TOPIC = "travis-test / PR #2 feat: Add Name.txt."
|
|
|
|
EXPECTED_NON_PULL_REQUEST_MESSAGE = (
|
|
":time_ticking: Build [#1](https://app.travis-ci.com/sathwikshetty33/travis-test/builds/277712204) "
|
|
"**is in progress** for commit [Add Projects model.](https://github.com/sathwikshetty33/travis-test/commit/193da1b72346) by sathwikshetty33"
|
|
)
|
|
|
|
EXPECTED_PULL_REQUEST_MESSAGE = (
|
|
":warning: Build [#42](https://app.travis-ci.com/sathwikshetty33/travis-test/builds/277927122) "
|
|
"**failed** for commit [feat: Created Name.txt.](https://github.com/sathwikshetty33/travis-test/pull/2) by Sathwik Shetty."
|
|
)
|
|
|
|
def test_travis_message(self) -> None:
|
|
"""
|
|
Build notifications are generated by Travis after build completes.
|
|
|
|
The subject describes the repo and Stash "project". The
|
|
content describes the commits pushed.
|
|
"""
|
|
|
|
self.check_webhook(
|
|
"non_pull_request",
|
|
self.NON_PR_TOPIC,
|
|
f"{self.EXPECTED_NON_PULL_REQUEST_MESSAGE}.",
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|
|
|
|
def test_travis_only_pull_request_event(self) -> None:
|
|
self.url = f'{self.build_webhook_url()}&only_events=["pull_request"]'
|
|
|
|
self.check_webhook(
|
|
"pull_request",
|
|
self.PR_TOPIC,
|
|
self.EXPECTED_PULL_REQUEST_MESSAGE,
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|
|
|
|
self.check_webhook(
|
|
"non_pull_request",
|
|
content_type="application/x-www-form-urlencoded",
|
|
expect_noop=True,
|
|
)
|
|
|
|
def test_travis_exclude_pull_request_event(self) -> None:
|
|
self.url = f'{self.build_webhook_url()}&exclude_events=["pull_request"]'
|
|
|
|
self.check_webhook(
|
|
"pull_request",
|
|
content_type="application/x-www-form-urlencoded",
|
|
expect_noop=True,
|
|
)
|
|
|
|
self.check_webhook(
|
|
"non_pull_request",
|
|
self.NON_PR_TOPIC,
|
|
f"{self.EXPECTED_NON_PULL_REQUEST_MESSAGE}.",
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|
|
|
|
def test_travis_only_push_event(self) -> None:
|
|
self.url = f'{self.build_webhook_url()}&only_events=["push"]'
|
|
|
|
self.check_webhook(
|
|
"non_pull_request",
|
|
self.NON_PR_TOPIC,
|
|
f"{self.EXPECTED_NON_PULL_REQUEST_MESSAGE}.",
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|
|
|
|
self.check_webhook(
|
|
"pull_request",
|
|
content_type="application/x-www-form-urlencoded",
|
|
expect_noop=True,
|
|
)
|
|
|
|
def test_travis_exclude_push_event(self) -> None:
|
|
self.url = f'{self.build_webhook_url()}&exclude_events=["push"]'
|
|
|
|
self.check_webhook(
|
|
"non_pull_request",
|
|
content_type="application/x-www-form-urlencoded",
|
|
expect_noop=True,
|
|
)
|
|
|
|
self.check_webhook(
|
|
"pull_request",
|
|
self.PR_TOPIC,
|
|
self.EXPECTED_PULL_REQUEST_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=["*"]'
|
|
|
|
self.check_webhook(
|
|
"pull_request",
|
|
self.PR_TOPIC,
|
|
self.EXPECTED_PULL_REQUEST_MESSAGE,
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|
|
|
|
self.check_webhook(
|
|
"non_pull_request",
|
|
self.NON_PR_TOPIC,
|
|
f"{self.EXPECTED_NON_PULL_REQUEST_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=["*"]'
|
|
|
|
self.check_webhook(
|
|
"pull_request",
|
|
content_type="application/x-www-form-urlencoded",
|
|
expect_noop=True,
|
|
)
|
|
|
|
self.check_webhook(
|
|
"non_pull_request",
|
|
content_type="application/x-www-form-urlencoded",
|
|
expect_noop=True,
|
|
)
|
|
|
|
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(
|
|
"non_pull_request",
|
|
content_type="application/x-www-form-urlencoded",
|
|
expect_noop=True,
|
|
)
|
|
self.assertEqual(str(exc.exception), expected_error_message)
|
|
|
|
@override
|
|
def get_body(self, fixture_name: str) -> str:
|
|
if fixture_name in {"api", "cron"}:
|
|
payload = orjson.loads(
|
|
self.webhook_fixture_data("travis", "non_pull_request", file_type="json")
|
|
)
|
|
payload["type"] = fixture_name
|
|
return urlencode({"payload": orjson.dumps(payload).decode()})
|
|
|
|
return urlencode(
|
|
{"payload": self.webhook_fixture_data("travis", fixture_name, file_type="json")}
|
|
)
|
|
|
|
def test_travis_api_event(self) -> None:
|
|
self.check_webhook(
|
|
"api",
|
|
self.NON_PR_TOPIC,
|
|
f"{self.EXPECTED_NON_PULL_REQUEST_MESSAGE} (triggered by api).",
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|
|
|
|
def test_travis_cron_event(self) -> None:
|
|
self.check_webhook(
|
|
"cron",
|
|
self.NON_PR_TOPIC,
|
|
f"{self.EXPECTED_NON_PULL_REQUEST_MESSAGE} (triggered by cron).",
|
|
content_type="application/x-www-form-urlencoded",
|
|
)
|