test_integrations: Extend tests to cover fixtureless integrations.

Tests for:
- Missing screenshot configs
- Extra/unmatched screenshot configs (since the screenshot configs are
hardcoded)
- Missing screenshot files
This commit is contained in:
Niloth P
2025-05-30 15:57:32 +05:30
committed by Tim Abbott
parent b1376a8cac
commit be5189774b

View File

@@ -1,10 +1,9 @@
import os
from zerver.lib.integrations import (
DOC_SCREENSHOT_CONFIG,
INTEGRATIONS,
NO_SCREENSHOT_WEBHOOKS,
WEBHOOK_INTEGRATIONS,
WEBHOOK_SCREENSHOT_CONFIG,
NO_SCREENSHOT_CONFIG,
WebhookIntegration,
WebhookScreenshotConfig,
get_fixture_path,
@@ -41,11 +40,14 @@ class IntegrationsTestCase(ZulipTestCase):
self.assertIsNone(integration.get_bot_avatar_path())
def test_no_missing_doc_screenshot_config(self) -> None:
webhook_names = {webhook.name for webhook in WEBHOOK_INTEGRATIONS}
webhooks_with_screenshot_config = set(WEBHOOK_SCREENSHOT_CONFIG.keys())
missing_webhooks = webhook_names - webhooks_with_screenshot_config - NO_SCREENSHOT_WEBHOOKS
extra_webhook_configs = webhooks_with_screenshot_config - webhook_names
extra_webhook_no_configs = NO_SCREENSHOT_WEBHOOKS - webhook_names
integration_names = {integration.name for integration in INTEGRATIONS.values()}
integrations_with_screenshot_configs = set(DOC_SCREENSHOT_CONFIG.keys())
missing_integration_screenshots = (
integration_names - integrations_with_screenshot_configs - NO_SCREENSHOT_CONFIG
)
extra_integration_configs = integrations_with_screenshot_configs - integration_names
extra_integration_no_configs = NO_SCREENSHOT_CONFIG - integration_names
def construct_message(title: str, integrations: set[str], action: str) -> str:
return (
@@ -53,21 +55,21 @@ class IntegrationsTestCase(ZulipTestCase):
)
self.assertEqual(
webhooks_with_screenshot_config,
webhook_names - NO_SCREENSHOT_WEBHOOKS,
integrations_with_screenshot_configs,
integration_names - NO_SCREENSHOT_CONFIG,
construct_message(
"The following integrations are missing their example screenshot configuration:",
missing_webhooks,
missing_integration_screenshots,
"Add them to zerver.lib.integrations.DOC_SCREENSHOT_CONFIG",
)
+ construct_message(
"The following integrations have a screenshot configuration but no longer exist:",
extra_webhook_configs,
extra_integration_configs,
"Remove them from zerver.lib.integrations.DOC_SCREENSHOT_CONFIG",
)
+ construct_message(
"The following integrations are listed in NO_SCREENSHOT_CONFIG but no longer exist:",
extra_webhook_no_configs,
extra_integration_no_configs,
"Remove them from zerver.lib.integrations.NO_SCREENSHOT_CONFIG",
),
)
@@ -77,20 +79,21 @@ class IntegrationsTestCase(ZulipTestCase):
tip = '\nConsider updating zerver.lib.integrations.DOC_SCREENSHOT_CONFIG\n and running "tools/screenshots/generate-integration-docs-screenshot" to keep the screenshots up-to-date.'
error_message = ""
for integration_name, screenshot_configs in WEBHOOK_SCREENSHOT_CONFIG.items():
for integration_name, screenshot_configs in DOC_SCREENSHOT_CONFIG.items():
for screenshot_config in screenshot_configs:
integration = INTEGRATIONS[integration_name]
assert isinstance(integration, WebhookIntegration)
if screenshot_config.fixture_name == "":
# Skip screenshot configs of webhooks with a placeholder fixture_name
continue
fixture_path = get_fixture_path(integration, screenshot_config)
error_message = (
error_message
+ message.format(path=fixture_path, integration_name=integration_name)
if not os.path.isfile(fixture_path)
else error_message
)
if isinstance(integration, WebhookIntegration):
assert isinstance(screenshot_config, WebhookScreenshotConfig)
if screenshot_config.fixture_name == "":
# Skip screenshot configs of webhooks with a placeholder fixture_name
continue
fixture_path = get_fixture_path(integration, screenshot_config)
error_message = (
error_message
+ message.format(path=fixture_path, integration_name=integration_name)
if not os.path.isfile(fixture_path)
else error_message
)
image_path = get_image_path(integration, screenshot_config)
error_message = (
error_message