Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Improve subscription payload tests and structure (#9719)
Jakub107cfb229e75
diff --git a/saleor/graphql/tests/queries/__init__.py b/saleor/graphql/tests/queries/__init__.pynew file mode 100644index 0000000000..e69de29bb2diff --git a/saleor/graphql/tests/queries/fragments.py b/saleor/graphql/tests/queries/fragments.pynew file mode 100644index 0000000000..1a0b3786f0--- /dev/null+++ b/saleor/graphql/tests/queries/fragments.py@@ -0,0 +1,329 @@+PRICE = """+ fragment Price on TaxedMoney {+ currency+ gross {+ amount+ }+ net {+ amount+ }+ }+"""++PRODUCT_VARIANT = """+ fragment ProductVariant on ProductVariant {+ id+ name+ product {+ id+ name+ }+ }+"""+++SHIPPING_METHOD_DETAILS = """+ fragment ShippingMethodDetails on ShippingMethodType {+ id+ name+ channelListings {+ channel {+ name+ }+ }+ }+"""++COLLECTION_POINT = """+ fragment CollectionPoint on Warehouse {+ id+ name+ isPrivate+ clickAndCollectOption+ address {+ streetAddress1+ }+ }+"""++PRICING_DETAILS = """+fragment PricingDetails on Pricing {+ price {+ gross {+ amount+ currency+ }+ }+ discount{+ currency+ gross+ net+ }+}+"""+++CATEGORY_DETAILS = """+fragment CategoryDetails on Category {+ id+ name+ ancestors(first: 20) {+ edges {+ node {+ name+ }+ }+ }+ children(first: 20) {+ edges {+ node {+ name+ }+ }+ }+ products(first: 10 channel: "main") {+ edges {+ node {+ id+ name+ }+ }+ }+}+"""+++INVOICE_DETAILS = """+fragment InvoiceDetails on Invoice {+ id+ status+ number+}+"""+++SHIPPING_METHOD_TYPE = """+fragment ShippingMethodType on ShippingMethodType{+ id+ name+ type+ maximumOrderPrice{+ amount+ }+ minimumOrderPrice {+ amount+ }+ maximumOrderWeight {+ value+ unit+ }+ maximumOrderWeight {+ value+ unit+ }++}+"""+++SHIPPING_ZONE_DETAILS = (+ SHIPPING_METHOD_TYPE+ + """+fragment ShippingZoneDetails on ShippingZone {+ id+ countries {+ code+ country+ }+ shippingMethods {+ ...ShippingMethodType+ }+}+"""+)++WAREHOUSE_DETAILS = (+ SHIPPING_ZONE_DETAILS+ + """+fragment WarehouseDetails on Warehouse {+ id+ name+ companyName+ shippingZones {+ edges {+ node {+ ...ShippingZoneDetails+ }+ }+ }+}+"""+)+++FULFILLMENT_DETAILS = (+ PRODUCT_VARIANT+ + PRICE+ + """+fragment FulfillmentDetails on Fulfillment {+ id+ fulfillmentOrder+ trackingNumber+ status+ lines {+ id+ quantity+ orderLine {+ variant {+ ...ProductVariant+ }+ unitPrice {+ currency+ ...Price+ }+ }+ }+}+"""+)+++ADDRESS_DETAILS = """+fragment AddressDetails on Address {+ firstName+ lastName+ companyName+ streetAddress1+ streetAddress2+ city+ cityArea+ postalCode+ countryArea+ phone+ country {+ code+ }+}+ """+++USER_DETAILS = (+ ADDRESS_DETAILS+ + """+fragment UserDetails on User {+ firstName+ lastName+ isStaff+ isActive+ addresses {+ id+ }+ languageCode+ defaultShippingAddress {+ ...AddressDetails+ }+ defaultBillingAddress {+ ...AddressDetails+ }+}+"""+)+++BASIC_PRODUCT_FIELDS = """+fragment BasicProductFields on Product {+ id+ name+}+"""+++COLLECTION = (+ BASIC_PRODUCT_FIELDS+ + """+ fragment CollectionDetails on Collection {+ id+ name+ slug+ channel+ products(first: 10) {+ edges {+ node {+ ...BasicProductFields+ }+ }+ }+ }+ """+)+++PAGE_DETAILS = """+fragment PageDetails on Page{+ id+ title+ content+ slug+ isPublished+ publishedAt+ pageType {+ id+ }+ attributes {+ attribute {+ slug+ }+ values {+ slug+ name+ reference+ date+ dateTime+ file {+ url+ contentType+ }+ }+ }+}++"""++SALE_DETAILS = """+fragment SaleDetails on Sale {+ id+ name+ startDate+ endDate+ categories(first:10){+ edges {+ node {+ id+ name+ }+ }+ }+}+"""++GIFT_CARD_DETAILS = """+fragment GiftCardDetails on GiftCard{+ id+ isActive+ code+ createdBy {+ }+}+"""+++VOUCHER_DETAILS = """+fragment VoucherDetails on Voucher{+ id+ name+ code+ usageLimit+}+"""diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/fixtures.py b/saleor/plugins/webhook/tests/subscription_webhooks/fixtures.pyindex beda8c289a..0ef772993d 100644--- a/saleor/plugins/webhook/tests/subscription_webhooks/fixtures.py+++ b/saleor/plugins/webhook/tests/subscription_webhooks/fixtures.py@@ -2,6 +2,7 @@ import pytestfrom .....webhook.event_types import WebhookEventAsyncTypefrom .....webhook.models import Webhook+from . import subscription_queries@pytest.fixture@@ -138,232 +139,78 @@ CATEGORY_CREATED_SUBSCRIPTION_QUERY = """@pytest.fixturedef subscription_category_created_webhook(subscription_webhook):return subscription_webhook(- CATEGORY_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.CATEGORY_CREATED+ subscription_queries.CATEGORY_CREATED, WebhookEventAsyncType.CATEGORY_CREATED)-CATEGORY_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on CategoryUpdated{- category{- id- }- }- }- }-"""--@pytest.fixturedef subscription_category_updated_webhook(subscription_webhook):return subscription_webhook(- CATEGORY_UPDATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.CATEGORY_UPDATED+ subscription_queries.CATEGORY_UPDATED, WebhookEventAsyncType.CATEGORY_UPDATED)-CATEGORY_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on CategoryDeleted{- category{- id- }- }- }- }-"""--@pytest.fixturedef subscription_category_deleted_webhook(subscription_webhook):return subscription_webhook(- CATEGORY_DELETED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.CATEGORY_DELETED+ subscription_queries.CATEGORY_DELETED, WebhookEventAsyncType.CATEGORY_DELETED)-CHANNEL_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ChannelCreated{- channel{- id- }- }- }- }-"""--@pytest.fixturedef subscription_channel_created_webhook(subscription_webhook):return subscription_webhook(- CHANNEL_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.CHANNEL_CREATED+ subscription_queries.CHANNEL_CREATED, WebhookEventAsyncType.CHANNEL_CREATED)-CHANNEL_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ChannelUpdated{- channel{- id- }- }- }- }-"""--@pytest.fixturedef subscription_channel_updated_webhook(subscription_webhook):return subscription_webhook(- CHANNEL_UPDATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.CHANNEL_UPDATED+ subscription_queries.CHANNEL_UPDATED, WebhookEventAsyncType.CHANNEL_UPDATED)-CHANNEL_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ChannelDeleted{- channel{- id- }- }- }- }-"""--@pytest.fixturedef subscription_channel_deleted_webhook(subscription_webhook):return subscription_webhook(- CHANNEL_DELETED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.CHANNEL_DELETED+ subscription_queries.CHANNEL_DELETED, WebhookEventAsyncType.CHANNEL_DELETED)-CHANNEL_STATUS_CHANGED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ChannelStatusChanged{- channel{- id- isActive- }- }- }- }-"""--@pytest.fixturedef subscription_channel_status_changed_webhook(subscription_webhook):return subscription_webhook(- CHANNEL_STATUS_CHANGED_SUBSCRIPTION_QUERY,+ subscription_queries.CHANNEL_STATUS_CHANGED,WebhookEventAsyncType.CHANNEL_STATUS_CHANGED,)-GIFT_CARD_DETAILS_FRAGMENT = """- fragment GiftCardDetails on GiftCard{- id- isActive- code- createdBy {- }- }-"""--GIFT_CARD_CREATED_SUBSCRIPTION_QUERY = (- GIFT_CARD_DETAILS_FRAGMENT- + """- subscription{- event{- ...on GiftCardCreated{- giftCard{- ...GiftCardDetails- }- }- }- }-"""-)--@pytest.fixturedef subscription_gift_card_created_webhook(subscription_webhook):return subscription_webhook(- GIFT_CARD_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.GIFT_CARD_CREATED+ subscription_queries.GIFT_CARD_CREATED, WebhookEventAsyncType.GIFT_CARD_CREATED)-GIFT_CARD_UPDATED_SUBSCRIPTION_QUERY = (- GIFT_CARD_DETAILS_FRAGMENT- + """- subscription{- event{- ...on GiftCardUpdated{- giftCard{- ...GiftCardDetails- }- }- }- }-"""-)--@pytest.fixturedef subscription_gift_card_updated_webhook(subscription_webhook):return subscription_webhook(- GIFT_CARD_UPDATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.GIFT_CARD_UPDATED+ subscription_queries.GIFT_CARD_UPDATED, WebhookEventAsyncType.GIFT_CARD_UPDATED)-GIFT_CARD_DELETED_SUBSCRIPTION_QUERY = (- GIFT_CARD_DETAILS_FRAGMENT- + """- subscription{- event{- ...on GiftCardDeleted{- giftCard{- ...GiftCardDetails- }- }- }- }-"""-)--@pytest.fixturedef subscription_gift_card_deleted_webhook(subscription_webhook):return subscription_webhook(- GIFT_CARD_DELETED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.GIFT_CARD_DELETED+ subscription_queries.GIFT_CARD_DELETED, WebhookEventAsyncType.GIFT_CARD_DELETED)-GIFT_CARD_STATUS_CHANGED_SUBSCRIPTION_QUERY = (- GIFT_CARD_DETAILS_FRAGMENT- + """- subscription{- event{- ...on GiftCardStatusChanged{- giftCard{- ...GiftCardDetails- }- }- }- }-"""-)--@pytest.fixturedef subscription_gift_card_status_changed_webhook(subscription_webhook):return subscription_webhook(- GIFT_CARD_STATUS_CHANGED_SUBSCRIPTION_QUERY,+ subscription_queries.GIFT_CARD_STATUS_CHANGED,WebhookEventAsyncType.GIFT_CARD_STATUS_CHANGED,)@@ -557,1064 +404,351 @@ SHIPPING_PRICE_CREATED_SUBSCRIPTION_QUERY = """@pytest.fixturedef subscription_shipping_price_created_webhook(subscription_webhook):return subscription_webhook(- SHIPPING_PRICE_CREATED_SUBSCRIPTION_QUERY,+ subscription_queries.SHIPPING_PRICE_CREATED,WebhookEventAsyncType.SHIPPING_PRICE_CREATED,)-SHIPPING_PRICE_UPDATED_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ShippingPriceUpdated{- shippingMethod{- id- name- channelListings {- channel {- name- }- }- }- shippingZone{- id- name- }- }- }- }-"""--@pytest.fixturedef subscription_shipping_price_updated_webhook(subscription_webhook):return subscription_webhook(- SHIPPING_PRICE_UPDATED_UPDATED_SUBSCRIPTION_QUERY,+ subscription_queries.SHIPPING_PRICE_UPDATED_UPDATED,WebhookEventAsyncType.SHIPPING_PRICE_UPDATED,)-SHIPPING_PRICE_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ShippingPriceDeleted{- shippingMethod{- id- name- }- }- }- }-"""--@pytest.fixturedef subscription_shipping_price_deleted_webhook(subscription_webhook):return subscription_webhook(- SHIPPING_PRICE_DELETED_SUBSCRIPTION_QUERY,+ subscription_queries.SHIPPING_PRICE_DELETED,WebhookEventAsyncType.SHIPPING_PRICE_DELETED,)-SHIPPING_ZONE_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ShippingZoneCreated{- shippingZone{- id- name- countries {- code- }- channels {- name- }- }- }- }- }-"""--@pytest.fixturedef subscription_shipping_zone_created_webhook(subscription_webhook):return subscription_webhook(- SHIPPING_ZONE_CREATED_SUBSCRIPTION_QUERY,+ subscription_queries.SHIPPING_ZONE_CREATED,WebhookEventAsyncType.SHIPPING_ZONE_CREATED,)-SHIPPING_ZONE_UPDATED_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ShippingZoneUpdated{- shippingZone{- id- name- countries {- code- }- channels {- name- }- }- }- }- }-"""--@pytest.fixturedef subscription_shipping_zone_updated_webhook(subscription_webhook):return subscription_webhook(- SHIPPING_ZONE_UPDATED_UPDATED_SUBSCRIPTION_QUERY,+ subscription_queries.SHIPPING_ZONE_UPDATED_UPDATED,WebhookEventAsyncType.SHIPPING_ZONE_UPDATED,)-SHIPPING_ZONE_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ShippingZoneDeleted{- shippingZone{- id- name- }- }- }- }-"""--@pytest.fixturedef subscription_shipping_zone_deleted_webhook(subscription_webhook):return subscription_webhook(- SHIPPING_ZONE_DELETED_SUBSCRIPTION_QUERY,+ subscription_queries.SHIPPING_ZONE_DELETED,WebhookEventAsyncType.SHIPPING_ZONE_DELETED,)-PRODUCT_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ProductUpdated{- product{- id- }- }- }- }-"""--@pytest.fixturedef subscription_product_updated_webhook(subscription_webhook):return subscription_webhook(- PRODUCT_UPDATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.PRODUCT_UPDATED+ subscription_queries.PRODUCT_UPDATED, WebhookEventAsyncType.PRODUCT_UPDATED)-PRODUCT_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ProductCreated{- product{- id- }- }- }- }-"""--@pytest.fixturedef subscription_product_created_webhook(subscription_webhook):return subscription_webhook(- PRODUCT_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.PRODUCT_CREATED+ subscription_queries.PRODUCT_CREATED, WebhookEventAsyncType.PRODUCT_CREATED)-PRODUCT_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ProductDeleted{- product{- id- }- }- }- }-"""--@pytest.fixturedef subscription_product_deleted_webhook(subscription_webhook):return subscription_webhook(- PRODUCT_DELETED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.PRODUCT_DELETED+ subscription_queries.PRODUCT_DELETED, WebhookEventAsyncType.PRODUCT_DELETED)-PRODUCT_VARIANT_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ProductVariantCreated{- productVariant{- id- }- }- }- }-"""--@pytest.fixturedef subscription_product_variant_created_webhook(subscription_webhook):return subscription_webhook(- PRODUCT_VARIANT_CREATED_SUBSCRIPTION_QUERY,+ subscription_queries.PRODUCT_VARIANT_CREATED,WebhookEventAsyncType.PRODUCT_VARIANT_CREATED,)-PRODUCT_VARIANT_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ProductVariantUpdated{- productVariant{- id- }- }- }- }-"""--@pytest.fixturedef subscription_product_variant_updated_webhook(subscription_webhook):return subscription_webhook(- PRODUCT_VARIANT_UPDATED_SUBSCRIPTION_QUERY,+ subscription_queries.PRODUCT_VARIANT_UPDATED,WebhookEventAsyncType.PRODUCT_VARIANT_UPDATED,)-PRODUCT_VARIANT_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ProductVariantDeleted{- productVariant{- id- }- }- }- }-"""--@pytest.fixturedef subscription_product_variant_deleted_webhook(subscription_webhook):return subscription_webhook(- PRODUCT_VARIANT_DELETED_SUBSCRIPTION_QUERY,+ subscription_queries.PRODUCT_VARIANT_DELETED,WebhookEventAsyncType.PRODUCT_VARIANT_DELETED,)-PRODUCT_VARIANT_OUT_OF_STOCK_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ProductVariantOutOfStock{- productVariant{- id- }- }- }- }-"""--@pytest.fixturedef subscription_product_variant_out_of_stock_webhook(subscription_webhook):return subscription_webhook(- PRODUCT_VARIANT_OUT_OF_STOCK_SUBSCRIPTION_QUERY,+ subscription_queries.PRODUCT_VARIANT_OUT_OF_STOCK,WebhookEventAsyncType.PRODUCT_VARIANT_OUT_OF_STOCK,)-PRODUCT_VARIANT_BACK_IN_STOCK_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ProductVariantBackInStock{- productVariant{- id- }- }- }- }-"""--@pytest.fixturedef subscription_product_variant_back_in_stock_webhook(subscription_webhook):return subscription_webhook(- PRODUCT_VARIANT_BACK_IN_STOCK_SUBSCRIPTION_QUERY,+ subscription_queries.PRODUCT_VARIANT_BACK_IN_STOCK,WebhookEventAsyncType.PRODUCT_VARIANT_BACK_IN_STOCK,)-ORDER_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on OrderCreated{- order{- id- }- }- }- }-"""--@pytest.fixturedef subscription_order_created_webhook(subscription_webhook):return subscription_webhook(- ORDER_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.ORDER_CREATED+ subscription_queries.ORDER_CREATED, WebhookEventAsyncType.ORDER_CREATED)-ORDER_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on OrderUpdated{- order{- id- }- }- }- }-"""--@pytest.fixturedef subscription_order_updated_webhook(subscription_webhook):return subscription_webhook(- ORDER_UPDATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.ORDER_UPDATED+ subscription_queries.ORDER_UPDATED, WebhookEventAsyncType.ORDER_UPDATED)-ORDER_CONFIRMED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on OrderConfirmed{- order{- id- }- }- }- }-"""--@pytest.fixturedef subscription_order_confirmed_webhook(subscription_webhook):return subscription_webhook(- ORDER_CONFIRMED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.ORDER_CONFIRMED+ subscription_queries.ORDER_CONFIRMED, WebhookEventAsyncType.ORDER_CONFIRMED)-ORDER_FULLY_PAID_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on OrderFullyPaid{- order{- id- }- }- }- }-"""--@pytest.fixturedef subscription_order_fully_paid_webhook(subscription_webhook):return subscription_webhook(- ORDER_FULLY_PAID_SUBSCRIPTION_QUERY, WebhookEventAsyncType.ORDER_FULLY_PAID+ subscription_queries.ORDER_FULLY_PAID, WebhookEventAsyncType.ORDER_FULLY_PAID)-ORDER_CANCELLED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on OrderCancelled{- order{- id- }- }- }- }-"""--@pytest.fixturedef subscription_order_cancelled_webhook(subscription_webhook):return subscription_webhook(- ORDER_CANCELLED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.ORDER_CANCELLED+ subscription_queries.ORDER_CANCELLED, WebhookEventAsyncType.ORDER_CANCELLED)-ORDER_FULFILLED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on OrderFulfilled{- order{- id- }- }- }- }-"""--@pytest.fixturedef subscription_order_fulfilled_webhook(subscription_webhook):return subscription_webhook(- ORDER_FULFILLED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.ORDER_FULFILLED+ subscription_queries.ORDER_FULFILLED, WebhookEventAsyncType.ORDER_FULFILLED)-DRAFT_ORDER_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on DraftOrderCreated{- order{- id- }- }- }- }-"""--@pytest.fixturedef subscription_draft_order_created_webhook(subscription_webhook):return subscription_webhook(- DRAFT_ORDER_CREATED_SUBSCRIPTION_QUERY,+ subscription_queries.DRAFT_ORDER_CREATED,WebhookEventAsyncType.DRAFT_ORDER_CREATED,)-DRAFT_ORDER_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on DraftOrderUpdated{- order{- id- }- }- }- }-"""--@pytest.fixturedef subscription_draft_order_updated_webhook(subscription_webhook):return subscription_webhook(- DRAFT_ORDER_UPDATED_SUBSCRIPTION_QUERY,+ subscription_queries.DRAFT_ORDER_UPDATED,WebhookEventAsyncType.DRAFT_ORDER_UPDATED,)-DRAFT_ORDER_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on DraftOrderDeleted{- order{- id- }- }- }- }-"""--@pytest.fixturedef subscription_draft_order_deleted_webhook(subscription_webhook):return subscription_webhook(- DRAFT_ORDER_DELETED_SUBSCRIPTION_QUERY,+ subscription_queries.DRAFT_ORDER_DELETED,WebhookEventAsyncType.DRAFT_ORDER_DELETED,)-SALE_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on SaleCreated{- sale{- id- }- }- }- }-"""--@pytest.fixturedef subscription_sale_created_webhook(subscription_webhook):return subscription_webhook(- SALE_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.SALE_CREATED+ subscription_queries.SALE_CREATED, WebhookEventAsyncType.SALE_CREATED)-SALE_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on SaleUpdated{- sale{- id- }- }- }- }-"""--@pytest.fixturedef subscription_sale_updated_webhook(subscription_webhook):return subscription_webhook(- SALE_UPDATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.SALE_UPDATED+ subscription_queries.SALE_UPDATED, WebhookEventAsyncType.SALE_UPDATED)-SALE_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on SaleDeleted{- sale{- id- }- }- }- }-"""--@pytest.fixturedef subscription_sale_deleted_webhook(subscription_webhook):return subscription_webhook(- SALE_DELETED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.SALE_DELETED+ subscription_queries.SALE_DELETED, WebhookEventAsyncType.SALE_DELETED)-INVOICE_REQUESTED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on InvoiceRequested{- invoice{- id- }- }- }- }-"""--@pytest.fixturedef subscription_invoice_requested_webhook(subscription_webhook):return subscription_webhook(- INVOICE_REQUESTED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.INVOICE_REQUESTED+ subscription_queries.INVOICE_REQUESTED, WebhookEventAsyncType.INVOICE_REQUESTED)-INVOICE_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on InvoiceDeleted{- invoice{- id- }- }- }- }-"""--@pytest.fixturedef subscription_invoice_deleted_webhook(subscription_webhook):return subscription_webhook(- INVOICE_DELETED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.INVOICE_DELETED+ subscription_queries.INVOICE_DELETED, WebhookEventAsyncType.INVOICE_DELETED)-INVOICE_SENT_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on InvoiceSent{- invoice{- id- }- }- }- }-"""--@pytest.fixturedef subscription_invoice_sent_webhook(subscription_webhook):return subscription_webhook(- INVOICE_SENT_SUBSCRIPTION_QUERY, WebhookEventAsyncType.INVOICE_SENT+ subscription_queries.INVOICE_SENT, WebhookEventAsyncType.INVOICE_SENT)-FULFILLMENT_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on FulfillmentCreated{- fulfillment{- id- }- }- }- }-"""--@pytest.fixturedef subscription_fulfillment_created_webhook(subscription_webhook):return subscription_webhook(- FULFILLMENT_CREATED_SUBSCRIPTION_QUERY,+ subscription_queries.FULFILLMENT_CREATED,WebhookEventAsyncType.FULFILLMENT_CREATED,)-FULFILLMENT_CANCELED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on FulfillmentCanceled{- fulfillment{- id- }- }- }- }-"""--@pytest.fixturedef subscription_fulfillment_canceled_webhook(subscription_webhook):return subscription_webhook(- FULFILLMENT_CANCELED_SUBSCRIPTION_QUERY,+ subscription_queries.FULFILLMENT_CANCELED,WebhookEventAsyncType.FULFILLMENT_CANCELED,)-CUSTOMER_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on CustomerCreated{- user{- id- }- }- }- }-"""--@pytest.fixturedef subscription_customer_created_webhook(subscription_webhook):return subscription_webhook(- CUSTOMER_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.CUSTOMER_CREATED+ subscription_queries.CUSTOMER_CREATED, WebhookEventAsyncType.CUSTOMER_CREATED)-CUSTOMER_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on CustomerUpdated{- user{- id- }- }- }- }-"""--@pytest.fixturedef subscription_customer_updated_webhook(subscription_webhook):return subscription_webhook(- CUSTOMER_UPDATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.CUSTOMER_UPDATED+ subscription_queries.CUSTOMER_UPDATED, WebhookEventAsyncType.CUSTOMER_UPDATED)-COLLECTION_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on CollectionCreated{- collection{- id- }- }- }- }-"""--@pytest.fixturedef subscription_collection_created_webhook(subscription_webhook):return subscription_webhook(- COLLECTION_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.COLLECTION_CREATED+ subscription_queries.COLLECTION_CREATED,+ WebhookEventAsyncType.COLLECTION_CREATED,)-COLLECTION_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on CollectionUpdated{- collection{- id- }- }- }- }-"""--@pytest.fixturedef subscription_collection_updated_webhook(subscription_webhook):return subscription_webhook(- COLLECTION_UPDATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.COLLECTION_UPDATED+ subscription_queries.COLLECTION_UPDATED,+ WebhookEventAsyncType.COLLECTION_UPDATED,)-COLLECTION_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on CollectionDeleted{- collection{- id- }- }- }- }-"""--@pytest.fixturedef subscription_collection_deleted_webhook(subscription_webhook):return subscription_webhook(- COLLECTION_DELETED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.COLLECTION_DELETED+ subscription_queries.COLLECTION_DELETED,+ WebhookEventAsyncType.COLLECTION_DELETED,)-CHECKOUT_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on CheckoutCreated{- checkout{- id- }- }- }- }-"""--@pytest.fixturedef subscription_checkout_created_webhook(subscription_webhook):return subscription_webhook(- CHECKOUT_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.CHECKOUT_CREATED+ subscription_queries.CHECKOUT_CREATED, WebhookEventAsyncType.CHECKOUT_CREATED)-CHECKOUT_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on CheckoutUpdated{- checkout{- id- }- }- }- }-"""--@pytest.fixturedef subscription_checkout_updated_webhook(subscription_webhook):return subscription_webhook(- CHECKOUT_UPDATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.CHECKOUT_UPDATED+ subscription_queries.CHECKOUT_UPDATED, WebhookEventAsyncType.CHECKOUT_UPDATED)-PAGE_CREATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on PageCreated{- page{- id- }- }- }- }-"""--@pytest.fixturedef subscription_page_created_webhook(subscription_webhook):return subscription_webhook(- PAGE_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.PAGE_CREATED+ subscription_queries.PAGE_CREATED, WebhookEventAsyncType.PAGE_CREATED)-PAGE_UPDATED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on PageUpdated{- page{- id- }- }- }- }-"""--@pytest.fixturedef subscription_page_updated_webhook(subscription_webhook):return subscription_webhook(- PAGE_UPDATED_SUBSCRIPTION_QUERY,+ subscription_queries.PAGE_UPDATED,WebhookEventAsyncType.PAGE_UPDATED,)-PAGE_DELETED_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on PageDeleted{- page{- id- }- }- }- }-"""--@pytest.fixturedef subscription_page_deleted_webhook(subscription_webhook):return subscription_webhook(- PAGE_DELETED_SUBSCRIPTION_QUERY,+ subscription_queries.PAGE_DELETED,WebhookEventAsyncType.PAGE_DELETED,)-MULTIPLE_EVENTS_SUBSCRIPTION_QUERY = """-subscription{- event{- ...on ProductCreated{- product{- id- }- }- ...on ProductUpdated{- product{- id- }- }- ...on OrderCreated{- order{- id- }- }- }-}-"""--@pytest.fixturedef subscription_product_created_multiple_events_webhook(subscription_webhook):return subscription_webhook(- MULTIPLE_EVENTS_SUBSCRIPTION_QUERY,+ subscription_queries.MULTIPLE_EVENTS,WebhookEventAsyncType.TRANSLATION_CREATED,)-TRANSLATION_CREATED_SUBSCRIPTION_QUERY = """-subscription {- event {- ... on TranslationCreated {- translation {- ... on ProductTranslation {- id- }- ... on CollectionTranslation {- id- }- ... on CategoryTranslation {- id- }- ... on AttributeTranslation {- id- }- ... on ProductVariantTranslation {- id- }- ... on PageTranslation {- id- }- ... on ShippingMethodTranslation {- id- }- ... on SaleTranslation {- id- }- ... on VoucherTranslation {- id- }- ... on MenuItemTranslation {- id- }- ... on AttributeValueTranslation {- id- }- }- }- }-}-"""--@pytest.fixturedef subscription_translation_created_webhook(subscription_webhook):return subscription_webhook(- TRANSLATION_CREATED_SUBSCRIPTION_QUERY,+ subscription_queries.TRANSLATION_CREATED,WebhookEventAsyncType.TRANSLATION_CREATED,)-TRANSLATION_UPDATED_SUBSCRIPTION_QUERY = """-subscription {- event {- ... on TranslationUpdated {- translation {- ... on ProductTranslation {- id- }- ... on CollectionTranslation {- id- }- ... on CategoryTranslation {- id- }- ... on AttributeTranslation {- id- }- ... on ProductVariantTranslation {- id- }- ... on PageTranslation {- id- }- ... on ShippingMethodTranslation {- id- }- ... on SaleTranslation {- id- }- ... on VoucherTranslation {- id- }- ... on MenuItemTranslation {- id- }- ... on AttributeValueTranslation {- id- }- }- }- }-}-"""--@pytest.fixturedef subscription_translation_updated_webhook(subscription_webhook):return subscription_webhook(- TRANSLATION_UPDATED_SUBSCRIPTION_QUERY,+ subscription_queries.TRANSLATION_UPDATED,WebhookEventAsyncType.TRANSLATION_UPDATED,)-VOUCHER_DETAILS_FRAGMENT = """- fragment VoucherDetails on Voucher{- id- name- code- usageLimit- }-"""--VOUCHER_CREATED_SUBSCRIPTION_QUERY = (- VOUCHER_DETAILS_FRAGMENT- + """- subscription{- event{- ...on VoucherCreated{- voucher{- ...VoucherDetails- }- }- }- }-"""-)--@pytest.fixturedef subscription_voucher_created_webhook(subscription_webhook):return subscription_webhook(- VOUCHER_CREATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.VOUCHER_CREATED+ subscription_queries.VOUCHER_CREATED, WebhookEventAsyncType.VOUCHER_CREATED)-VOUCHER_UPDATED_SUBSCRIPTION_QUERY = (- VOUCHER_DETAILS_FRAGMENT- + """- subscription{- event{- ...on VoucherUpdated{- voucher{- ...VoucherDetails- }- }- }- }-"""-)--@pytest.fixturedef subscription_voucher_updated_webhook(subscription_webhook):return subscription_webhook(- VOUCHER_UPDATED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.VOUCHER_UPDATED+ subscription_queries.VOUCHER_UPDATED, WebhookEventAsyncType.VOUCHER_UPDATED)-VOUCHER_DELETED_SUBSCRIPTION_QUERY = (- VOUCHER_DETAILS_FRAGMENT- + """- subscription{- event{- ...on VoucherDeleted{- voucher{- ...VoucherDetails- }- }- }- }-"""-)--@pytest.fixturedef subscription_voucher_deleted_webhook(subscription_webhook):return subscription_webhook(- VOUCHER_DELETED_SUBSCRIPTION_QUERY, WebhookEventAsyncType.VOUCHER_DELETED+ subscription_queries.VOUCHER_DELETED, WebhookEventAsyncType.VOUCHER_DELETED)diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/payloads.py b/saleor/plugins/webhook/tests/subscription_webhooks/payloads.pynew file mode 100644index 0000000000..defc95a100--- /dev/null+++ b/saleor/plugins/webhook/tests/subscription_webhooks/payloads.py@@ -0,0 +1,311 @@+import json++import graphene++from saleor.product.models import Product+++def generate_taxed_money_payload(taxed_money):+ return {+ "currency": taxed_money.currency,+ "gross": {"amount": float(taxed_money.gross.amount)},+ "net": {"amount": float(taxed_money.net.amount)},+ }+++def generate_variant_payload(variant):+ return {+ "id": graphene.Node.to_global_id("ProductVariant", variant.pk),+ "name": variant.name,+ "product": {+ "id": graphene.Node.to_global_id("Product", variant.product.pk),+ "name": variant.product.name,+ },+ }+++def generate_fulfillment_lines_payload(fulfillment):+ lines = fulfillment.lines.all()+ lines = sorted(lines, key=lambda d: d.pk)+ return [+ {+ "id": graphene.Node.to_global_id("FulfillmentLine", line.pk),+ "quantity": line.quantity,+ "orderLine": {+ "variant": generate_variant_payload(line.order_line.variant),+ "unitPrice": generate_taxed_money_payload(line.order_line.unit_price),+ },+ }+ for line in lines+ ]+++def generate_fulfillment_payload(fulfillment):+ fulfillment_id = graphene.Node.to_global_id("Fulfillment", fulfillment.pk)+ return {+ "fulfillment": {+ "id": fulfillment_id,+ "fulfillmentOrder": fulfillment.fulfillment_order,+ "trackingNumber": fulfillment.tracking_number,+ "status": fulfillment.status.upper(),+ "lines": generate_fulfillment_lines_payload(fulfillment),+ },+ "meta": None,+ }+++def generate_address_payload(address):+ return {+ "firstName": address.first_name,+ "lastName": address.last_name,+ "companyName": address.company_name,+ "streetAddress1": address.street_address_1,+ "streetAddress2": address.street_address_2,+ "city": address.city,+ "cityArea": address.city_area,+ "postalCode": address.postal_code,+ "countryArea": address.country_area,+ "phone": str(address.phone),+ "country": {"code": address.country.code},+ }+++def generate_customer_payload(customer):+ addresses = sorted(customer.addresses.all(), key=lambda address: address.pk)+ return {+ "user": {+ "email": customer.email,+ "firstName": customer.first_name,+ "lastName": customer.last_name,+ "isStaff": customer.is_staff,+ "isActive": customer.is_active,+ "addresses": [+ {"id": graphene.Node.to_global_id("Address", address.pk)}+ for address in addresses+ ],+ "languageCode": customer.language_code.upper(),+ "defaultShippingAddress": (+ generate_address_payload(customer.default_shipping_address)+ ),+ "defaultBillingAddress": (+ generate_address_payload(customer.default_billing_address)+ ),+ },+ "meta": None,+ }+++def generate_collection_payload(collection):+ collection_id = graphene.Node.to_global_id("Collection", collection.pk)+ products = sorted(collection.products.all(), key=lambda product: product.name)+ products_node = [+ {+ "node": {+ "id": graphene.Node.to_global_id("Product", product.pk),+ "name": product.name,+ }+ }+ for product in products+ ]+ return {+ "collection": {+ "id": collection_id,+ "name": collection.name,+ "slug": collection.slug,+ "channel": "main",+ "products": {"edges": products_node},+ },+ "meta": None,+ }+++def generate_page_payload(page):+ page_id = graphene.Node.to_global_id("Page", page.pk)+ page_type_id = graphene.Node.to_global_id("PageType", page.page_type.pk)+ page_attributes = page.page_type.page_attributes.all()+ attribute_values_1 = page_attributes[0].values.first()+ return {+ "page": {+ "id": page_id,+ "title": page.title,+ "content": json.dumps(page.content),+ "slug": page.slug,+ "isPublished": page.is_published,+ "publishedAt": page.published_at,+ "pageType": {"id": page_type_id},+ "attributes": [+ {+ "attribute": {"slug": page_attributes[0].slug},+ "values": [+ {+ "slug": attribute_values_1.slug,+ "name": attribute_values_1.name,+ "reference": None,+ "date": None,+ "dateTime": None,+ "file": None,+ }+ ],+ },+ {"attribute": {"slug": page_attributes[1].slug}, "values": []},+ ],+ },+ "meta": None,+ }+++def generate_invoice_payload(invoice):+ return {+ "invoice": {+ "id": graphene.Node.to_global_id("Invoice", invoice.pk),+ "status": invoice.status.upper(),+ "number": invoice.number,+ },+ "meta": None,+ }+++def generate_category_payload(category):+ tree = category.get_descendants(include_self=True)+ products = sorted(+ Product.objects.all().filter(category__in=tree),+ key=lambda product: product.name,+ )+ return {+ "category": {+ "id": graphene.Node.to_global_id("Category", category.id),+ "name": category.name,+ "ancestors": {"edges": []},+ "children": {"edges": [{"node": {"name": category.children.first().name}}]},+ "products": {+ "edges": [+ {+ "node": {+ "id": graphene.Node.to_global_id("Product", product.id),+ "name": product.name,+ }+ }+ for product in products+ ]+ },+ },+ "meta": None,+ }+++def generate_shipping_method_payload(shipping_method):+ shipping_method_id = graphene.Node.to_global_id(+ "ShippingMethodType", shipping_method.id+ )+ shipping_zone_id = graphene.Node.to_global_id(+ "ShippingZone", shipping_method.shipping_zone.id+ )+ channel_listings = sorted(+ shipping_method.channel_listings.all(), key=lambda cl: cl.pk+ )+ return {+ "shippingMethod": {+ "id": shipping_method_id,+ "name": shipping_method.name,+ "channelListings": [+ {"channel": {"name": sl.channel.name}} for sl in channel_listings+ ],+ },+ "shippingZone": {+ "id": shipping_zone_id,+ "name": shipping_method.shipping_zone.name,+ },+ "meta": None,+ }+++def generate_sale_payload(sale):+ return {+ "sale": {+ "id": graphene.Node.to_global_id("Sale", sale.pk),+ "name": sale.name,+ "startDate": sale.start_date.isoformat(),+ "endDate": None,+ "categories": {+ "edges": [+ {+ "node": {+ "id": graphene.Node.to_global_id("Category", category.pk),+ "name": category.name,+ }+ }+ for category in sale.categories.all()+ ]+ },+ },+ "meta": None,+ }+++def generate_voucher_payload(voucher, voucher_global_id):+ return json.dumps(+ {+ "voucher": {+ "id": voucher_global_id,+ "name": voucher.name,+ "code": voucher.code,+ "usageLimit": voucher.usage_limit,+ },+ "meta": None,+ }+ )+++def generate_gift_card_payload(gift_card, card_global_id):+ return json.dumps(+ {+ "giftCard": {+ "id": card_global_id,+ "isActive": gift_card.is_active,+ "code": gift_card.code,+ "createdBy": {"email": gift_card.created_by.email},+ },+ "meta": None,+ }+ )+++def generate_menu_payload(menu, menu_global_id):+ menu_items = sorted(menu.items.all(), key=lambda key: key.pk)+ return {+ "menu": {+ "id": menu_global_id,+ "name": menu.name,+ "slug": menu.slug,+ "items": [+ {+ "id": graphene.Node.to_global_id(item.id, "MenuItem"),+ "name": item.name,+ }+ for item in menu_items+ ],+ },+ "meta": None,+ }+++def generate_menu_item_payload(menu_item, menu_item_global_id):+ menu = (+ {"id": graphene.Node.to_global_id("Menu", menu_item.menu_id)}+ if menu_item.menu_id+ else None+ )+ page = (+ {"id": graphene.Node.to_global_id("Page", menu_item.page_id)}+ if menu_item.page_id+ else None+ )+ return {+ "menuItem": {+ "id": menu_item_global_id,+ "name": menu_item.name,+ "menu": menu,+ "page": page,+ },+ "meta": None,+ }diff --git a/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py b/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.pynew file mode 100644index 0000000000..a4a3fdb007--- /dev/null+++ b/saleor/plugins/webhook/tests/subscription_webhooks/subscription_queries.py@@ -0,0 +1,990 @@+from .....graphql.tests.queries import fragments++GIFT_CARD_CREATED = (+ fragments.GIFT_CARD_DETAILS+ + """+ subscription{+ event{+ ...on GiftCardCreated{+ giftCard{+ ...GiftCardDetails+ }+ }+ }+ }+"""+)+++GIFT_CARD_UPDATED = (+ fragments.GIFT_CARD_DETAILS+ + """+ subscription{+ event{+ ...on GiftCardUpdated{+ giftCard{+ ...GiftCardDetails+ }+ }+ }+ }+"""+)++GIFT_CARD_DELETED = (+ fragments.GIFT_CARD_DETAILS+ + """+ subscription{+ event{+ ...on GiftCardDeleted{+ giftCard{+ ...GiftCardDetails+ }+ }+ }+ }+"""+)+++GIFT_CARD_STATUS_CHANGED = (+ fragments.GIFT_CARD_DETAILS+ + """+ subscription{+ event{+ ...on GiftCardStatusChanged{+ giftCard{+ ...GiftCardDetails+ }+ }+ }+ }+"""+)+++VOUCHER_CREATED = (+ fragments.VOUCHER_DETAILS+ + """+ subscription{+ event{+ ...on VoucherCreated{+ voucher{+ ...VoucherDetails+ }+ }+ }+ }+"""+)+++VOUCHER_UPDATED = (+ fragments.VOUCHER_DETAILS+ + """+ subscription{+ event{+ ...on VoucherUpdated{+ voucher{+ ...VoucherDetails+ }+ }+ }+ }+"""+)+++VOUCHER_DELETED = (+ fragments.VOUCHER_DETAILS+ + """+ subscription{+ event{+ ...on VoucherDeleted{+ voucher{+ ...VoucherDetails+ }+ }+ }+ }+"""+)+++CHANNEL_CREATED = """+ subscription{+ event{+ ...on ChannelCreated{+ channel{+ id+ }+ }+ }+ }+"""++CHANNEL_UPDATED = """+ subscription{+ event{+ ...on ChannelUpdated{+ channel{+ id+ }+ }+ }+ }+"""++CHANNEL_DELETED = """+ subscription{+ event{+ ...on ChannelDeleted{+ channel{+ id+ }+ }+ }+ }+"""++CHANNEL_STATUS_CHANGED = """+ subscription{+ event{+ ...on ChannelStatusChanged{+ channel{+ id+ isActive+ }+ }+ }+ }+"""+++CATEGORY_CREATED = (+ fragments.CATEGORY_DETAILS+ + """+ subscription{+ event{+ ...on CategoryCreated{+ category{+ ...CategoryDetails+ }+ }+ }+ }+ """+)++CATEGORY_UPDATED = (+ fragments.CATEGORY_DETAILS+ + """+ subscription{+ event{+ ...on CategoryUpdated{+ category{+ ...CategoryDetails+ }+ }+ }+ }+ """+)++CATEGORY_DELETED = """+ subscription{+ event{+ ...on CategoryDeleted{+ category{+ id+ }+ }+ }+ }+"""+++SHIPPING_PRICE_CREATED = (+ fragments.SHIPPING_METHOD_DETAILS+ + """+ subscription{+ event{+ ...on ShippingPriceCreated{+ shippingMethod{+ ...ShippingMethodDetails+ }+ shippingZone{+ id+ name+ }+ }+ }+ }+"""+)++SHIPPING_PRICE_UPDATED_UPDATED = (+ fragments.SHIPPING_METHOD_DETAILS+ + """+ subscription{+ event{+ ...on ShippingPriceUpdated{+ shippingMethod{+ ...ShippingMethodDetails+ }+ shippingZone{+ id+ name+ }+ }+ }+ }+"""+)++SHIPPING_PRICE_DELETED = """+ subscription{+ event{+ ...on ShippingPriceDeleted{+ shippingMethod{+ id+ name+ }+ }+ }+ }+"""++SHIPPING_ZONE_CREATED = """+ subscription{+ event{+ ...on ShippingZoneCreated{+ shippingZone{+ id+ name+ countries {+ code+ }+ channels {+ name+ }+ }+ }+ }+ }+"""++SHIPPING_ZONE_UPDATED_UPDATED = """+ subscription{+ event{+ ...on ShippingZoneUpdated{+ shippingZone{+ id+ name+ countries {+ code+ }+ channels {+ name+ }+ }+ }+ }+ }+"""++SHIPPING_ZONE_DELETED = """+ subscription{+ event{+ ...on ShippingZoneDeleted{+ shippingZone{+ id+ name+ }+ }+ }+ }+"""++PRODUCT_UPDATED = """+ subscription{+ event{+ ...on ProductUpdated{+ product{+ id+ }+ }+ }+ }+"""++PRODUCT_CREATED = """+ subscription{+ event{+ ...on ProductCreated{+ product{+ id+ }+ }+ }+ }+"""++PRODUCT_DELETED = """+ subscription{+ event{+ ...on ProductDeleted{+ product{+ id+ }+ }+ }+ }+"""++PRODUCT_VARIANT_CREATED = """+ subscription{+ event{+ ...on ProductVariantCreated{+ productVariant{+ id+ }+ }+ }+ }+"""++PRODUCT_VARIANT_UPDATED = """+ subscription{+ event{+ ...on ProductVariantUpdated{+ productVariant{+ id+ }+ }+ }+ }+"""+++PRODUCT_VARIANT_DELETED = """+ subscription{+ event{+ ...on ProductVariantDeleted{+ productVariant{+ id+ }+ }+ }+ }+"""++PRODUCT_VARIANT_OUT_OF_STOCK = """+ subscription{+ event{+ ...on ProductVariantOutOfStock{+ productVariant{+ id+ }+ }+ }+ }+"""++PRODUCT_VARIANT_BACK_IN_STOCK = """+ subscription{+ event{+ ...on ProductVariantBackInStock{+ productVariant{+ id+ }+ }+ }+ }+"""++ORDER_CREATED = """+ subscription{+ event{+ ...on OrderCreated{+ order{+ id+ }+ }+ }+ }+"""++ORDER_UPDATED = """+ subscription{+ event{+ ...on OrderUpdated{+ order{+ id+ }+ }+ }+ }+"""++ORDER_CONFIRMED = """+ subscription{+ event{+ ...on OrderConfirmed{+ order{+ id+ }+ }+ }+ }+"""++ORDER_FULLY_PAID = """+ subscription{+ event{+ ...on OrderFullyPaid{+ order{+ id+ }+ }+ }+ }+"""++ORDER_CANCELLED = """+ subscription{+ event{+ ...on OrderCancelled{+ order{+ id+ }+ }+ }+ }+"""++ORDER_FULFILLED = """+ subscription{+ event{+ ...on OrderFulfilled{+ order{+ id+ }+ }+ }+ }+"""++DRAFT_ORDER_CREATED = """+ subscription{+ event{+ ...on DraftOrderCreated{+ order{+ id+ }+ }+ }+ }+"""++DRAFT_ORDER_UPDATED = """+ subscription{+ event{+ ...on DraftOrderUpdated{+ order{+ id+ }+ }+ }+ }+"""++DRAFT_ORDER_DELETED = """+ subscription{+ event{+ ...on DraftOrderDeleted{+ order{+ id+ }+ }+ }+ }+"""++SALE_CREATED = (+ fragments.SALE_DETAILS+ + """+ subscription{+ event{+ ...on SaleCreated{+ sale{+ ...SaleDetails+ }+ }+ }+ }+"""+)++SALE_UPDATED = (+ fragments.SALE_DETAILS+ + """+ subscription{+ event{+ ...on SaleUpdated{+ sale{+ ...SaleDetails+ }+ }+ }+ }+"""+)++SALE_DELETED = (+ fragments.SALE_DETAILS+ + """+ subscription{+ event{+ ...on SaleDeleted{+ sale{+ ...SaleDetails+ }+ }+ }+ }+"""+)++INVOICE_REQUESTED = (+ fragments.INVOICE_DETAILS+ + """+ subscription{+ event{+ ...on InvoiceRequested{+ invoice{+ ...InvoiceDetails+ }+ }+ }+ }+"""+)++INVOICE_DELETED = (+ fragments.INVOICE_DETAILS+ + """+ subscription{+ event{+ ...on InvoiceDeleted{+ invoice{+ ...InvoiceDetails+ }+ }+ }+ }+"""+)++INVOICE_SENT = (+ fragments.INVOICE_DETAILS+ + """+ subscription{+ event{+ ...on InvoiceSent{+ invoice{+ ...InvoiceDetails+ }+ }+ }+ }+"""+)++FULFILLMENT_CREATED = (+ fragments.FULFILLMENT_DETAILS+ + """+ subscription{+ event{+ ...on FulfillmentCreated{+ fulfillment{+ ...FulfillmentDetails+ }+ }+ }+ }+"""+)++FULFILLMENT_CANCELED = (+ fragments.FULFILLMENT_DETAILS+ + """+ subscription{+ event{+ ...on FulfillmentCanceled{+ fulfillment{+ ...FulfillmentDetails+ }+ }+ }+ }+"""+)++CUSTOMER_CREATED = (+ fragments.USER_DETAILS+ + """+ subscription{+ event{+ ...on CustomerCreated{+ user{+ ...UserDetails+ }+ }+ }+ }+"""+)++CUSTOMER_UPDATED = (+ fragments.USER_DETAILS+ + """+ subscription{+ event{+ ...on CustomerUpdated{+ user{+ ...UserDetails+ }+ }+ }+ }+"""+)++COLLECTION_CREATED = (+ fragments.COLLECTION+ + """+ subscription{+ event{+ ...on CollectionCreated{+ collection(channel: "main"){+ ...CollectionDetails+ }+ }+ }+ }+ """+)++COLLECTION_UPDATED = (+ fragments.COLLECTION+ + """+ subscription{+ event{+ ...on CollectionUpdated{+ collection(channel: "main"){+ ...CollectionDetails+ }+ }+ }+ }+ """+)++COLLECTION_DELETED = (+ fragments.COLLECTION+ + """+ subscription{+ event{+ ...on CollectionDeleted{+ collection(channel: "main"){+ ...CollectionDetails+ }+ }+ }+ }+ """+)+++CHECKOUT_CREATED = """+ subscription{+ event{+ ...on CheckoutCreated{+ checkout{+ id+ }+ }+ }+ }+"""++CHECKOUT_UPDATED = """+ subscription{+ event{+ ...on CheckoutUpdated{+ checkout{+ id+ }+ }+ }+ }+"""++PAGE_CREATED = (+ fragments.PAGE_DETAILS+ + """+ subscription{+ event{+ ...on PageCreated{+ page{+ ...PageDetails+ }+ }+ }+ }+"""+)++PAGE_UPDATED = (+ fragments.PAGE_DETAILS+ + """+ subscription{+ event{+ ...on PageUpdated{+ page{+ ...PageDetails+ }+ }+ }+ }+"""+)++PAGE_DELETED = (+ fragments.PAGE_DETAILS+ + """+ subscription{+ event{+ ...on PageDeleted{+ page{+ ...PageDetails+ }+ }+ }+ }+"""+)++MULTIPLE_EVENTS = """+subscription{+ event{+ ...on ProductCreated{+ product{+ id+ }+ }+ ...on ProductUpdated{+ product{+ id+ }+ }+ ...on OrderCreated{+ order{+ id+ }+ }+ }+}+"""++TRANSLATION_CREATED = """+subscription {+ event {+ ... on TranslationCreated {+ translation {+ ... on ProductTranslation {+ id+ }+ ... on CollectionTranslation {+ id+ }+ ... on CategoryTranslation {+ id+ }+ ... on AttributeTranslation {+ id+ }+ ... on ProductVariantTranslation {+ id+ }+ ... on PageTranslation {+ id+ }+ ... on ShippingMethodTranslation {+ id+ }+ ... on SaleTranslation {+ id+ }+ ... on VoucherTranslation {+ id+ }+ ... on MenuItemTranslation {+ id+ }+ ... on AttributeValueTranslation {+ id+ }+ }+ }+ }+}+"""++TRANSLATION_UPDATED = """+subscription {+ event {+ ... on TranslationUpdated {+ translation {+ ... on ProductTranslation {+ id+ }+ ... on CollectionTranslation {+ id+ }+ ... on CategoryTranslation {+ id+ }+ ... on AttributeTranslation {+ id+ }+ ... on ProductVariantTranslation {+ id+ }+ ... on PageTranslation {+ id+ }+ ... on ShippingMethodTranslation {+ id+ }+ ... on SaleTranslation {+ id+ }+ ... on VoucherTranslation {+ id+ }+ ... on MenuItemTranslation {+ id+ }+ ... on AttributeValueTranslation {+ id+ }+ }+ }+ }+}+"""++TEST_VALID_SUBSCRIPTION = """+ subscription{+ event{+ ...on ProductUpdated{+ product{+ id+ }+ }+ }+ }+"""++TEST_INVALID_MULTIPLE_SUBSCRIPTION = """+subscription{+ event{+ ...on ProductUpdated{+ product{+ id+ }+ }+ }+}+subscription{+ event{+ ...on ProductCreated{+ product{+ id+ }+ }+ }+}+"""+++TEST_INVALID_SUBSCRIPTION_AND_QUERY = """+subscription{+ event{+ ...on ProductUpdated{+ product{+ id+ }+ }+ }+}+query{+ products(first:100){+ edges{+ node{+ id+ }+ }+ }+}+"""++TEST_INVALID_QUERY_AND_SUBSCRIPTION = """+query{+ products(first:100){+ edges{+ node{+ id+ }+ }+ }+}+subscription{+ event{+ ...on ProductUpdated{+ product{+ id+ }+ }+ }+}"""++TEST_VALID_SUBSCRIPTION_QUERY_WITH_FRAGMENT = """+fragment productFragment on Product{+ name+}+subscription{+ event{+ ...on ProductUpdated{+ product{+ id+ ...productFragment+ }+ }+ }+}+"""++TEST_VALID_SUBSCRIPTION_QUERY = """+ subscription{+ event{+ ...on ProductUpdated{+ product{+ id+ }+ }+ }+ }+"""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 7fb43b98a3..12f5b6fb8c 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@@ -12,6 +12,21 @@ from .....product.models import Categoryfrom .....shipping.models import ShippingMethod, ShippingZonefrom .....webhook.event_types import WebhookEventAsyncTypefrom ...tasks import create_deliveries_for_subscriptions, logger+from . import subscription_queries+from .payloads import (+ generate_category_payload,+ generate_collection_payload,+ generate_customer_payload,+ generate_fulfillment_payload,+ generate_gift_card_payload,+ generate_invoice_payload,+ generate_menu_item_payload,+ generate_menu_payload,+ generate_page_payload,+ generate_sale_payload,+ generate_shipping_method_payload,+ generate_voucher_payload,+)def generate_expected_payload_for_app(app, app_global_id):@@ -102,34 +117,45 @@ def test_app_status_changed(status, app, subscription_app_status_changed_webhookassert deliveries[0].webhook == webhooks[0]-def test_category_created(category, subscription_category_created_webhook):+def test_category_created(+ categories_tree_with_published_products,+ subscription_category_created_webhook,+):# given+ parent_category = categories_tree_with_published_productswebhooks = [subscription_category_created_webhook]event_type = WebhookEventAsyncType.CATEGORY_CREATED- category_id = graphene.Node.to_global_id("Category", category.id)+ expected_payload = generate_category_payload(parent_category)# when- deliveries = create_deliveries_for_subscriptions(event_type, category, webhooks)+ deliveries = create_deliveries_for_subscriptions(+ event_type, parent_category, webhooks+ )# then- expected_payload = json.dumps({"category": {"id": category_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]-def test_category_updated(category, subscription_category_updated_webhook):+def test_category_updated(+ categories_tree_with_published_products,+ subscription_category_updated_webhook,+ channel_USD,+):# given+ parent_category = categories_tree_with_published_productswebhooks = [subscription_category_updated_webhook]event_type = WebhookEventAsyncType.CATEGORY_UPDATED- category_id = graphene.Node.to_global_id("Category", category.id)+ expected_payload = generate_category_payload(parent_category)# when- deliveries = create_deliveries_for_subscriptions(event_type, category, webhooks)+ deliveries = create_deliveries_for_subscriptions(+ event_type, parent_category, webhooks+ )# then- expected_payload = json.dumps({"category": {"id": category_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -239,20 +265,6 @@ def test_channel_status_changed(assert deliveries[0].webhook == webhooks[0]-def generate_expected_payload_for_gift_card(gift_card, card_global_id):- return json.dumps(- {- "giftCard": {- "id": card_global_id,- "isActive": gift_card.is_active,- "code": gift_card.code,- "createdBy": {"email": gift_card.created_by.email},- },- "meta": None,- }- )--def test_gift_card_created(gift_card, subscription_gift_card_created_webhook):# givenwebhooks = [subscription_gift_card_created_webhook]@@ -263,7 +275,7 @@ def test_gift_card_created(gift_card, subscription_gift_card_created_webhook):deliveries = create_deliveries_for_subscriptions(event_type, gift_card, webhooks)# then- expected_payload = generate_expected_payload_for_gift_card(gift_card, gift_card_id)+ expected_payload = generate_gift_card_payload(gift_card, gift_card_id)assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -279,7 +291,7 @@ def test_gift_card_updated(gift_card, subscription_gift_card_updated_webhook):deliveries = create_deliveries_for_subscriptions(event_type, gift_card, webhooks)# then- expected_payload = generate_expected_payload_for_gift_card(gift_card, gift_card_id)+ expected_payload = generate_gift_card_payload(gift_card, gift_card_id)assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -302,7 +314,7 @@ def test_gift_card_deleted(gift_card, subscription_gift_card_deleted_webhook):)# then- expected_payload = generate_expected_payload_for_gift_card(gift_card, gift_card_id)+ expected_payload = generate_gift_card_payload(gift_card, gift_card_id)assert gift_card_instances[0].id is not Noneassert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)@@ -326,32 +338,12 @@ def test_gift_card_status_changed(deliveries = create_deliveries_for_subscriptions(event_type, gift_card, webhooks)# then- expected_payload = generate_expected_payload_for_gift_card(gift_card, gift_card_id)+ expected_payload = generate_gift_card_payload(gift_card, gift_card_id)assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]-def generate_expected_payload_for_menu(menu, menu_global_id):- return json.dumps(- {- "menu": {- "id": menu_global_id,- "name": menu.name,- "slug": menu.slug,- "items": [- {- "id": graphene.Node.to_global_id(item.id, "MenuItem"),- "name": item.name,- }- for item in menu.items.all()- ],- },- "meta": None,- }- )--def test_menu_created(menu, subscription_menu_created_webhook):# givenwebhooks = [subscription_menu_created_webhook]@@ -362,7 +354,7 @@ def test_menu_created(menu, subscription_menu_created_webhook):deliveries = create_deliveries_for_subscriptions(event_type, menu, webhooks)# then- expected_payload = generate_expected_payload_for_menu(menu, menu_id)+ expected_payload = json.dumps(generate_menu_payload(menu, menu_id))assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -378,7 +370,7 @@ def test_menu_updated(menu, subscription_menu_updated_webhook):deliveries = create_deliveries_for_subscriptions(event_type, menu, webhooks)# then- expected_payload = generate_expected_payload_for_menu(menu, menu_id)+ expected_payload = json.dumps(generate_menu_payload(menu, menu_id))assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -401,31 +393,13 @@ def test_menu_deleted(menu, subscription_menu_deleted_webhook):)# then- expected_payload = generate_expected_payload_for_menu(menu, menu_id)+ expected_payload = json.dumps(generate_menu_payload(menu, menu_id))assert menu_instances[0].id is not Noneassert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]-def generate_expected_payload_for_menu_item(menu_item, menu_item_global_id):- return json.dumps(- {- "menuItem": {- "id": menu_item_global_id,- "name": menu_item.name,- "menu": {"id": graphene.Node.to_global_id("Menu", menu_item.menu_id)}- if menu_item.menu_id- else None,- "page": {"id": graphene.Node.to_global_id("Page", menu_item.page_id)}- if menu_item.page_id- else None,- },- "meta": None,- }- )--def test_menu_item_created(menu_item, subscription_menu_item_created_webhook):# givenwebhooks = [subscription_menu_item_created_webhook]@@ -436,7 +410,7 @@ def test_menu_item_created(menu_item, subscription_menu_item_created_webhook):deliveries = create_deliveries_for_subscriptions(event_type, menu_item, webhooks)# then- expected_payload = generate_expected_payload_for_menu_item(menu_item, menu_item_id)+ expected_payload = json.dumps(generate_menu_item_payload(menu_item, menu_item_id))assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -452,7 +426,7 @@ def test_menu_item_updated(menu_item, subscription_menu_item_updated_webhook):deliveries = create_deliveries_for_subscriptions(event_type, menu_item, webhooks)# then- expected_payload = generate_expected_payload_for_menu_item(menu_item, menu_item_id)+ expected_payload = json.dumps(generate_menu_item_payload(menu_item, menu_item_id))assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -475,8 +449,8 @@ def test_menu_item_deleted(menu_item, subscription_menu_item_deleted_webhook):)# then- expected_payload = generate_expected_payload_for_menu_item(- menu_item_instances[0], menu_item_id+ expected_payload = json.dumps(+ generate_menu_item_payload(menu_item_instances[0], menu_item_id))assert menu_item_instances[0].id is not Noneassert deliveries[0].payload.payload == expected_payload@@ -490,13 +464,7 @@ def test_shipping_price_created(# givenwebhooks = [subscription_shipping_price_created_webhook]event_type = WebhookEventAsyncType.SHIPPING_PRICE_CREATED-- shipping_method_id = graphene.Node.to_global_id(- "ShippingMethodType", shipping_method.id- )- shipping_zone_id = graphene.Node.to_global_id(- "ShippingZone", shipping_method.shipping_zone.id- )+ expected_payload = generate_shipping_method_payload(shipping_method)# whendeliveries = create_deliveries_for_subscriptions(@@ -504,25 +472,7 @@ def test_shipping_price_created()# then- expected_payload = json.dumps(- {- "shippingMethod": {- "id": shipping_method_id,- "name": shipping_method.name,- "channelListings": [- {"channel": {"name": sl.channel.name}}- for sl in shipping_method.channel_listings.all()- ],- },- "shippingZone": {- "id": shipping_zone_id,- "name": shipping_method.shipping_zone.name,- },- "meta": None,- }- )-- assert deliveries[0].payload.payload == expected_payload+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -533,12 +483,7 @@ def test_shipping_price_updated(# givenwebhooks = [subscription_shipping_price_updated_webhook]event_type = WebhookEventAsyncType.SHIPPING_PRICE_UPDATED- shipping_method_id = graphene.Node.to_global_id(- "ShippingMethodType", shipping_method.id- )- shipping_zone_id = graphene.Node.to_global_id(- "ShippingZone", shipping_method.shipping_zone.id- )+ expected_payload = generate_shipping_method_payload(shipping_method)# whendeliveries = create_deliveries_for_subscriptions(@@ -546,25 +491,7 @@ def test_shipping_price_updated()# then- expected_payload = json.dumps(- {- "shippingMethod": {- "id": shipping_method_id,- "name": shipping_method.name,- "channelListings": [- {"channel": {"name": sl.channel.name}}- for sl in shipping_method.channel_listings.all()- ],- },- "shippingZone": {- "id": shipping_zone_id,- "name": shipping_method.shipping_zone.name,- },- "meta": None,- }- )-- assert deliveries[0].payload.payload == expected_payload+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -903,165 +830,212 @@ def test_draft_order_deleted(order, subscription_draft_order_deleted_webhook):def test_sale_created(sale, subscription_sale_created_webhook):+ # givenwebhooks = [subscription_sale_created_webhook]event_type = WebhookEventAsyncType.SALE_CREATED- sale_id = graphene.Node.to_global_id("Sale", sale.id)+ expected_payload = generate_sale_payload(sale)++ # whendeliveries = create_deliveries_for_subscriptions(event_type, sale, webhooks)- expected_payload = json.dumps({"sale": {"id": sale_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ # then+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_sale_updated(sale, subscription_sale_updated_webhook):+ # givenwebhooks = [subscription_sale_updated_webhook]event_type = WebhookEventAsyncType.SALE_UPDATED- sale_id = graphene.Node.to_global_id("Sale", sale.id)+ expected_payload = generate_sale_payload(sale)++ # whendeliveries = create_deliveries_for_subscriptions(event_type, sale, webhooks)- expected_payload = json.dumps({"sale": {"id": sale_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ # hen+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_sale_deleted(sale, subscription_sale_deleted_webhook):+ # givenwebhooks = [subscription_sale_deleted_webhook]event_type = WebhookEventAsyncType.SALE_DELETED- sale_id = graphene.Node.to_global_id("Sale", sale.id)+ expected_payload = generate_sale_payload(sale)++ # whendeliveries = create_deliveries_for_subscriptions(event_type, sale, webhooks)- expected_payload = json.dumps({"sale": {"id": sale_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ # then+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_invoice_requested(fulfilled_order, subscription_invoice_requested_webhook):+ # givenwebhooks = [subscription_invoice_requested_webhook]event_type = WebhookEventAsyncType.INVOICE_REQUESTEDinvoice = fulfilled_order.invoices.first()- invoice_id = graphene.Node.to_global_id("Invoice", invoice.id)+ expected_payload = generate_invoice_payload(invoice)++ # whendeliveries = create_deliveries_for_subscriptions(event_type, invoice, webhooks)- expected_payload = json.dumps({"invoice": {"id": invoice_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ # then+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_invoice_deleted(fulfilled_order, subscription_invoice_deleted_webhook):+ # givenwebhooks = [subscription_invoice_deleted_webhook]event_type = WebhookEventAsyncType.INVOICE_DELETEDinvoice = fulfilled_order.invoices.first()- invoice_id = graphene.Node.to_global_id("Invoice", invoice.id)+ expected_payload = generate_invoice_payload(invoice)++ # whendeliveries = create_deliveries_for_subscriptions(event_type, invoice, webhooks)- expected_payload = json.dumps({"invoice": {"id": invoice_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ # then+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_invoice_sent(fulfilled_order, subscription_invoice_sent_webhook):+ # givenwebhooks = [subscription_invoice_sent_webhook]event_type = WebhookEventAsyncType.INVOICE_SENTinvoice = fulfilled_order.invoices.first()- invoice_id = graphene.Node.to_global_id("Invoice", invoice.id)+ expected_payload = generate_invoice_payload(invoice)++ # whendeliveries = create_deliveries_for_subscriptions(event_type, invoice, webhooks)- expected_payload = json.dumps({"invoice": {"id": invoice_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ # then+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_fulfillment_created(fulfillment, subscription_fulfillment_created_webhook):+ # givenwebhooks = [subscription_fulfillment_created_webhook]event_type = WebhookEventAsyncType.FULFILLMENT_CREATED- fulfillment_id = graphene.Node.to_global_id("Fulfillment", fulfillment.id)+ expected_payload = generate_fulfillment_payload(fulfillment)++ # whendeliveries = create_deliveries_for_subscriptions(event_type, fulfillment, webhooks)- expected_payload = json.dumps({"fulfillment": {"id": fulfillment_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ # then+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_fulfillment_canceled(fulfillment, subscription_fulfillment_canceled_webhook):+ # givenwebhooks = [subscription_fulfillment_canceled_webhook]event_type = WebhookEventAsyncType.FULFILLMENT_CANCELED- fulfillment_id = graphene.Node.to_global_id("Fulfillment", fulfillment.id)- deliveries = create_deliveries_for_subscriptions(event_type, fulfillment, webhooks)- expected_payload = json.dumps({"fulfillment": {"id": fulfillment_id}, "meta": None})+ expected_payload = generate_fulfillment_payload(fulfillment)- assert deliveries[0].payload.payload == expected_payload+ # when+ deliveries = create_deliveries_for_subscriptions(event_type, fulfillment, webhooks)+ # then+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_customer_created(customer_user, subscription_customer_created_webhook):+ # givenwebhooks = [subscription_customer_created_webhook]event_type = WebhookEventAsyncType.CUSTOMER_CREATED- user_id = graphene.Node.to_global_id("User", customer_user.id)+ expected_payload = json.dumps(generate_customer_payload(customer_user))++ # whendeliveries = create_deliveries_for_subscriptions(event_type, customer_user, webhooks)- expected_payload = json.dumps({"user": {"id": user_id}, "meta": None})+ # thenassert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_customer_updated(customer_user, subscription_customer_updated_webhook):+ # givenwebhooks = [subscription_customer_updated_webhook]event_type = WebhookEventAsyncType.CUSTOMER_UPDATED- user_id = graphene.Node.to_global_id("User", customer_user.id)+ expected_payload = json.dumps(generate_customer_payload(customer_user))++ # whendeliveries = create_deliveries_for_subscriptions(event_type, customer_user, webhooks)- expected_payload = json.dumps({"user": {"id": user_id}, "meta": None})+ # thenassert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]-def test_collection_created(collection, subscription_collection_created_webhook):+def test_collection_created(+ collection_with_products, subscription_collection_created_webhook+):+ # given+ collection = collection_with_products[0].collections.first()webhooks = [subscription_collection_created_webhook]event_type = WebhookEventAsyncType.COLLECTION_CREATED- collection_id = graphene.Node.to_global_id("Collection", collection.pk)+ expected_payload = generate_collection_payload(collection)++ # whendeliveries = create_deliveries_for_subscriptions(event_type, collection, webhooks)- expected_payload = json.dumps({"collection": {"id": collection_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ # then+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]-def test_collection_updated(collection, subscription_collection_updated_webhook):+def test_collection_updated(+ collection_with_products, subscription_collection_updated_webhook+):+ # givenwebhooks = [subscription_collection_updated_webhook]+ collection = collection_with_products[0].collections.first()event_type = WebhookEventAsyncType.COLLECTION_UPDATED- collection_id = graphene.Node.to_global_id("Collection", collection.id)+ expected_payload = generate_collection_payload(collection)++ # whendeliveries = create_deliveries_for_subscriptions(event_type, collection, webhooks)- expected_payload = json.dumps({"collection": {"id": collection_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ # then+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]-def test_collection_deleted(collection, subscription_collection_deleted_webhook):+def test_collection_deleted(+ collection_with_products, subscription_collection_deleted_webhook+):+ # givenwebhooks = [subscription_collection_deleted_webhook]+ collection = collection_with_products[0].collections.first()event_type = WebhookEventAsyncType.COLLECTION_DELETED- collection_id = graphene.Node.to_global_id("Collection", collection.id)+ expected_payload = generate_collection_payload(collection)++ # whendeliveries = create_deliveries_for_subscriptions(event_type, collection, webhooks)- expected_payload = json.dumps({"collection": {"id": collection_id}, "meta": None})- assert deliveries[0].payload.payload == expected_payload+ # then+ assert deliveries[0].payload.payload == json.dumps(expected_payload)assert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -1072,7 +1046,6 @@ def test_checkout_create(checkout, subscription_checkout_created_webhook):checkout_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}, "meta": None})-assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -1091,36 +1064,45 @@ def test_checkout_update(checkout, subscription_checkout_updated_webhook):def test_page_created(page, subscription_page_created_webhook):+ # givenwebhooks = [subscription_page_created_webhook]event_type = WebhookEventAsyncType.PAGE_CREATED- page_id = graphene.Node.to_global_id("Page", page.pk)+ expected_payload = json.dumps(generate_page_payload(page))++ # whendeliveries = create_deliveries_for_subscriptions(event_type, page, webhooks)- expected_payload = json.dumps({"page": {"id": page_id}, "meta": None})+ # thenassert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_page_updated(page, subscription_page_updated_webhook):+ # givenwebhooks = [subscription_page_updated_webhook]event_type = WebhookEventAsyncType.PAGE_UPDATED- page_id = graphene.Node.to_global_id("Page", page.pk)+ expected_payload = json.dumps(generate_page_payload(page))++ # whendeliveries = create_deliveries_for_subscriptions(event_type, page, webhooks)- expected_payload = json.dumps({"page": {"id": page_id}, "meta": None})+ # thenassert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]def test_page_deleted(page, subscription_page_deleted_webhook):+ # givenwebhooks = [subscription_page_deleted_webhook]event_type = WebhookEventAsyncType.PAGE_DELETED- page_id = graphene.Node.to_global_id("Page", page.pk)+ expected_payload = json.dumps(generate_page_payload(page))++ # whendeliveries = create_deliveries_for_subscriptions(event_type, page, webhooks)- expected_payload = json.dumps({"page": {"id": page_id}, "meta": None})+ # thenassert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -1140,20 +1122,6 @@ def test_product_created_multiple_events_in_subscription(assert deliveries[0].webhook == webhooks[0]-def generate_expected_payload_for_voucher(voucher, voucher_global_id):- return json.dumps(- {- "voucher": {- "id": voucher_global_id,- "name": voucher.name,- "code": voucher.code,- "usageLimit": voucher.usage_limit,- },- "meta": None,- }- )--def test_voucher_created(voucher, subscription_voucher_created_webhook):# givenwebhooks = [subscription_voucher_created_webhook]@@ -1164,7 +1132,7 @@ def test_voucher_created(voucher, subscription_voucher_created_webhook):deliveries = create_deliveries_for_subscriptions(event_type, voucher, webhooks)# then- expected_payload = generate_expected_payload_for_voucher(voucher, voucher_id)+ expected_payload = generate_voucher_payload(voucher, voucher_id)assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -1180,7 +1148,7 @@ def test_voucher_updated(voucher, subscription_voucher_updated_webhook):deliveries = create_deliveries_for_subscriptions(event_type, voucher, webhooks)# then- expected_payload = generate_expected_payload_for_voucher(voucher, voucher_id)+ expected_payload = generate_voucher_payload(voucher, voucher_id)assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -1201,7 +1169,7 @@ def test_voucher_deleted(voucher, subscription_voucher_deleted_webhook):deliveries = create_deliveries_for_subscriptions(event_type, voucher, webhooks)# then- expected_payload = generate_expected_payload_for_voucher(voucher, voucher_global_id)+ expected_payload = generate_voucher_payload(voucher, voucher_global_id)assert deliveries[0].payload.payload == expected_payloadassert len(deliveries) == len(webhooks)assert deliveries[0].webhook == webhooks[0]@@ -1243,131 +1211,41 @@ def test_create_deliveries_for_subscriptions_document_executed_with_error(assert len(deliveries) == 0-TEST_VALID_SUBSCRIPTION_QUERY = """- subscription{- event{- ...on ProductUpdated{- product{- id- }- }- }- }-"""--def test_validate_subscription_query_valid():- result = validate_subscription_query(TEST_VALID_SUBSCRIPTION_QUERY)+ result = validate_subscription_query(+ subscription_queries.TEST_VALID_SUBSCRIPTION_QUERY+ )assert result is Truedef test_validate_subscription_query_invalid():-result = validate_subscription_query("invalid_query")assert result is False-TEST_VALID_SUBSCRIPTION_QUERY_WITH_FRAGMENT = """-fragment productFragment on Product{- name-}-subscription{- event{- ...on ProductUpdated{- product{- id- ...productFragment- }- }- }-}-"""--def test_validate_subscription_query_valid_with_fragment():-- result = validate_subscription_query(TEST_VALID_SUBSCRIPTION_QUERY_WITH_FRAGMENT)+ result = validate_subscription_query(+ subscription_queries.TEST_VALID_SUBSCRIPTION_QUERY_WITH_FRAGMENT+ )assert result is True-TEST_INVALID_MULTIPLE_QUERY_AND_SUBSCRIPTION = """-query{- products(first:100){- edges{- node{- id- }- }- }-}-subscription{- event{- ...on ProductUpdated{- product{- id- }- }- }-}"""--def test_validate_invalid_query_and_subscription():-- result = validate_subscription_query(TEST_INVALID_MULTIPLE_QUERY_AND_SUBSCRIPTION)+ result = validate_subscription_query(+ subscription_queries.TEST_INVALID_QUERY_AND_SUBSCRIPTION+ )assert result is False-TEST_INVALID_MULTIPLE_SUBSCRIPTION_AND_QUERY = """-subscription{- event{- ...on ProductUpdated{- product{- id- }- }- }-}-query{- products(first:100){- edges{- node{- id- }- }- }-}-"""--def test_validate_invalid_subscription_and_query():-- result = validate_subscription_query(TEST_INVALID_MULTIPLE_SUBSCRIPTION_AND_QUERY)+ result = validate_subscription_query(+ subscription_queries.TEST_INVALID_SUBSCRIPTION_AND_QUERY+ )assert result is False-TEST_INVALID_MULTIPLE_SUBSCRIPTION = """-subscription{- event{- ...on ProductUpdated{- product{- id- }- }- }-}-subscription{- event{- ...on ProductCreated{- product{- id- }- }- }-}-"""--def test_validate_invalid_multiple_subscriptions():-- result = validate_subscription_query(TEST_INVALID_MULTIPLE_SUBSCRIPTION)+ result = validate_subscription_query(+ subscription_queries.TEST_INVALID_MULTIPLE_SUBSCRIPTION+ )assert result is False