From 0b8e042627f442687740e5e46f8c5eac2afbed29 Mon Sep 17 00:00:00 2001 From: Niloth P <20315308+Niloth-p@users.noreply.github.com> Date: Wed, 28 May 2025 03:28:55 +0530 Subject: [PATCH] integrations: Split the getters for fixture_path and image_path. This is in preparation of adding support for generating screenshots of fixtureless integrations, which would need to get image_path, without involving fixture_path. --- .../screenshots/generate-integration-docs-screenshot | 6 ++++-- zerver/lib/integrations.py | 10 +++++++--- zerver/tests/test_integrations.py | 11 ++++++----- 3 files changed, 17 insertions(+), 10 deletions(-) diff --git a/tools/screenshots/generate-integration-docs-screenshot b/tools/screenshots/generate-integration-docs-screenshot index cbd14c4400..feb2a844fd 100755 --- a/tools/screenshots/generate-integration-docs-screenshot +++ b/tools/screenshots/generate-integration-docs-screenshot @@ -42,7 +42,8 @@ from zerver.lib.integrations import ( Integration, WebhookIntegration, WebhookScreenshotConfig, - get_fixture_and_image_paths, + get_fixture_path, + get_image_path, split_fixture_path, ) from zerver.lib.storage import static_path @@ -220,7 +221,8 @@ def generate_screenshot_from_config( ) -> None: integration = INTEGRATIONS[integration_name] assert isinstance(integration, WebhookIntegration) - fixture_path, image_path = get_fixture_and_image_paths(integration, screenshot_config) + fixture_path = get_fixture_path(integration, screenshot_config) + image_path = get_image_path(integration, screenshot_config) bot = create_integration_bot(integration, screenshot_config.bot_name) create_integration_stream(integration, bot) if send_bot_payload_message(bot, integration, fixture_path, screenshot_config): diff --git a/zerver/lib/integrations.py b/zerver/lib/integrations.py index 0805d63528..c265e2c315 100644 --- a/zerver/lib/integrations.py +++ b/zerver/lib/integrations.py @@ -314,15 +314,19 @@ class WebhookScreenshotConfig: custom_headers: dict[str, str] = field(default_factory=dict) -def get_fixture_and_image_paths( +def get_fixture_path( integration: WebhookIntegration, screenshot_config: WebhookScreenshotConfig -) -> tuple[str, str]: +) -> str: fixture_dir = os.path.join("zerver", "webhooks", integration.dir_name, "fixtures") fixture_path = os.path.join(fixture_dir, screenshot_config.fixture_name) + return fixture_path + + +def get_image_path(integration: Integration, screenshot_config: WebhookScreenshotConfig) -> str: image_dir = screenshot_config.image_dir or integration.name image_name = screenshot_config.image_name image_path = os.path.join("static/images/integrations", image_dir, image_name) - return fixture_path, image_path + return image_path class HubotIntegration(Integration): diff --git a/zerver/tests/test_integrations.py b/zerver/tests/test_integrations.py index 7c0331424e..b77508901d 100644 --- a/zerver/tests/test_integrations.py +++ b/zerver/tests/test_integrations.py @@ -7,7 +7,8 @@ from zerver.lib.integrations import ( WEBHOOK_INTEGRATIONS, WebhookIntegration, WebhookScreenshotConfig, - get_fixture_and_image_paths, + get_fixture_path, + get_image_path, split_fixture_path, ) from zerver.lib.test_classes import ZulipTestCase @@ -24,7 +25,8 @@ class IntegrationsTestCase(ZulipTestCase): integration = INTEGRATIONS["airbrake"] assert isinstance(integration, WebhookIntegration) screenshot_config = WebhookScreenshotConfig("error_message.json", "002.png", "ci") - fixture_path, image_path = get_fixture_and_image_paths(integration, screenshot_config) + fixture_path = get_fixture_path(integration, screenshot_config) + image_path = get_image_path(integration, screenshot_config) self.assertEqual(fixture_path, "zerver/webhooks/airbrake/fixtures/error_message.json") self.assertEqual(image_path, "static/images/integrations/ci/002.png") @@ -63,13 +65,12 @@ class IntegrationsTestCase(ZulipTestCase): # Such screenshot configs only use a placeholder # fixture_name. continue - fixture_path, image_path = get_fixture_and_image_paths( - integration, screenshot_config - ) + fixture_path = get_fixture_path(integration, screenshot_config) self.assertTrue( os.path.isfile(fixture_path), message.format(path=fixture_path, webhook_name=integration_name), ) + image_path = get_image_path(integration, screenshot_config) self.assertTrue( os.path.isfile(image_path), message.format(path=image_path, webhook_name=integration_name),