Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Use `webhookDryRun` mutation's context instead of creating dummy one (#12994)
Piotr Zabieglik8f76ddc6267f
diff --git a/saleor/graphql/webhook/mutations/webhook_dry_run.py b/saleor/graphql/webhook/mutations/webhook_dry_run.pyindex f1207c3989..af48c9a856 100644--- a/saleor/graphql/webhook/mutations/webhook_dry_run.py+++ b/saleor/graphql/webhook/mutations/webhook_dry_run.py@@ -10,10 +10,7 @@ from ...core.fields import JSONStringfrom ...core.mutations import BaseMutationfrom ...core.types import WebhookDryRunErrorfrom ...core.utils import raise_validation_error-from ..subscription_payload import (- generate_payload_from_subscription,- initialize_request,-)+from ..subscription_payload import generate_payload_from_subscriptionfrom ..subscription_query import SubscriptionQueryfrom ..subscription_types import WEBHOOK_TYPES_MAP@@ -114,7 +111,7 @@ class WebhookDryRun(BaseMutation):event_type, object, query = cls.validate_input(info, **data)payload = Noneif all([event_type, object, query]):- request = initialize_request()+ request = info.contextpayload = generate_payload_from_subscription(event_type, object, query, request)diff --git a/saleor/graphql/webhook/subscription_types.py b/saleor/graphql/webhook/subscription_types.pyindex 1d5f00f99d..c066ce68ef 100644--- a/saleor/graphql/webhook/subscription_types.py+++ b/saleor/graphql/webhook/subscription_types.py@@ -43,6 +43,7 @@ from ..core.descriptions import ()from ..core.doc_category import (DOC_CATEGORY_CHECKOUT,+ DOC_CATEGORY_GIFT_CARDS,DOC_CATEGORY_ORDERS,DOC_CATEGORY_PAYMENTS,DOC_CATEGORY_PRODUCTS,@@ -561,12 +562,13 @@ class GiftCardSent(SubscriptionObjectType, GiftCardBase):)class Meta:- root_type = "GiftCard"- enable_dry_run = True+ root_type = None+ enable_dry_run = Falseinterfaces = (Event,)description = ("Event sent when gift card is e-mailed." + ADDED_IN_313 + PREVIEW_FEATURE)+ doc_category = DOC_CATEGORY_GIFT_CARDS@staticmethoddef resolve_gift_card(root, info: ResolveInfo):diff --git a/saleor/graphql/webhook/tests/mutations/test_webhook_dry_run.py b/saleor/graphql/webhook/tests/mutations/test_webhook_dry_run.pyindex 94cd78ff30..a8596c9c05 100644--- a/saleor/graphql/webhook/tests/mutations/test_webhook_dry_run.py+++ b/saleor/graphql/webhook/tests/mutations/test_webhook_dry_run.py@@ -603,6 +603,7 @@ def test_webhook_dry_run_root_type(for event_name, event_type in WEBHOOK_TYPES_MAP.items():if not event_type._meta.enable_dry_run:continue+webhook = async_subscription_webhooks_with_root_objects[event_name][0]object = async_subscription_webhooks_with_root_objects[event_name][1]object_id = graphene.Node.to_global_id(object.__class__.__name__, object.pk)@@ -615,7 +616,9 @@ def test_webhook_dry_run_root_type(# thenassert not content["data"]["webhookDryRun"]["errors"]- assert content["data"]["webhookDryRun"]["payload"]+ payload = content["data"]["webhookDryRun"]["payload"]+ assert payload+ assert not json.loads(payload).get("errors")def test_webhook_dry_run_root_type_for_transaction_item_metadata_updated(