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 CircleCiHookTests ( WebhookTestCase ) :
2020-06-12 20:19:07 +02:00
STREAM_NAME = " circleci "
2020-04-09 21:51:58 +02:00
URL_TEMPLATE = " /api/v1/external/circleci?stream= {stream} &api_key= {api_key} "
2021-06-26 09:18:33 +02:00
WEBHOOK_DIR_NAME = " circleci "
2020-06-12 20:19:07 +02:00
2022-10-02 08:48:28 +02:00
def test_bitbucket_job_completed ( self ) - > None :
expected_topic = " circleci-webhook-testing "
2020-06-12 20:19:07 +02:00
expected_message = """
2022-10-02 08:48:28 +02:00
Job ` build - and - test ` within Pipeline #4 has succeeded.
Triggered on [ ` 8 ab595d2de9 : app . py edited online with Bitbucket ` ] ( https : / / bitbucket . org / hariprashant1 / circleci - webhook - testing / commits / 8 ab595d2de95767993472837df2cb7884519a92b ) on branch ` master ` by Hari Prashant Bhimaraju .
""" .strip()
self . check_webhook ( " bitbucket_job_completed " , expected_topic , expected_message )
def test_bitbucket_manual_workflow_completed ( self ) - > None :
expected_topic = " circleci-webhook-testing "
expected_message = """
Workflow [ ` sample ` ] ( https : / / app . circleci . com / pipelines / bitbucket / hariprashant1 / circleci - webhook - testing / 2 / workflows / baa45986 - 84 db - 47 a0 - bc6c - 89e9 fe751bc9 ) within Pipeline #2 has succeeded.
Triggered on ` master ` ' s HEAD on [cab5eacb4cc](https://bitbucket.org/hariprashant1/circleci-webhook-testing/commits/cab5eacb4ccee2710529894425341fa20a48fe6a).
""" .strip()
self . check_webhook ( " bitbucket_manual_workflow_completed " , expected_topic , expected_message )
def test_bitbucket_workflow_completed ( self ) - > None :
expected_topic = " circleci-webhook-testing "
expected_message = """
Workflow [ ` sample ` ] ( https : / / app . circleci . com / pipelines / bitbucket / hariprashant1 / circleci - webhook - testing / 4 / workflows / fd29ef0c - 3e39 - 4 c8f - b1d5 - d8be1bab8165 ) within Pipeline #4 has succeeded.
Triggered on [ ` 8 ab595d2de9 : app . py edited online with Bitbucket ` ] ( https : / / bitbucket . org / hariprashant1 / circleci - webhook - testing / commits / 8 ab595d2de95767993472837df2cb7884519a92b ) on branch ` master ` by Hari Prashant Bhimaraju .
2020-06-12 20:19:07 +02:00
""" .strip()
2022-10-02 08:48:28 +02:00
self . check_webhook ( " bitbucket_workflow_completed " , expected_topic , expected_message )
2020-06-12 20:19:07 +02:00
2022-10-02 08:48:28 +02:00
def test_github_job_completed ( self ) - > None :
expected_topic = " circleci-webhook-test "
2020-06-12 20:19:07 +02:00
expected_message = """
2022-10-02 08:48:28 +02:00
Job ` build - and - test ` within Pipeline #4 has succeeded.
2020-06-12 20:19:07 +02:00
2022-10-02 08:48:28 +02:00
Triggered on [ ` a5e30a90822 : . circleci : Update Webhook URL . ` ] ( https : / / github . com / zulip - testing / circleci - webhook - test / commit / a5e30a908224e46626a796d058289475f6d387b5 ) on branch ` main ` by Hari Prashant Bhimaraju .
2020-06-12 20:19:07 +02:00
""" .strip()
2022-10-02 08:48:28 +02:00
self . check_webhook ( " github_job_completed " , expected_topic , expected_message )
2020-06-12 20:19:07 +02:00
2022-10-02 08:48:28 +02:00
def test_github_tag_workflow_completed ( self ) - > None :
expected_topic = " circleci-webhook-test "
2020-06-12 20:19:07 +02:00
expected_message = """
2022-10-02 08:48:28 +02:00
Workflow [ ` sample ` ] ( https : / / app . circleci . com / pipelines / github / prah23 / circleci - webhook - test / 20 / workflows / 045 c6271 - 78e2 - 4802 - 8 a62 - f4fa6d25d0c9 ) within Pipeline #20 has succeeded.
2020-06-12 20:19:07 +02:00
2022-10-02 08:48:28 +02:00
Triggered on the latest tag on [ 0e6 e66c14e6 ] ( https : / / github . com / prah23 / circleci - webhook - test / commit / 0e6 e66c14e61fbcd95db716b0f30d67dbcce7814 ) .
2020-06-12 20:19:07 +02:00
""" .strip()
2022-10-02 08:48:28 +02:00
self . check_webhook ( " github_tag_workflow_completed " , expected_topic , expected_message )
def test_github_workflow_completed ( self ) - > None :
expected_topic = " circleci-webhook-test "
expected_message = """
Workflow [ ` sample ` ] ( https : / / app . circleci . com / pipelines / github / zulip - testing / circleci - webhook - test / 4 / workflows / 7381218 b - d04c - 4 aa3 - b8b8 - 8 c00a9319d1f ) within Pipeline #4 has succeeded.
Triggered on [ ` a5e30a90822 : . circleci : Update Webhook URL . ` ] ( https : / / github . com / zulip - testing / circleci - webhook - test / commit / a5e30a908224e46626a796d058289475f6d387b5 ) on branch ` main ` by Hari Prashant Bhimaraju .
""" .strip()
self . check_webhook ( " github_workflow_completed " , expected_topic , expected_message )
def test_gitlab_job_completed ( self ) - > None :
expected_topic = " circleci-webhook-test "
expected_message = """
Job ` build - and - test ` within Pipeline #3 has succeeded.
Triggered on [ ` c31f86994c5 : app : Enhance message within hello ( ) . ` ] ( https : / / gitlab . com / zulip - testing / circleci - webhook - test / - / commit / c31f86994c54672f97b5bd5e544315b7bd40e4c1 ) on branch ` main ` by Hari Prashant Bhimaraju .
""" .strip()
self . check_webhook ( " gitlab_job_completed " , expected_topic , expected_message )
def test_gitlab_workflow_completed ( self ) - > None :
expected_topic = " circleci-webhook-test "
2020-06-12 20:19:07 +02:00
expected_message = """
2022-10-02 08:48:28 +02:00
Workflow [ ` sample ` ] ( https : / / app . circleci . com / pipelines / circleci / 89 xcrx7UvWQfzcUPAEmu5Q / 63 AY3yf3XeUQojmQcGZTtB / 3 / workflows / b23ceb64 - 127 a - 4075 - a27c - d204a7a0a3b3 ) within Pipeline #3 has succeeded.
2020-06-12 20:19:07 +02:00
2022-10-02 08:48:28 +02:00
Triggered on [ ` c31f86994c5 : app : Enhance message within hello ( ) . ` ] ( https : / / gitlab . com / zulip - testing / circleci - webhook - test / - / commit / c31f86994c54672f97b5bd5e544315b7bd40e4c1 ) on branch ` main ` by Hari Prashant Bhimaraju .
2020-06-12 20:19:07 +02:00
""" .strip()
2022-10-02 08:48:28 +02:00
self . check_webhook ( " gitlab_workflow_completed " , expected_topic , expected_message )