2020-04-26 08:35:53 +02:00
|
|
|
from zerver.lib.integrations import (
|
2020-06-11 00:54:34 +02:00
|
|
|
DOC_SCREENSHOT_CONFIG,
|
|
|
|
INTEGRATIONS,
|
|
|
|
NO_SCREENSHOT_WEBHOOKS,
|
|
|
|
WEBHOOK_INTEGRATIONS,
|
2021-03-29 23:04:31 +02:00
|
|
|
BaseScreenshotConfig,
|
|
|
|
Integration,
|
2020-06-11 00:54:34 +02:00
|
|
|
ScreenshotConfig,
|
|
|
|
WebhookIntegration,
|
|
|
|
get_fixture_and_image_paths,
|
|
|
|
split_fixture_path,
|
|
|
|
)
|
|
|
|
from zerver.lib.test_classes import ZulipTestCase
|
|
|
|
|
2020-04-09 19:33:49 +02:00
|
|
|
|
|
|
|
class IntegrationsTestCase(ZulipTestCase):
|
|
|
|
def test_split_fixture_path(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
path = "zerver/webhooks/semaphore/fixtures/push.json"
|
2020-04-09 19:33:49 +02:00
|
|
|
integration_name, fixture_name = split_fixture_path(path)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(integration_name, "semaphore")
|
|
|
|
self.assertEqual(fixture_name, "push")
|
2020-04-26 08:35:53 +02:00
|
|
|
|
|
|
|
def test_get_fixture_and_image_paths(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
integration = INTEGRATIONS["airbrake"]
|
2020-04-26 08:35:53 +02:00
|
|
|
assert isinstance(integration, WebhookIntegration)
|
2021-02-12 08:20:45 +01:00
|
|
|
screenshot_config = ScreenshotConfig("error_message.json", "002.png", "ci")
|
2020-04-26 08:35:53 +02:00
|
|
|
fixture_path, image_path = get_fixture_and_image_paths(integration, screenshot_config)
|
2021-02-12 08:20:45 +01:00
|
|
|
self.assertEqual(fixture_path, "zerver/webhooks/airbrake/fixtures/error_message.json")
|
|
|
|
self.assertEqual(image_path, "static/images/integrations/ci/002.png")
|
2020-04-26 10:35:13 +02:00
|
|
|
|
2021-03-29 23:04:31 +02:00
|
|
|
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")
|
|
|
|
|
2020-05-15 09:45:06 +02:00
|
|
|
def test_get_bot_avatar_path(self) -> None:
|
2021-02-12 08:20:45 +01:00
|
|
|
integration = INTEGRATIONS["alertmanager"]
|
2021-02-12 08:19:30 +01:00
|
|
|
self.assertEqual(
|
2021-02-12 08:20:45 +01:00
|
|
|
integration.get_bot_avatar_path(), "images/integrations/bot_avatars/prometheus.png"
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2020-05-15 09:45:06 +02:00
|
|
|
|
|
|
|
# New instance with logo parameter not set
|
2021-02-12 08:20:45 +01:00
|
|
|
integration = WebhookIntegration("alertmanager", ["misc"])
|
2020-05-15 09:45:06 +02:00
|
|
|
self.assertIsNone(integration.get_bot_avatar_path())
|
|
|
|
|
2020-04-26 10:35:13 +02:00
|
|
|
def test_no_missing_doc_screenshot_config(self) -> None:
|
|
|
|
webhook_names = {webhook.name for webhook in WEBHOOK_INTEGRATIONS}
|
|
|
|
webhooks_with_screenshot_config = set(DOC_SCREENSHOT_CONFIG.keys())
|
2021-02-12 08:19:30 +01:00
|
|
|
missing_webhooks = webhook_names - webhooks_with_screenshot_config - NO_SCREENSHOT_WEBHOOKS
|
2020-04-26 10:35:13 +02:00
|
|
|
message = (
|
|
|
|
f"These webhooks are missing screenshot config: {missing_webhooks}.\n"
|
|
|
|
"Add them to zerver.lib.integrations.DOC_SCREENSHOT_CONFIG"
|
|
|
|
)
|
|
|
|
self.assertFalse(missing_webhooks, message)
|