Zulip server and web application. Open-source team chat that helps teams stay productive and focused.
webhooks: Rename get_fixture_http_headers to call_fixture_to_headers.
Niloth P0ebca8d6c789
diff --git a/tools/screenshots/generate-integration-docs-screenshot b/tools/screenshots/generate-integration-docs-screenshotindex 7f00610d51c..c4cca165594 100755--- a/tools/screenshots/generate-integration-docs-screenshot+++ b/tools/screenshots/generate-integration-docs-screenshot@@ -54,7 +54,7 @@ from zerver.lib.integrations import (from zerver.lib.storage import static_pathfrom zerver.lib.streams import create_stream_if_neededfrom zerver.lib.upload import upload_avatar_image-from zerver.lib.webhooks.common import get_fixture_http_headers, parse_multipart_string+from zerver.lib.webhooks.common import call_fixture_to_headers, parse_multipart_stringfrom zerver.models import Message, UserProfilefrom zerver.models.realms import get_realmfrom zerver.models.users import get_user_by_delivery_email@@ -129,7 +129,7 @@ def get_fixture_info(fixture_path: str) -> tuple[Any, bool, bool, str]:def get_requests_headers(integration_dir_name: str, fixture_name: str) -> dict[str, Any]:- headers = get_fixture_http_headers(integration_dir_name, fixture_name)+ headers = call_fixture_to_headers(integration_dir_name, fixture_name)def fix_name(header: str) -> str:return header.removeprefix("HTTP_").replace("_", "-")diff --git a/zerver/lib/test_classes.py b/zerver/lib/test_classes.pyindex f44c2df3dba..68369c5e1cc 100644--- a/zerver/lib/test_classes.py+++ b/zerver/lib/test_classes.py@@ -89,8 +89,8 @@ from zerver.lib.topic import RESOLVED_TOPIC_PREFIX, filter_by_topic_name_via_mesfrom zerver.lib.upload import upload_message_attachment_from_requestfrom zerver.lib.user_groups import get_system_user_group_for_userfrom zerver.lib.webhooks.common import (+ call_fixture_to_headers,check_send_webhook_message,- get_fixture_http_headers,standardize_headers,)from zerver.models import (@@ -2589,7 +2589,7 @@ You can fix this by adding "{complete_event_type}" to ALL_EVENT_TYPES for this wif content_type is not None:extra["content_type"] = content_typeif self.WEBHOOK_DIR_NAME is not None:- headers = get_fixture_http_headers(self.WEBHOOK_DIR_NAME, fixture_name)+ headers = call_fixture_to_headers(self.WEBHOOK_DIR_NAME, fixture_name)headers = standardize_headers(headers)extra.update(headers)try:@@ -2655,7 +2655,7 @@ one or more new messages.extra["content_type"] = content_typeif self.WEBHOOK_DIR_NAME is not None:- headers = get_fixture_http_headers(self.WEBHOOK_DIR_NAME, fixture_name)+ headers = call_fixture_to_headers(self.WEBHOOK_DIR_NAME, fixture_name)headers = standardize_headers(headers)extra.update(headers)diff --git a/zerver/lib/webhooks/common.py b/zerver/lib/webhooks/common.pyindex f43f7940f69..730dc025e00 100644--- a/zerver/lib/webhooks/common.py+++ b/zerver/lib/webhooks/common.py@@ -258,7 +258,7 @@ def validate_extract_webhook_http_header(return extracted_header-def get_fixture_http_headers(integration_dir_name: str, fixture_name: str) -> dict["str", "str"]:+def call_fixture_to_headers(integration_dir_name: str, fixture_name: str) -> dict["str", "str"]:"""For integrations that require custom HTTP headers for some (or all)of their test fixtures, this method will call a specially namedfunction from the target integration module to determine what setdiff --git a/zerver/tests/test_webhooks_common.py b/zerver/tests/test_webhooks_common.pyindex 48e28d1c49d..5c86ce870df 100644--- a/zerver/tests/test_webhooks_common.py+++ b/zerver/tests/test_webhooks_common.py@@ -20,8 +20,8 @@ from zerver.lib.webhooks.common import (INVALID_JSON_MESSAGE,MISSING_EVENT_HEADER_MESSAGE,MissingHTTPEventHeaderError,+ call_fixture_to_headers,check_send_webhook_message,- get_fixture_http_headers,standardize_headers,validate_extract_webhook_http_header,validate_webhook_signature,@@ -108,7 +108,7 @@ class WebhooksCommonTestCase(ZulipTestCase):self.assertEqual(msg.content, expected_msg.strip())@patch("zerver.lib.webhooks.common.importlib.import_module")- def test_get_fixture_http_headers_for_success(self, import_module_mock: MagicMock) -> None:+ def test_call_fixture_to_headers_for_success(self, import_module_mock: MagicMock) -> None:def fixture_to_headers(fixture_name: str) -> dict[str, str]:# A sample function which would normally perform some# extra operations before returning a dictionary@@ -119,15 +119,15 @@ class WebhooksCommonTestCase(ZulipTestCase):fake_module = SimpleNamespace(fixture_to_headers=fixture_to_headers)import_module_mock.return_value = fake_module- headers = get_fixture_http_headers("some_integration", "complex_fixture")+ headers = call_fixture_to_headers("some_integration", "complex_fixture")self.assertEqual(headers, {"key": "value"})- def test_get_fixture_http_headers_for_non_existent_integration(self) -> None:- headers = get_fixture_http_headers("some_random_nonexistent_integration", "fixture_name")+ def test_call_fixture_to_headers_for_non_existent_integration(self) -> None:+ headers = call_fixture_to_headers("some_random_nonexistent_integration", "fixture_name")self.assertEqual(headers, {})@patch("zerver.lib.webhooks.common.importlib.import_module")- def test_get_fixture_http_headers_with_no_fixtures_to_headers_function(+ def test_call_fixture_to_headers_with_no_fixtures_to_headers_function(self,import_module_mock: MagicMock,) -> None:@@ -135,7 +135,7 @@ class WebhooksCommonTestCase(ZulipTestCase):import_module_mock.return_value = fake_moduleself.assertEqual(- get_fixture_http_headers("some_integration", "simple_fixture"),+ call_fixture_to_headers("some_integration", "simple_fixture"),{},)diff --git a/zerver/views/development/integrations.py b/zerver/views/development/integrations.pyindex 7ecdd72b57d..a3ec1ce7122 100644--- a/zerver/views/development/integrations.py+++ b/zerver/views/development/integrations.py@@ -13,7 +13,7 @@ from zerver.lib.exceptions import JsonableError, ResourceNotFoundErrorfrom zerver.lib.integrations import INCOMING_WEBHOOK_INTEGRATIONSfrom zerver.lib.response import json_successfrom zerver.lib.typed_endpoint import PathOnly, typed_endpoint-from zerver.lib.webhooks.common import get_fixture_http_headers, standardize_headers+from zerver.lib.webhooks.common import call_fixture_to_headers, standardize_headersfrom zerver.models import UserProfilefrom zerver.models.realms import get_realm@@ -90,7 +90,7 @@ def get_fixtures(request: HttpRequest, *, integration_name: PathOnly[str]) -> Htwith suppress(orjson.JSONDecodeError):body = orjson.loads(body)- headers_raw = get_fixture_http_headers(+ headers_raw = call_fixture_to_headers(valid_integration_name, "".join(fixture.split(".")[:-1]))@@ -145,7 +145,7 @@ def send_all_webhook_fixture_messages(content = f.read()x = fixture.split(".")fixture_name, fixture_format = "".join(_ for _ in x[:-1]), x[-1]- headers = get_fixture_http_headers(valid_integration_name, fixture_name)+ headers = call_fixture_to_headers(valid_integration_name, fixture_name)is_json = fixture_format == "json"response = send_webhook_fixture_message(url, content, is_json, headers)responses.append(