From d20deccee7a872d1ef61a178485a0d2ef25955a6 Mon Sep 17 00:00:00 2001 From: PIG208 <359101898@qq.com> Date: Tue, 30 Mar 2021 05:04:31 +0800 Subject: [PATCH] tests: Add a test for fixtures for non-webhook integrations. This commit create a directory to store the mock message for nagios and more will be added. The json files in this directory will be used to config the screenshot generating script for the documentations of non-webhook integrations. --- zerver/integration_fixtures/nagios/service_notify.json | 4 ++++ zerver/lib/integrations.py | 1 + zerver/tests/test_integrations.py | 10 ++++++++++ 3 files changed, 15 insertions(+) create mode 100644 zerver/integration_fixtures/nagios/service_notify.json diff --git a/zerver/integration_fixtures/nagios/service_notify.json b/zerver/integration_fixtures/nagios/service_notify.json new file mode 100644 index 0000000000..722a7aaeab --- /dev/null +++ b/zerver/integration_fixtures/nagios/service_notify.json @@ -0,0 +1,4 @@ +{ + "subject": "service remote load on postgres.humbughq.com", + "body": "**PROBLEM**: service is CRITICAL\n> CRITICAL - load average: 7.49, 8.20, 4.72" +} diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py index 0a84a64ffa..820df79f98 100644 --- a/zerver/lib/integrations.py +++ b/zerver/lib/integrations.py @@ -741,6 +741,7 @@ DOC_SCREENSHOT_CONFIG: Dict[str, List[BaseScreenshotConfig]] = { "json": [ScreenshotConfig("json_github_push__1_commit.json")], "librato": [ScreenshotConfig("three_conditions_alert.json", payload_as_query_param=True)], "mention": [ScreenshotConfig("webfeeds.json")], + "nagios": [BaseScreenshotConfig("service_notify.json")], "netlify": [ScreenshotConfig("deploy_building.json")], "newrelic": [ScreenshotConfig("alert.txt", "002.png")], "opbeat": [ScreenshotConfig("error_reopen.json")], diff --git a/zerver/tests/test_integrations.py b/zerver/tests/test_integrations.py index 342af981a1..f2ae81fb5f 100644 --- a/zerver/tests/test_integrations.py +++ b/zerver/tests/test_integrations.py @@ -3,6 +3,8 @@ from zerver.lib.integrations import ( INTEGRATIONS, NO_SCREENSHOT_WEBHOOKS, WEBHOOK_INTEGRATIONS, + BaseScreenshotConfig, + Integration, ScreenshotConfig, WebhookIntegration, get_fixture_and_image_paths, @@ -26,6 +28,14 @@ class IntegrationsTestCase(ZulipTestCase): self.assertEqual(fixture_path, "zerver/webhooks/airbrake/fixtures/error_message.json") self.assertEqual(image_path, "static/images/integrations/ci/002.png") + def test_get_fixture_and_image_paths_non_webhook(self) -> None: + integration = INTEGRATIONS["nagios"] + assert isinstance(integration, Integration) + screenshot_config = BaseScreenshotConfig("service_notify.json", "001.png") + fixture_path, image_path = get_fixture_and_image_paths(integration, screenshot_config) + self.assertEqual(fixture_path, "zerver/integration_fixtures/nagios/service_notify.json") + self.assertEqual(image_path, "static/images/integrations/nagios/001.png") + def test_get_bot_avatar_path(self) -> None: integration = INTEGRATIONS["alertmanager"] self.assertEqual(