Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add missing context data to initialize_request function. (#9932)
SzymJd07455bc32f3
diff --git a/saleor/graphql/webhook/subscription_payload.py b/saleor/graphql/webhook/subscription_payload.pyindex ef4663c54c..2475284d89 100644--- a/saleor/graphql/webhook/subscription_payload.py+++ b/saleor/graphql/webhook/subscription_payload.py@@ -2,7 +2,9 @@ from typing import Any, Dict, Optionalfrom celery.utils.log import get_task_loggerfrom django.conf import settings+from django.contrib.sites.models import Sitefrom django.http import HttpRequest+from django.utils import timezonefrom django.utils.functional import SimpleLazyObjectfrom graphql import GraphQLDocument, get_default_backend, parsefrom graphql.error import GraphQLSyntaxError@@ -10,6 +12,8 @@ from graphql.language.ast import FragmentDefinition, OperationDefinitionfrom promise import Promisefrom ...app.models import App+from ...discount.utils import fetch_discounts+from ...plugins.manager import PluginsManagerfrom ...settings import get_hostlogger = get_task_logger(__name__)@@ -55,6 +59,11 @@ def initialize_request(requestor=None) -> HttpRequest:return: HttpRequest"""+ def _get_plugins(requestor_getter):+ return PluginsManager(settings.PLUGINS, requestor_getter)++ request_time = timezone.now()+request = HttpRequest()request.path = "/graphql/"request.path_info = "/graphql/"@@ -65,6 +74,13 @@ def initialize_request(requestor=None) -> HttpRequest:request.META["SERVER_PORT"] = "443"request.requestor = requestor # type: ignore+ request.request_time = request_time # type: ignore+ request.site = SimpleLazyObject(lambda: Site.objects.get_current()) # type: ignore+ request.discounts = SimpleLazyObject( # type: ignore+ lambda: fetch_discounts(request_time)+ )+ request.plugins = SimpleLazyObject(lambda: _get_plugins(requestor)) # type: ignore+return requestdiff --git a/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py b/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.pyindex b4eb1ab06d..4bfc7f3501 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py@@ -863,6 +863,9 @@ CHECKOUT_CREATED = """...on CheckoutCreated{checkout{id+ totalPrice{+ currency+ }}}}diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.pyindex d0b84a3d5c..aa019f9ab7 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/test_create_deliveries_for_subscription.py@@ -1117,7 +1117,9 @@ def test_checkout_create(checkout, subscription_checkout_created_webhook):event_type = WebhookEventAsyncType.CHECKOUT_CREATEDcheckout_id = graphene.Node.to_global_id("Checkout", checkout.pk)deliveries = create_deliveries_for_subscriptions(event_type, checkout, webhooks)- expected_payload = json.dumps({"checkout": {"id": checkout_id}})+ expected_payload = json.dumps(+ {"checkout": {"id": checkout_id, "totalPrice": {"currency": "USD"}}}+ )assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]