Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
integrations: Remove support for non-webhook example screenshots.
Niloth P9f92ae710f4c
diff --git a/tools/screenshots/generate-integration-docs-screenshot b/tools/screenshots/generate-integration-docs-screenshotindex bacde015f76..db69a000012 100755--- a/tools/screenshots/generate-integration-docs-screenshot+++ b/tools/screenshots/generate-integration-docs-screenshot@@ -30,7 +30,6 @@ django.setup()import orjsonimport requests-import zulipfrom scripts.lib.zulip_tools import BOLDRED, ENDCfrom tools.lib.test_script import prepare_puppeteer_run@@ -40,7 +39,6 @@ from zerver.actions.user_settings import do_change_avatar_fieldsfrom zerver.lib.integrations import (DOC_SCREENSHOT_CONFIG,INTEGRATIONS,- BaseScreenshotConfig,Integration,ScreenshotConfig,WebhookIntegration,@@ -118,11 +116,6 @@ def get_fixture_info(fixture_path: str) -> tuple[Any, bool, bool, str]:return data, json_fixture, multipart_fixture, fixture_name-def get_integration(integration_name: str) -> Integration:- integration = INTEGRATIONS[integration_name]- return integration--def get_requests_headers(integration_name: str, fixture_name: str) -> dict[str, Any]:headers = get_fixture_http_headers(integration_name, fixture_name)@@ -144,31 +137,6 @@ def custom_headers(headers_json: str) -> dict[str, str]:)-def send_bot_mock_message(bot: UserProfile, integration: Integration, fixture_path: str) -> None:- # Delete all messages, so new message is the only one it's message group- Message.objects.filter(realm_id=bot.realm_id, sender=bot).delete()- data, _, _, _ = get_fixture_info(fixture_path)-- assert bot.bot_owner is not None- url = f"{bot.bot_owner.realm.url}"- client = zulip.Client(email=bot.email, api_key=bot.api_key, site=url)-- try:- request = {- "type": "stream",- "to": integration.stream_name,- "topic": data["subject"],- "content": data["body"],- }- client.send_message(request)- except KeyError:- print(- f"{fixture_path} contains invalid configuration. "- 'Fields "subject" and "body" are required for non-webhook integrations.'- )- sys.exit(1)--def send_bot_payload_message(bot: UserProfile, integration: WebhookIntegration, fixture_path: str, config: ScreenshotConfig) -> bool:@@ -245,21 +213,14 @@ def capture_last_message_screenshot(bot: UserProfile, image_path: str) -> None:def generate_screenshot_from_config(- integration_name: str, screenshot_config: BaseScreenshotConfig+ integration_name: str, screenshot_config: ScreenshotConfig) -> None:- integration = get_integration(integration_name)+ integration = INTEGRATIONS[integration_name]+ assert isinstance(integration, WebhookIntegration)fixture_path, image_path = get_fixture_and_image_paths(integration, screenshot_config)bot = create_integration_bot(integration, screenshot_config.bot_name)create_integration_stream(integration, bot)- if isinstance(integration, WebhookIntegration):- assert isinstance(screenshot_config, ScreenshotConfig), (- "Webhook integrations require ScreenshotConfig"- )- message_sent = send_bot_payload_message(bot, integration, fixture_path, screenshot_config)- else:- send_bot_mock_message(bot, integration, fixture_path)- message_sent = True- if message_sent:+ if send_bot_payload_message(bot, integration, fixture_path, screenshot_config):capture_last_message_screenshot(bot, image_path)print(f"Screenshot captured to: {BOLDRED}{image_path}{ENDC}")diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.pyindex 2c9e7d7b029..04c22bc4f48 100644--- a/zerver/lib/integrations.py+++ b/zerver/lib/integrations.py@@ -302,15 +302,11 @@ def split_fixture_path(path: str) -> tuple[str, str]:@dataclass-class BaseScreenshotConfig:+class ScreenshotConfig:fixture_name: strimage_name: str = "001.png"image_dir: str | None = Nonebot_name: str | None = None---@dataclass-class ScreenshotConfig(BaseScreenshotConfig):payload_as_query_param: bool = Falsepayload_param_name: str = "payload"extra_params: dict[str, str] = field(default_factory=dict)@@ -319,12 +315,9 @@ class ScreenshotConfig(BaseScreenshotConfig):def get_fixture_and_image_paths(- integration: Integration, screenshot_config: BaseScreenshotConfig+ integration: WebhookIntegration, screenshot_config: ScreenshotConfig) -> tuple[str, str]:- if isinstance(integration, WebhookIntegration):- fixture_dir = os.path.join("zerver", "webhooks", integration.dir_name, "fixtures")- else:- fixture_dir = os.path.join("zerver", "integration_fixtures", integration.name)+ fixture_dir = os.path.join("zerver", "webhooks", integration.dir_name, "fixtures")fixture_path = os.path.join(fixture_dir, screenshot_config.fixture_name)image_dir = screenshot_config.image_dir or integration.nameimage_name = screenshot_config.image_name@@ -695,7 +688,7 @@ NO_SCREENSHOT_WEBHOOKS = {}-DOC_SCREENSHOT_CONFIG: dict[str, list[BaseScreenshotConfig]] = {+DOC_SCREENSHOT_CONFIG: dict[str, list[ScreenshotConfig]] = {"airbrake": [ScreenshotConfig("error_message.json")],"airbyte": [ScreenshotConfig("airbyte_job_payload_success.json")],"alertmanager": [diff --git a/zerver/tests/test_integrations.py b/zerver/tests/test_integrations.pyindex a12f128e149..ad4c7583cba 100644--- a/zerver/tests/test_integrations.py+++ b/zerver/tests/test_integrations.py@@ -5,8 +5,6 @@ from zerver.lib.integrations import (INTEGRATIONS,NO_SCREENSHOT_WEBHOOKS,WEBHOOK_INTEGRATIONS,- BaseScreenshotConfig,- Integration,ScreenshotConfig,WebhookIntegration,get_fixture_and_image_paths,@@ -30,14 +28,6 @@ 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(@@ -68,6 +58,7 @@ class IntegrationsTestCase(ZulipTestCase):configs = DOC_SCREENSHOT_CONFIG[integration_name]for screenshot_config in configs:integration = INTEGRATIONS[integration_name]+ assert isinstance(integration, WebhookIntegration)if screenshot_config.fixture_name == "":# Such screenshot configs only use a placeholder# fixture_name.