Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks/gitlab: Remove redundant Pipeline Hook fixtures.
Niloth Pa53ededc3c86
diff --git a/zerver/webhooks/gitlab/fixtures/pipeline_hook__pipeline_pending.json b/zerver/webhooks/gitlab/fixtures/pipeline_hook.jsonsimilarity index 100%rename from zerver/webhooks/gitlab/fixtures/pipeline_hook__pipeline_pending.jsonrename to zerver/webhooks/gitlab/fixtures/pipeline_hook.jsondiff --git a/zerver/webhooks/gitlab/fixtures/pipeline_hook__pipeline_started.json b/zerver/webhooks/gitlab/fixtures/pipeline_hook__pipeline_started.jsondeleted file mode 100644index bb55227c5a3..00000000000--- a/zerver/webhooks/gitlab/fixtures/pipeline_hook__pipeline_started.json+++ /dev/null@@ -1,93 +0,0 @@-{- "object_kind":"pipeline",- "object_attributes":{- "id":4414206,- "ref":"master",- "tag":false,- "sha":"6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "before_sha":"6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "status":"running",- "stages":[- "test"- ],- "created_at":"2016-09-28 20:04:55 UTC",- "finished_at":null,- "duration":0- },- "user":{- "name":"Tomasz Kolek",- "username":"TomaszKolek",- "avatar_url":"https://secure.gravatar.com/avatar/c80a7a8454ed7d9e3c5618f1748385c2?s=80\u0026d=identicon"- },- "project":{- "name":"my-awesome-project",- "description":"abc",- "web_url":"https://gitlab.com/TomaszKolek/my-awesome-project",- "avatar_url":null,- "git_ssh_url":"[email protected]:TomaszKolek/my-awesome-project.git",- "git_http_url":"https://gitlab.com/TomaszKolek/my-awesome-project.git",- "namespace":"TomaszKolek",- "visibility_level":20,- "path_with_namespace":"TomaszKolek/my-awesome-project",- "default_branch":"master"- },- "commit":{- "id":"6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "message":"a\n",- "timestamp":"2016-09-28T22:04:48+02:00",- "url":"https://gitlab.com/TomaszKolek/my-awesome-project/commit/6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "author":{- "name":"Tomasz Kolek",- "email":"[email protected]"- }- },- "builds":[- {- "id":4541112,- "stage":"test",- "name":"job_name",- "status":"running",- "created_at":"2016-09-28 20:04:55 UTC",- "started_at":"2016-09-28 20:21:04 UTC",- "finished_at":null,- "when":"on_success",- "manual":false,- "user":{- "name":"Tomasz Kolek",- "username":"TomaszKolek",- "avatar_url":"https://secure.gravatar.com/avatar/c80a7a8454ed7d9e3c5618f1748385c2?s=80\u0026d=identicon"- },- "runner":{- "id":21099,- "description":"shared-runners-manager-2.gitlab.com",- "active":true,- "is_shared":true- },- "artifacts_file":{- "filename":null,- "size":null- }- },- {- "id":4541113,- "stage":"test",- "name":"job_name2",- "status":"pending",- "created_at":"2016-09-28 20:04:56 UTC",- "started_at":null,- "finished_at":null,- "when":"on_success",- "manual":false,- "user":{- "name":"Tomasz Kolek",- "username":"TomaszKolek",- "avatar_url":"https://secure.gravatar.com/avatar/c80a7a8454ed7d9e3c5618f1748385c2?s=80\u0026d=identicon"- },- "runner":null,- "artifacts_file":{- "filename":null,- "size":null- }- }- ]-}diff --git a/zerver/webhooks/gitlab/fixtures/pipeline_hook__pipeline_succeeded.json b/zerver/webhooks/gitlab/fixtures/pipeline_hook__pipeline_succeeded.jsondeleted file mode 100644index e72809ba104..00000000000--- a/zerver/webhooks/gitlab/fixtures/pipeline_hook__pipeline_succeeded.json+++ /dev/null@@ -1,98 +0,0 @@-{- "object_kind":"pipeline",- "object_attributes":{- "id":4414206,- "ref":"master",- "tag":false,- "sha":"6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "before_sha":"6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "status":"success",- "stages":[- "test"- ],- "created_at":"2016-09-28 20:04:55 UTC",- "finished_at":"2016-09-28 20:22:34 UTC",- "duration":84- },- "user":{- "name":"Tomasz Kolek",- "username":"TomaszKolek",- "avatar_url":"https://secure.gravatar.com/avatar/c80a7a8454ed7d9e3c5618f1748385c2?s=80\u0026d=identicon"- },- "project":{- "name":"my-awesome-project",- "description":"abc",- "web_url":"https://gitlab.com/TomaszKolek/my-awesome-project",- "avatar_url":null,- "git_ssh_url":"[email protected]:TomaszKolek/my-awesome-project.git",- "git_http_url":"https://gitlab.com/TomaszKolek/my-awesome-project.git",- "namespace":"TomaszKolek",- "visibility_level":20,- "path_with_namespace":"TomaszKolek/my-awesome-project",- "default_branch":"master"- },- "commit":{- "id":"6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "message":"a\n",- "timestamp":"2016-09-28T22:04:48+02:00",- "url":"https://gitlab.com/TomaszKolek/my-awesome-project/commit/6f88e719ccde3804b1b669cef9dfb236a92fbbff",- "author":{- "name":"Tomasz Kolek",- "email":"[email protected]"- }- },- "builds":[- {- "id":4541113,- "stage":"test",- "name":"job_name2",- "status":"success",- "created_at":"2016-09-28 20:04:56 UTC",- "started_at":"2016-09-28 20:21:52 UTC",- "finished_at":"2016-09-28 20:22:34 UTC",- "when":"on_success",- "manual":false,- "user":{- "name":"Tomasz Kolek",- "username":"TomaszKolek",- "avatar_url":"https://secure.gravatar.com/avatar/c80a7a8454ed7d9e3c5618f1748385c2?s=80\u0026d=identicon"- },- "runner":{- "id":21099,- "description":"shared-runners-manager-2.gitlab.com",- "active":true,- "is_shared":true- },- "artifacts_file":{- "filename":null,- "size":null- }- },- {- "id":4541112,- "stage":"test",- "name":"job_name",- "status":"success",- "created_at":"2016-09-28 20:04:55 UTC",- "started_at":"2016-09-28 20:21:04 UTC",- "finished_at":"2016-09-28 20:21:47 UTC",- "when":"on_success",- "manual":false,- "user":{- "name":"Tomasz Kolek",- "username":"TomaszKolek",- "avatar_url":"https://secure.gravatar.com/avatar/c80a7a8454ed7d9e3c5618f1748385c2?s=80\u0026d=identicon"- },- "runner":{- "id":21099,- "description":"shared-runners-manager-2.gitlab.com",- "active":true,- "is_shared":true- },- "artifacts_file":{- "filename":null,- "size":null- }- }- ]-}diff --git a/zerver/webhooks/gitlab/fixtures/pipeline_hook__pipeline_succeeded_with_artifacts.json b/zerver/webhooks/gitlab/fixtures/pipeline_hook__with_artifacts.jsonsimilarity index 100%rename from zerver/webhooks/gitlab/fixtures/pipeline_hook__pipeline_succeeded_with_artifacts.jsonrename to zerver/webhooks/gitlab/fixtures/pipeline_hook__with_artifacts.jsondiff --git a/zerver/webhooks/gitlab/tests.py b/zerver/webhooks/gitlab/tests.pyindex e0c5c2b5d07..22780efd812 100644--- a/zerver/webhooks/gitlab/tests.py+++ b/zerver/webhooks/gitlab/tests.py@@ -457,45 +457,55 @@ A trivial change that should probably be ignored.custom_payload=payload,)- def test_pipeline_succeeded_with_artifacts_event_message(self) -> None:+ def test_pipeline_with_artifacts_event_message(self) -> None:expected_topic_name = "onlysomeproject / test/links-in-zulip-pipeline-message"expected_message = "[Pipeline (22668)](https://gitlab.example.com/group1/onlysomeproject/-/pipelines/22668) changed status to success with build(s):\n* [cleanup:cleanup docker image](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58592) - success\n* [pages](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591) - success\n * built artifact: *artifacts.zip* [[Browse](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591/artifacts/browse)|[Download](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58591/artifacts/download)]\n* [black+pytest:future environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58590) - success\n* [docs:anaconda environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589) - success\n * built artifact: *sphinx-docs.zip* [[Browse](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589/artifacts/browse)|[Download](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58589/artifacts/download)]\n* [pytest:current environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58588) - success\n* [black:current environment](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58587) - success\n* [setup:docker image](https://gitlab.example.com/group1/onlysomeproject/-/jobs/58586) - success."self.check_webhook(- "pipeline_hook__pipeline_succeeded_with_artifacts",+ "pipeline_hook__with_artifacts",expected_topic_name,expected_message,)- def test_pipeline_succeeded_event_message(self) -> None:+ def test_pipeline_event_messages(self) -> None:+ pipeline_link = "[Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/-/pipelines/4414206)"+ job_link = "[job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112)"+ job2_link = "[job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113)"expected_topic_name = "my-awesome-project / master"- expected_message = "[Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/-/pipelines/4414206) changed status to success with build(s):\n* [job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113) - success\n* [job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112) - success."- self.check_webhook(- "pipeline_hook__pipeline_succeeded",- expected_topic_name,- expected_message,- )-- def test_pipeline_started_event_message(self) -> None:- expected_topic_name = "my-awesome-project / master"- expected_message = "[Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/-/pipelines/4414206) started with build(s):\n* [job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112) - running\n* [job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113) - pending."-- self.check_webhook(- "pipeline_hook__pipeline_started",- expected_topic_name,- expected_message,- )+ # Each case is a pipeline status, the status of each of the+ # pipeline's builds keyed by build name, and the expected message.+ test_cases = [+ (+ "pending",+ {"job_name2": "pending", "job_name": "created"},+ f"{pipeline_link} was created with build(s):\n* {job2_link} - pending\n* {job_link} - created.",+ ),+ (+ "running",+ {"job_name2": "pending", "job_name": "running"},+ f"{pipeline_link} started with build(s):\n* {job2_link} - pending\n* {job_link} - running.",+ ),+ (+ "success",+ {"job_name2": "success", "job_name": "success"},+ f"{pipeline_link} changed status to success with build(s):\n* {job2_link} - success\n* {job_link} - success.",+ ),+ ]- def test_pipeline_pending_event_message(self) -> None:- expected_topic_name = "my-awesome-project / master"- expected_message = "[Pipeline (4414206)](https://gitlab.com/TomaszKolek/my-awesome-project/-/pipelines/4414206) was created with build(s):\n* [job_name2](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541113) - pending\n* [job_name](https://gitlab.com/TomaszKolek/my-awesome-project/-/jobs/4541112) - created."+ payload = orjson.loads(self.get_body("pipeline_hook"))- self.check_webhook(- "pipeline_hook__pipeline_pending",- expected_topic_name,- expected_message,- )+ for pipeline_status, build_statuses, expected_message in test_cases:+ with self.subTest(pipeline_status=pipeline_status):+ payload["object_attributes"]["status"] = pipeline_status+ for build in payload["builds"]:+ build["status"] = build_statuses[build["name"]]+ self.check_webhook(+ "pipeline_hook",+ expected_topic_name,+ expected_message,+ custom_payload=payload,+ )def test_issue_type_test_payload(self) -> None:expected_topic_name = "public-repo"