Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Change eventType for sample webhook payload
Maciej Korycinski9fc9c9cef6bb
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex fc88435e7f..9ccdededea 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3671,7 +3671,7 @@ type Query {webhook(id: ID!): Webhookwebhooks(sortBy: WebhookSortingInput, filter: WebhookFilterInput, before: String, after: String, first: Int, last: Int): WebhookCountableConnectionwebhookEvents: [WebhookEvent]- webhookSamplePayload(eventType: WebhookEventTypeEnum!): JSONString+ webhookSamplePayload(eventType: WebhookSampleEventTypeEnum!): JSONStringwarehouse(id: ID!): Warehousewarehouses(filter: WarehouseFilterInput, sortBy: WarehouseSortingInput, before: String, after: String, first: Int, last: Int): WarehouseCountableConnectiontranslations(kind: TranslatableKinds!, before: String, after: String, first: Int, last: Int): TranslatableItemConnection@@ -4988,6 +4988,17 @@ input WebhookFilterInput {isActive: Boolean}+enum WebhookSampleEventTypeEnum {+ ORDER_CREATED+ ORDER_FULLY_PAID+ ORDER_UPDATED+ ORDER_CANCELLED+ ORDER_FULFILLED+ CUSTOMER_CREATED+ PRODUCT_CREATED+ CHECKOUT_QUANTITY_CHANGED+}+enum WebhookSortField {NAMESERVICE_ACCOUNTdiff --git a/saleor/graphql/webhook/enums.py b/saleor/graphql/webhook/enums.pyindex e0c2b99d27..3dab9b609f 100644--- a/saleor/graphql/webhook/enums.py+++ b/saleor/graphql/webhook/enums.py@@ -7,3 +7,11 @@ WebhookEventTypeEnum = graphene.Enum("WebhookEventTypeEnum",[(str_to_enum(e_type[0]), e_type[0]) for e_type in WebhookEventType.CHOICES],)+WebhookSampleEventTypeEnum = graphene.Enum(+ "WebhookSampleEventTypeEnum",+ [+ (str_to_enum(e_type[0]), e_type[0])+ for e_type in WebhookEventType.CHOICES+ if e_type[0] != WebhookEventType.ANY+ ],+)diff --git a/saleor/graphql/webhook/resolvers.py b/saleor/graphql/webhook/resolvers.pyindex 1f6b27f8b0..1a32b88261 100644--- a/saleor/graphql/webhook/resolvers.py+++ b/saleor/graphql/webhook/resolvers.py@@ -42,8 +42,9 @@ def resolve_webhook_events():def resolve_sample_payload(info, event_name):service_account = info.context.service_accountrequired_permission = WebhookEventType.PERMISSIONS.get(event_name)- if service_account and service_account.has_perm(required_permission):- return payloads.generate_sample_payload(event_name)- if info.context.user.has_perm(required_permission):- return payloads.generate_sample_payload(event_name)+ if required_permission:+ if service_account and service_account.has_perm(required_permission):+ return payloads.generate_sample_payload(event_name)+ if info.context.user.has_perm(required_permission):+ return payloads.generate_sample_payload(event_name)raise PermissionDenied()diff --git a/saleor/graphql/webhook/schema.py b/saleor/graphql/webhook/schema.pyindex 16978471c1..8df25e8030 100644--- a/saleor/graphql/webhook/schema.py+++ b/saleor/graphql/webhook/schema.py@@ -3,7 +3,7 @@ import graphenefrom ...core.permissions import WebhookPermissionsfrom ..core.fields import FilterInputConnectionFieldfrom ..decorators import permission_required-from .enums import WebhookEventTypeEnum+from .enums import WebhookSampleEventTypeEnumfrom .filters import WebhookFilterInputfrom .mutations import WebhookCreate, WebhookDelete, WebhookUpdatefrom .resolvers import (@@ -37,7 +37,7 @@ class WebhookQueries(graphene.ObjectType):webhook_sample_payload = graphene.Field(graphene.JSONString,event_type=graphene.Argument(- WebhookEventTypeEnum,+ WebhookSampleEventTypeEnum,required=True,description="Name of the requested event type.",),diff --git a/tests/api/test_webhook.py b/tests/api/test_webhook.pyindex f9b0038da1..a23d192e9d 100644--- a/tests/api/test_webhook.py+++ b/tests/api/test_webhook.py@@ -4,7 +4,10 @@ import grapheneimport pytestfrom saleor.account.models import ServiceAccount-from saleor.graphql.webhook.enums import WebhookEventTypeEnum+from saleor.graphql.webhook.enums import (+ WebhookEventTypeEnum,+ WebhookSampleEventTypeEnum,+)from saleor.webhook.event_types import WebhookEventTypefrom saleor.webhook.models import Webhook@@ -609,7 +612,7 @@ def test_query_webhook_events_without_permissions(staff_api_client):SAMPLE_PAYLOAD_QUERY = """- query webhookSamplePayload($event_type: WebhookEventTypeEnum!){+ query webhookSamplePayload($event_type: WebhookSampleEventTypeEnum!){webhookSamplePayload(eventType: $event_type)}"""@@ -619,15 +622,15 @@ SAMPLE_PAYLOAD_QUERY = """@pytest.mark.parametrize("event_type, has_access",[- (WebhookEventTypeEnum.ORDER_CREATED, True),- (WebhookEventTypeEnum.ORDER_CREATED, True),- (WebhookEventTypeEnum.ORDER_FULLY_PAID, True),- (WebhookEventTypeEnum.ORDER_UPDATED, True),- (WebhookEventTypeEnum.ORDER_CANCELLED, True),- (WebhookEventTypeEnum.ORDER_FULFILLED, True),- (WebhookEventTypeEnum.CUSTOMER_CREATED, False),- (WebhookEventTypeEnum.PRODUCT_CREATED, False),- (WebhookEventTypeEnum.CHECKOUT_QUANTITY_CHANGED, False),+ (WebhookSampleEventTypeEnum.ORDER_CREATED, True),+ (WebhookSampleEventTypeEnum.ORDER_CREATED, True),+ (WebhookSampleEventTypeEnum.ORDER_FULLY_PAID, True),+ (WebhookSampleEventTypeEnum.ORDER_UPDATED, True),+ (WebhookSampleEventTypeEnum.ORDER_CANCELLED, True),+ (WebhookSampleEventTypeEnum.ORDER_FULFILLED, True),+ (WebhookSampleEventTypeEnum.CUSTOMER_CREATED, False),+ (WebhookSampleEventTypeEnum.PRODUCT_CREATED, False),+ (WebhookSampleEventTypeEnum.CHECKOUT_QUANTITY_CHANGED, False),],)def test_sample_payload_query_by_service_account(@@ -656,15 +659,15 @@ def test_sample_payload_query_by_service_account(@pytest.mark.parametrize("event_type, has_access",[- (WebhookEventTypeEnum.ORDER_CREATED, False),- (WebhookEventTypeEnum.ORDER_CREATED, False),- (WebhookEventTypeEnum.ORDER_FULLY_PAID, False),- (WebhookEventTypeEnum.ORDER_UPDATED, False),- (WebhookEventTypeEnum.ORDER_CANCELLED, False),- (WebhookEventTypeEnum.ORDER_FULFILLED, False),- (WebhookEventTypeEnum.CUSTOMER_CREATED, True),- (WebhookEventTypeEnum.PRODUCT_CREATED, True),- (WebhookEventTypeEnum.CHECKOUT_QUANTITY_CHANGED, True),+ (WebhookSampleEventTypeEnum.ORDER_CREATED, False),+ (WebhookSampleEventTypeEnum.ORDER_CREATED, False),+ (WebhookSampleEventTypeEnum.ORDER_FULLY_PAID, False),+ (WebhookSampleEventTypeEnum.ORDER_UPDATED, False),+ (WebhookSampleEventTypeEnum.ORDER_CANCELLED, False),+ (WebhookSampleEventTypeEnum.ORDER_FULFILLED, False),+ (WebhookSampleEventTypeEnum.CUSTOMER_CREATED, True),+ (WebhookSampleEventTypeEnum.PRODUCT_CREATED, True),+ (WebhookSampleEventTypeEnum.CHECKOUT_QUANTITY_CHANGED, True),],)def test_sample_payload_query_by_staff(